1515package dmap
1616
1717import (
18- "context"
1918 "errors"
2019 "fmt"
2120 "time"
3837 ErrDMapNotFound = errors .New ("dmap not found" )
3938)
4039
41- // DMap implements a single hop distributed hash table.
40+ // DMap implements a single- hop distributed hash table.
4241type DMap struct {
4342 name string
4443 s * Service
@@ -110,31 +109,6 @@ func (s *Service) getOrCreateDMap(name string) (*DMap, error) {
110109 return dm , err
111110}
112111
113- func (dm * DMap ) loadFragmentFromPartition (part * partitions.Partition ) (* fragment , error ) {
114- f , ok := part .Map ().Load (dm .name )
115- if ! ok {
116- return nil , errFragmentNotFound
117- }
118- return f .(* fragment ), nil
119- }
120-
121- func (dm * DMap ) createFragmentOnPartition (part * partitions.Partition ) (* fragment , error ) {
122- ctx , cancel := context .WithCancel (context .Background ())
123- f := & fragment {
124- service : dm .s ,
125- accessLog : newAccessLog (),
126- ctx : ctx ,
127- cancel : cancel ,
128- }
129- var err error
130- f .storage , err = dm .engine .Fork (nil )
131- if err != nil {
132- return nil , err
133- }
134- part .Map ().Store (dm .name , f )
135- return f , nil
136- }
137-
138112func (dm * DMap ) getPartitionByHKey (hkey uint64 , kind partitions.Kind ) * partitions.Partition {
139113 var part * partitions.Partition
140114 switch {
@@ -148,27 +122,6 @@ func (dm *DMap) getPartitionByHKey(hkey uint64, kind partitions.Kind) *partition
148122 return part
149123}
150124
151- func (dm * DMap ) getFragment (hkey uint64 , kind partitions.Kind ) (* fragment , error ) {
152- part := dm .getPartitionByHKey (hkey , kind )
153- part .Lock ()
154- defer part .Unlock ()
155- return dm .loadFragmentFromPartition (part )
156- }
157-
158- func (dm * DMap ) getOrCreateFragment (hkey uint64 , kind partitions.Kind ) (* fragment , error ) {
159- part := dm .getPartitionByHKey (hkey , kind )
160- part .Lock ()
161- defer part .Unlock ()
162-
163- // try to get
164- f , err := dm .loadFragmentFromPartition (part )
165- if errors .Is (err , errFragmentNotFound ) {
166- // create the fragment and return
167- return dm .createFragmentOnPartition (part )
168- }
169- return f , err
170- }
171-
172125func timeoutToTTL (timeout time.Duration ) int64 {
173126 if timeout .Seconds () == 0 {
174127 return 0
0 commit comments