New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: new localstore migration to reset gcSize #3595
Merged
+76
−1
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
// Copyright 2022 The Swarm Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style | ||
// license that can be found in the LICENSE file. | ||
|
||
package localstore | ||
|
||
import ( | ||
"encoding/binary" | ||
"fmt" | ||
"time" | ||
|
||
"github.com/ethersphere/bee/pkg/postage" | ||
"github.com/ethersphere/bee/pkg/shed" | ||
) | ||
|
||
// DBSchemaCatharsis is the bee schema identifier for resetting gcIndex. | ||
const DBSchemaCatharsis = "catharsis" | ||
|
||
// migrateCatharsis resets the gcSize to the count of gcIndex items. | ||
func migrateCatharsis(db *DB) error { | ||
db.logger.Info("starting catharsis migration") | ||
start := time.Now() | ||
var err error | ||
|
||
db.gcSize, err = db.shed.NewUint64Field("gc-size") | ||
if err != nil { | ||
return err | ||
} | ||
|
||
db.gcIndex, err = db.shed.NewIndex("AccessTimestamp|BinID|Hash->BatchID|BatchIndex", shed.IndexFuncs{ | ||
EncodeKey: func(fields shed.Item) (key []byte, err error) { | ||
b := make([]byte, 16, 16+len(fields.Address)) | ||
binary.BigEndian.PutUint64(b[:8], uint64(fields.AccessTimestamp)) | ||
binary.BigEndian.PutUint64(b[8:16], fields.BinID) | ||
key = append(b, fields.Address...) | ||
return key, nil | ||
}, | ||
DecodeKey: func(key []byte) (e shed.Item, err error) { | ||
e.AccessTimestamp = int64(binary.BigEndian.Uint64(key[:8])) | ||
e.BinID = binary.BigEndian.Uint64(key[8:16]) | ||
e.Address = key[16:] | ||
return e, nil | ||
}, | ||
EncodeValue: func(fields shed.Item) (value []byte, err error) { | ||
value = make([]byte, 40) | ||
copy(value, fields.BatchID) | ||
copy(value[32:], fields.Index) | ||
return value, nil | ||
}, | ||
DecodeValue: func(keyItem shed.Item, value []byte) (e shed.Item, err error) { | ||
e.BatchID = make([]byte, 32) | ||
copy(e.BatchID, value[:32]) | ||
e.Index = make([]byte, postage.IndexSize) | ||
copy(e.Index, value[32:]) | ||
return e, nil | ||
}, | ||
}) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
count, err := db.gcIndex.Count() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
err = db.gcSize.Put(uint64(count)) | ||
if err != nil { | ||
return fmt.Errorf("failed updating gcSize: %w", err) | ||
} | ||
|
||
db.logger.Info("catharsis done", "elapsed", time.Since(start), "new_gc_size", count) | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
very dramatic name :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Beginning of the cleansing!