Get gets the value for the given key. It returns ErrKeyNotFound if the DB does not contain the key. It's thread-safe. It is safe to modify the contents of the returned value.
(ctx context.Context, key string)
| 369 | // does not contain the key. It's thread-safe. It is safe to modify the contents |
| 370 | // of the returned value. |
| 371 | func (dm *DMap) Get(ctx context.Context, key string) (storage.Entry, error) { |
| 372 | hkey := partitions.HKey(dm.name, key) |
| 373 | member := dm.s.primary.PartitionByHKey(hkey).Owner() |
| 374 | |
| 375 | // We are on the partition owner |
| 376 | if member.CompareByName(dm.s.rt.This()) { |
| 377 | entry, err := dm.getOnCluster(hkey, key) |
| 378 | if errors.Is(err, ErrKeyNotFound) { |
| 379 | GetMisses.Increase(1) |
| 380 | } |
| 381 | if err != nil { |
| 382 | return nil, err |
| 383 | } |
| 384 | |
| 385 | // number of keys that have been requested and found present |
| 386 | GetHits.Increase(1) |
| 387 | |
| 388 | return entry, nil |
| 389 | } |
| 390 | |
| 391 | // Redirect to the partition owner |
| 392 | cmd := protocol.NewGet(dm.name, key).SetRaw().Command(dm.s.ctx) |
| 393 | rc := dm.s.client.Get(member.String()) |
| 394 | err := rc.Process(ctx, cmd) |
| 395 | if err != nil { |
| 396 | return nil, protocol.ConvertError(err) |
| 397 | } |
| 398 | |
| 399 | value, err := cmd.Bytes() |
| 400 | if err != nil { |
| 401 | return nil, protocol.ConvertError(err) |
| 402 | } |
| 403 | |
| 404 | // number of keys that have been requested and found present |
| 405 | GetHits.Increase(1) |
| 406 | |
| 407 | entry := dm.engine.NewEntry() |
| 408 | entry.Decode(value) |
| 409 | return entry, nil |
| 410 | } |