-
Notifications
You must be signed in to change notification settings - Fork 14
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
Archive migration online #75
Merged
Merged
Changes from 3 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
f948023
Latest key migration
Kbhat1 badcc17
Update interface
Kbhat1 6c09008
Update interface
Kbhat1 c9b6c25
Reduce logging
Kbhat1 dae2750
Add SetLatestVersion log
Kbhat1 69f6da1
Metrics
Kbhat1 c6d42e6
Update metric
Kbhat1 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,12 +25,14 @@ | |
const ( | ||
VersionSize = 8 | ||
|
||
PrefixStore = "s/k:" | ||
LenPrefixStore = 4 | ||
StorePrefixTpl = "s/k:%s/" // s/k:<storeKey> | ||
latestVersionKey = "s/_latest" // NB: latestVersionKey key must be lexically smaller than StorePrefixTpl | ||
earliestVersionKey = "s/_earliest" | ||
tombstoneVal = "TOMBSTONE" | ||
PrefixStore = "s/k:" | ||
LenPrefixStore = 4 | ||
StorePrefixTpl = "s/k:%s/" // s/k:<storeKey> | ||
latestVersionKey = "s/_latest" // NB: latestVersionKey key must be lexically smaller than StorePrefixTpl | ||
earliestVersionKey = "s/_earliest" | ||
latestMigratedKeyMetadata = "s/_latestMigratedKey" | ||
latestMigratedModuleMetadata = "s/_latestMigratedModule" | ||
tombstoneVal = "TOMBSTONE" | ||
|
||
// TODO: Make configurable | ||
ImportCommitBatchSize = 10000 | ||
|
@@ -210,6 +212,42 @@ | |
return int64(binary.LittleEndian.Uint64(bz)), closer.Close() | ||
} | ||
|
||
// SetLatestKey sets the latest key processed during migration. | ||
func (db *Database) SetLatestMigratedKey(key []byte) error { | ||
return db.storage.Set([]byte(latestMigratedKeyMetadata), key, defaultWriteOpts) | ||
} | ||
|
||
// GetLatestKey retrieves the latest key processed during migration. | ||
func (db *Database) GetLatestMigratedKey() ([]byte, error) { | ||
bz, closer, err := db.storage.Get([]byte(latestMigratedKeyMetadata)) | ||
if err != nil { | ||
if errors.Is(err, pebble.ErrNotFound) { | ||
return nil, nil | ||
} | ||
return nil, err | ||
} | ||
defer closer.Close() | ||
return bz, nil | ||
} | ||
|
||
// SetLatestModule sets the latest module processed during migration. | ||
func (db *Database) SetLatestMigratedModule(module string) error { | ||
return db.storage.Set([]byte(latestMigratedModuleMetadata), []byte(module), defaultWriteOpts) | ||
} | ||
|
||
// GetLatestModule retrieves the latest module processed during migration. | ||
func (db *Database) GetLatestMigratedModule() (string, error) { | ||
bz, closer, err := db.storage.Get([]byte(latestMigratedModuleMetadata)) | ||
if err != nil { | ||
if errors.Is(err, pebble.ErrNotFound) { | ||
return "", nil | ||
} | ||
return "", err | ||
} | ||
defer closer.Close() | ||
return string(bz), nil | ||
} | ||
|
||
func (db *Database) Has(storeKey string, version int64, key []byte) (bool, error) { | ||
if version < db.earliestVersion { | ||
return false, nil | ||
|
@@ -556,27 +594,60 @@ | |
} | ||
|
||
var counter int | ||
var latestKey []byte // store the latest key from the batch | ||
var latestModule string | ||
for entry := range ch { | ||
err := batch.Set(entry.StoreKey, entry.Key, entry.Value, entry.Version) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
latestKey = entry.Key // track the latest key | ||
latestModule = entry.StoreKey | ||
counter++ | ||
|
||
if counter%ImportCommitBatchSize == 0 { | ||
startTime := time.Now() | ||
|
||
// Commit the batch and record the latest key as metadata | ||
if err := batch.Write(); err != nil { | ||
panic(err) | ||
} | ||
|
||
// Persist the latest key in the metadata | ||
if err := db.SetLatestMigratedKey(latestKey); err != nil { | ||
panic(err) | ||
} | ||
|
||
if err := db.SetLatestMigratedModule(latestModule); err != nil { | ||
panic(err) | ||
} | ||
|
||
fmt.Printf("Time taken to write batch counter %d: %v\n", counter, time.Since(startTime)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will this log be too annoying? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also I wonder if there's a way to track the current progress of how many modules has been migrated till now? |
||
|
||
batch, err = NewRawBatch(db.storage) | ||
if err != nil { | ||
fmt.Printf("Error creating new raw batch: %v\n", err) | ||
panic(err) | ||
} | ||
} | ||
} | ||
|
||
// Final batch write | ||
if batch.Size() > 0 { | ||
if err := batch.Write(); err != nil { | ||
fmt.Printf("Error writing final batch: %v\n", err) | ||
panic(err) | ||
} | ||
|
||
// Persist the final latest key | ||
if err := db.SetLatestMigratedKey(latestKey); err != nil { | ||
fmt.Printf("Error setting final latest key: %v\n", err) | ||
panic(err) | ||
} | ||
|
||
if err := db.SetLatestMigratedModule(latestModule); err != nil { | ||
fmt.Printf("Error setting latest key: %v\n", err) | ||
panic(err) | ||
} | ||
} | ||
|
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
Oops, something went wrong.
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.
Check warning
Code scanning / CodeQL
Calling the system time Warning