@@ -54,6 +54,8 @@ type version struct {
5454 entry storage.Entry
5555}
5656
57+ // getOnFragment retrieves an entry from the associated fragment based on the provided environment details.
58+ // It returns the found entry or an error if the key is not found, too large, or expired.
5759func (dm * DMap ) getOnFragment (e * env ) (storage.Entry , error ) {
5860 part := dm .getPartitionByHKey (e .hkey , e .kind )
5961 f , err := dm .loadFragment (part )
@@ -81,6 +83,8 @@ func (dm *DMap) getOnFragment(e *env) (storage.Entry, error) {
8183 return entry , nil
8284}
8385
86+ // lookupOnPreviousOwner retrieves the version of a key from a previous owner in the cluster.
87+ // It communicates with the specified owner node and decodes the value into a version object.
8488func (dm * DMap ) lookupOnPreviousOwner (owner * discovery.Member , key string ) (* version , error ) {
8589 cmd := protocol .NewGetEntry (dm .name , key ).Command (dm .s .ctx )
8690 rc := dm .s .client .Get (owner .String ())
@@ -108,6 +112,8 @@ func (dm *DMap) valueToVersion(value storage.Entry) *version {
108112 }
109113}
110114
115+ // lookupOnThisNode searches for a key's version on the current node, considering
116+ // only the primary partition owner.
111117func (dm * DMap ) lookupOnThisNode (hkey uint64 , key string ) * version {
112118 // Check on localhost, the partition owner.
113119 part := dm .getPartitionByHKey (hkey , partitions .PRIMARY )
@@ -179,6 +185,8 @@ func (dm *DMap) sortVersions(versions []*version) []*version {
179185 return versions
180186}
181187
188+ // sanitizeAndSortVersions removes nil versions from the input slice and sorts
189+ // the remaining versions by recency.
182190func (dm * DMap ) sanitizeAndSortVersions (versions []* version ) []* version {
183191 var sanitized []* version
184192 // We use versions slice for read-repair. Clear nil values first.
@@ -193,6 +201,8 @@ func (dm *DMap) sanitizeAndSortVersions(versions []*version) []*version {
193201 return dm .sortVersions (sanitized )
194202}
195203
204+ // lookupOnReplicas retrieves data from replica nodes for the given hash key and
205+ // key, returning a list of versioned entries.
196206func (dm * DMap ) lookupOnReplicas (hkey uint64 , key string ) []* version {
197207 // Check backup.
198208 backups := dm .s .backup .PartitionOwnersByHKey (hkey )
@@ -229,6 +239,8 @@ func (dm *DMap) lookupOnReplicas(hkey uint64, key string) []*version {
229239 return versions
230240}
231241
242+ // readRepair performs synchronization of inconsistent replicas by applying the
243+ // winning version to out-of-sync nodes.
232244func (dm * DMap ) readRepair (winner * version , versions []* version ) {
233245 for _ , value := range versions {
234246 if value .entry != nil && winner .entry .Timestamp () == value .entry .Timestamp () {
@@ -273,10 +285,13 @@ func (dm *DMap) readRepair(winner *version, versions []*version) {
273285 }
274286}
275287
288+ // getOnCluster retrieves the storage.Entry for a given hashed key and key string
289+ // from cluster nodes with read quorum. It ensures data consistency via read repair
290+ // and returns ErrKeyNotFound or ErrReadQuorum if conditions aren't met.
276291func (dm * DMap ) getOnCluster (hkey uint64 , key string ) (storage.Entry , error ) {
277- // RUnlock should not be called with defer statement here because
278- // readRepair function may call putOnFragment function which needs a write
279- // lock. Please don't forget calling RUnlock before returning here.
292+ // RUnlock should not be called with a defer statement here because
293+ // the readRepair function may call putOnFragment function which needs a write
294+ // lock. Please remember calling RUnlock before returning here.
280295 versions := dm .lookupOnOwners (hkey , key )
281296 if dm .s .config .ReadQuorum >= config .MinimumReplicaCount {
282297 v := dm .lookupOnReplicas (hkey , key )
0 commit comments