MCPcopy
hub / github.com/olric-data/olric / Get

Method Get

internal/dmap/get.go:371–410  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

369// does not contain the key. It's thread-safe. It is safe to modify the contents
370// of the returned value.
371func (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}

Callers 15

TestDMap_Put_StandaloneFunction · 0.95
TestDMap_Put_ClusterFunction · 0.95
TestDMap_Put_PXFunction · 0.95
TestDMap_Put_NXFunction · 0.95
TestDMap_Put_XXFunction · 0.95
TestDMap_Put_EXFunction · 0.95
TestDMap_Put_EXATFunction · 0.95
TestDMap_Put_PXATFunction · 0.95
TestDMap_Put_PX_With_NXFunction · 0.95
TestDMap_Get_StandaloneFunction · 0.95
TestDMap_Get_ClusterFunction · 0.95

Implementers 2

ClusterDMapcluster_client.go
EmbeddedDMapembedded_client.go

Calls 15

getOnClusterMethod · 0.95
DecodeMethod · 0.95
HKeyFunction · 0.92
NewGetFunction · 0.92
ConvertErrorFunction · 0.92
OwnerMethod · 0.80
PartitionByHKeyMethod · 0.80
CompareByNameMethod · 0.80
ThisMethod · 0.80
GetMethod · 0.65
NewEntryMethod · 0.65
IncreaseMethod · 0.45

Tested by 15

TestDMap_Put_StandaloneFunction · 0.76
TestDMap_Put_ClusterFunction · 0.76
TestDMap_Put_PXFunction · 0.76
TestDMap_Put_NXFunction · 0.76
TestDMap_Put_XXFunction · 0.76
TestDMap_Put_EXFunction · 0.76
TestDMap_Put_EXATFunction · 0.76
TestDMap_Put_PXATFunction · 0.76
TestDMap_Put_PX_With_NXFunction · 0.76
TestDMap_Get_StandaloneFunction · 0.76
TestDMap_Get_ClusterFunction · 0.76