swarm/chunk: move chunk related declarations to chunk package (#19170)
This commit is contained in:
committed by
Anton Evangelatov
parent
b7e0dec6bd
commit
f0233948d2
@@ -312,7 +312,7 @@ func decodeIndex(data []byte, index *dpaDBIndex) error {
|
||||
return dec.Decode(index)
|
||||
}
|
||||
|
||||
func decodeData(addr Address, data []byte) (*chunk, error) {
|
||||
func decodeData(addr Address, data []byte) (Chunk, error) {
|
||||
return NewChunk(addr, data[32:]), nil
|
||||
}
|
||||
|
||||
@@ -502,7 +502,7 @@ func (s *LDBStore) Import(in io.Reader) (int64, error) {
|
||||
}
|
||||
|
||||
// Cleanup iterates over the database and deletes chunks if they pass the `f` condition
|
||||
func (s *LDBStore) Cleanup(f func(*chunk) bool) {
|
||||
func (s *LDBStore) Cleanup(f func(Chunk) bool) {
|
||||
var errorsFound, removed, total int
|
||||
|
||||
it := s.db.NewIterator()
|
||||
@@ -551,12 +551,14 @@ func (s *LDBStore) Cleanup(f func(*chunk) bool) {
|
||||
continue
|
||||
}
|
||||
|
||||
cs := int64(binary.LittleEndian.Uint64(c.sdata[:8]))
|
||||
log.Trace("chunk", "key", fmt.Sprintf("%x", key), "ck", fmt.Sprintf("%x", ck), "dkey", fmt.Sprintf("%x", datakey), "dataidx", index.Idx, "po", po, "len data", len(data), "len sdata", len(c.sdata), "size", cs)
|
||||
sdata := c.Data()
|
||||
|
||||
cs := int64(binary.LittleEndian.Uint64(sdata[:8]))
|
||||
log.Trace("chunk", "key", fmt.Sprintf("%x", key), "ck", fmt.Sprintf("%x", ck), "dkey", fmt.Sprintf("%x", datakey), "dataidx", index.Idx, "po", po, "len data", len(data), "len sdata", len(sdata), "size", cs)
|
||||
|
||||
// if chunk is to be removed
|
||||
if f(c) {
|
||||
log.Warn("chunk for cleanup", "key", fmt.Sprintf("%x", key), "ck", fmt.Sprintf("%x", ck), "dkey", fmt.Sprintf("%x", datakey), "dataidx", index.Idx, "po", po, "len data", len(data), "len sdata", len(c.sdata), "size", cs)
|
||||
log.Warn("chunk for cleanup", "key", fmt.Sprintf("%x", key), "ck", fmt.Sprintf("%x", ck), "dkey", fmt.Sprintf("%x", datakey), "dataidx", index.Idx, "po", po, "len data", len(data), "len sdata", len(sdata), "size", cs)
|
||||
s.deleteNow(&index, getIndexKey(key[1:]), po)
|
||||
removed++
|
||||
errorsFound++
|
||||
@@ -980,7 +982,7 @@ func (s *LDBStore) Has(_ context.Context, addr Address) bool {
|
||||
}
|
||||
|
||||
// TODO: To conform with other private methods of this object indices should not be updated
|
||||
func (s *LDBStore) get(addr Address) (chunk *chunk, err error) {
|
||||
func (s *LDBStore) get(addr Address) (chunk Chunk, err error) {
|
||||
if s.closed {
|
||||
return nil, ErrDBClosed
|
||||
}
|
||||
|
Reference in New Issue
Block a user