Skip to content

Commit

Permalink
revert some more stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
acud committed Apr 2, 2021
1 parent aaf0a9d commit b98122c
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 2 deletions.
16 changes: 14 additions & 2 deletions pkg/localstore/mode_put.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,18 +73,26 @@ func (db *DB) put(mode storage.ModePut, chs ...swarm.Chunk) (exist []bool, err e
binIDs := make(map[uint8]uint64)

switch mode {
case storage.ModePutRequest:
case storage.ModePutRequest, storage.ModePutRequestPin:
for i, ch := range chs {
if containsChunk(ch.Address(), chs[:i]...) {
exist[i] = true
continue
}
exists, c, err := db.putRequest(batch, binIDs, chunkToItem(ch))
item := chunkToItem(ch)
exists, c, err := db.putRequest(batch, binIDs, item)
if err != nil {
return nil, err
}
exist[i] = exists
gcSizeChange += c

if mode == storage.ModePutRequestPin {
_, err = db.setPin(batch, item)
if err != nil {
return nil, err
}
}
}

case storage.ModePutUpload, storage.ModePutUploadPin:
Expand Down Expand Up @@ -192,6 +200,7 @@ func (db *DB) putRequest(batch *leveldb.Batch, binIDs map[uint8]uint64, item she
if err != nil {
return false, 0, err
}

return false, gcSizeChange, nil
}

Expand All @@ -207,6 +216,7 @@ func (db *DB) putUpload(batch *leveldb.Batch, binIDs map[uint8]uint64, item shed
if exists {
return true, 0, nil
}

item.StoreTimestamp = now()
item.BinID, err = db.incBinID(binIDs, db.po(swarm.NewAddress(item.Address)))
if err != nil {
Expand Down Expand Up @@ -243,6 +253,7 @@ func (db *DB) putSync(batch *leveldb.Batch, binIDs map[uint8]uint64, item shed.I
if exists {
return true, 0, nil
}

item.StoreTimestamp = now()
item.BinID, err = db.incBinID(binIDs, db.po(swarm.NewAddress(item.Address)))
if err != nil {
Expand All @@ -264,6 +275,7 @@ func (db *DB) putSync(batch *leveldb.Batch, binIDs map[uint8]uint64, item shed.I
if err != nil {
return false, 0, err
}

return false, gcSizeChange, nil
}

Expand Down
28 changes: 28 additions & 0 deletions pkg/localstore/mode_put_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,34 @@ func TestModePutRequest(t *testing.T) {
}
}

// TestModePutRequestPin validates ModePutRequestPin index values on the provided DB.
func TestModePutRequestPin(t *testing.T) {
for _, tc := range multiChunkTestCases {
t.Run(tc.name, func(t *testing.T) {
db := newTestDB(t, nil)

chunks := generateTestRandomChunks(tc.count)

wantTimestamp := time.Now().UTC().UnixNano()
defer setNow(func() (t int64) {
return wantTimestamp
})()

_, err := db.Put(context.Background(), storage.ModePutRequestPin, chunks...)
if err != nil {
t.Fatal(err)
}

for _, ch := range chunks {
newRetrieveIndexesTestWithAccess(db, ch, wantTimestamp, wantTimestamp)(t)
newPinIndexTest(db, ch, nil)(t)
}

newItemsCountTest(db.gcIndex, tc.count)(t)
})
}
}

// TestModePutSync validates ModePutSync index values on the provided DB.
func TestModePutSync(t *testing.T) {
for _, tc := range multiChunkTestCases {
Expand Down

0 comments on commit b98122c

Please sign in to comment.