@@ -71,20 +71,20 @@ func New(path string) (s *Store, err error) {
7171 }
7272 // Index storing actual chunk address, data and store timestamp.
7373 s .retrievalIndex , err = db .NewIndex ("Address->StoreTimestamp|Data" , shed.IndexFuncs {
74- EncodeKey : func (fields shed.IndexItem ) (key []byte , err error ) {
74+ EncodeKey : func (fields shed.Item ) (key []byte , err error ) {
7575 return fields .Address , nil
7676 },
77- DecodeKey : func (key []byte ) (e shed.IndexItem , err error ) {
77+ DecodeKey : func (key []byte ) (e shed.Item , err error ) {
7878 e .Address = key
7979 return e , nil
8080 },
81- EncodeValue : func (fields shed.IndexItem ) (value []byte , err error ) {
81+ EncodeValue : func (fields shed.Item ) (value []byte , err error ) {
8282 b := make ([]byte , 8 )
8383 binary .BigEndian .PutUint64 (b , uint64 (fields .StoreTimestamp ))
8484 value = append (b , fields .Data ... )
8585 return value , nil
8686 },
87- DecodeValue : func (value []byte ) (e shed.IndexItem , err error ) {
87+ DecodeValue : func (keyItem shed. Item , value []byte ) (e shed.Item , err error ) {
8888 e .StoreTimestamp = int64 (binary .BigEndian .Uint64 (value [:8 ]))
8989 e .Data = value [8 :]
9090 return e , nil
@@ -96,19 +96,19 @@ func New(path string) (s *Store, err error) {
9696 // Index storing access timestamp for a particular address.
9797 // It is needed in order to update gc index keys for iteration order.
9898 s .accessIndex , err = db .NewIndex ("Address->AccessTimestamp" , shed.IndexFuncs {
99- EncodeKey : func (fields shed.IndexItem ) (key []byte , err error ) {
99+ EncodeKey : func (fields shed.Item ) (key []byte , err error ) {
100100 return fields .Address , nil
101101 },
102- DecodeKey : func (key []byte ) (e shed.IndexItem , err error ) {
102+ DecodeKey : func (key []byte ) (e shed.Item , err error ) {
103103 e .Address = key
104104 return e , nil
105105 },
106- EncodeValue : func (fields shed.IndexItem ) (value []byte , err error ) {
106+ EncodeValue : func (fields shed.Item ) (value []byte , err error ) {
107107 b := make ([]byte , 8 )
108108 binary .BigEndian .PutUint64 (b , uint64 (fields .AccessTimestamp ))
109109 return b , nil
110110 },
111- DecodeValue : func (value []byte ) (e shed.IndexItem , err error ) {
111+ DecodeValue : func (keyItem shed. Item , value []byte ) (e shed.Item , err error ) {
112112 e .AccessTimestamp = int64 (binary .BigEndian .Uint64 (value ))
113113 return e , nil
114114 },
@@ -118,23 +118,23 @@ func New(path string) (s *Store, err error) {
118118 }
119119 // Index with keys ordered by access timestamp for garbage collection prioritization.
120120 s .gcIndex , err = db .NewIndex ("AccessTimestamp|StoredTimestamp|Address->nil" , shed.IndexFuncs {
121- EncodeKey : func (fields shed.IndexItem ) (key []byte , err error ) {
121+ EncodeKey : func (fields shed.Item ) (key []byte , err error ) {
122122 b := make ([]byte , 16 , 16 + len (fields .Address ))
123123 binary .BigEndian .PutUint64 (b [:8 ], uint64 (fields .AccessTimestamp ))
124124 binary .BigEndian .PutUint64 (b [8 :16 ], uint64 (fields .StoreTimestamp ))
125125 key = append (b , fields .Address ... )
126126 return key , nil
127127 },
128- DecodeKey : func (key []byte ) (e shed.IndexItem , err error ) {
128+ DecodeKey : func (key []byte ) (e shed.Item , err error ) {
129129 e .AccessTimestamp = int64 (binary .BigEndian .Uint64 (key [:8 ]))
130130 e .StoreTimestamp = int64 (binary .BigEndian .Uint64 (key [8 :16 ]))
131131 e .Address = key [16 :]
132132 return e , nil
133133 },
134- EncodeValue : func (fields shed.IndexItem ) (value []byte , err error ) {
134+ EncodeValue : func (fields shed.Item ) (value []byte , err error ) {
135135 return nil , nil
136136 },
137- DecodeValue : func (value []byte ) (e shed.IndexItem , err error ) {
137+ DecodeValue : func (keyItem shed. Item , value []byte ) (e shed.Item , err error ) {
138138 return e , nil
139139 },
140140 })
@@ -146,7 +146,7 @@ func New(path string) (s *Store, err error) {
146146
147147// Put stores the chunk and sets it store timestamp.
148148func (s * Store ) Put (_ context.Context , ch storage.Chunk ) (err error ) {
149- return s .retrievalIndex .Put (shed.IndexItem {
149+ return s .retrievalIndex .Put (shed.Item {
150150 Address : ch .Address (),
151151 Data : ch .Data (),
152152 StoreTimestamp : time .Now ().UTC ().UnixNano (),
@@ -161,7 +161,7 @@ func (s *Store) Get(_ context.Context, addr storage.Address) (c storage.Chunk, e
161161 batch := new (leveldb.Batch )
162162
163163 // Get the chunk data and storage timestamp.
164- item , err := s .retrievalIndex .Get (shed.IndexItem {
164+ item , err := s .retrievalIndex .Get (shed.Item {
165165 Address : addr ,
166166 })
167167 if err != nil {
@@ -172,13 +172,13 @@ func (s *Store) Get(_ context.Context, addr storage.Address) (c storage.Chunk, e
172172 }
173173
174174 // Get the chunk access timestamp.
175- accessItem , err := s .accessIndex .Get (shed.IndexItem {
175+ accessItem , err := s .accessIndex .Get (shed.Item {
176176 Address : addr ,
177177 })
178178 switch err {
179179 case nil :
180180 // Remove gc index entry if access timestamp is found.
181- err = s .gcIndex .DeleteInBatch (batch , shed.IndexItem {
181+ err = s .gcIndex .DeleteInBatch (batch , shed.Item {
182182 Address : item .Address ,
183183 StoreTimestamp : accessItem .AccessTimestamp ,
184184 AccessTimestamp : item .StoreTimestamp ,
@@ -197,7 +197,7 @@ func (s *Store) Get(_ context.Context, addr storage.Address) (c storage.Chunk, e
197197 accessTimestamp := time .Now ().UTC ().UnixNano ()
198198
199199 // Put new access timestamp in access index.
200- err = s .accessIndex .PutInBatch (batch , shed.IndexItem {
200+ err = s .accessIndex .PutInBatch (batch , shed.Item {
201201 Address : addr ,
202202 AccessTimestamp : accessTimestamp ,
203203 })
@@ -206,7 +206,7 @@ func (s *Store) Get(_ context.Context, addr storage.Address) (c storage.Chunk, e
206206 }
207207
208208 // Put new access timestamp in gc index.
209- err = s .gcIndex .PutInBatch (batch , shed.IndexItem {
209+ err = s .gcIndex .PutInBatch (batch , shed.Item {
210210 Address : item .Address ,
211211 AccessTimestamp : accessTimestamp ,
212212 StoreTimestamp : item .StoreTimestamp ,
@@ -244,7 +244,7 @@ func (s *Store) CollectGarbage() (err error) {
244244 // New batch for a new cg round.
245245 trash := new (leveldb.Batch )
246246 // Iterate through all index items and break when needed.
247- err = s .gcIndex .IterateAll (func (item shed.IndexItem ) (stop bool , err error ) {
247+ err = s .gcIndex .Iterate (func (item shed.Item ) (stop bool , err error ) {
248248 // Remove the chunk.
249249 err = s .retrievalIndex .DeleteInBatch (trash , item )
250250 if err != nil {
@@ -265,7 +265,7 @@ func (s *Store) CollectGarbage() (err error) {
265265 return true , nil
266266 }
267267 return false , nil
268- })
268+ }, nil )
269269 if err != nil {
270270 return err
271271 }
0 commit comments