-
Notifications
You must be signed in to change notification settings - Fork 639
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add merge operation of rosedb the caller can use `Merge` function to reclaim the disk files of db.
- Loading branch information
Showing
8 changed files
with
648 additions
and
18 deletions.
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
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,38 @@ | ||
package main | ||
|
||
import ( | ||
"github.com/rosedblabs/rosedb/v2" | ||
"github.com/rosedblabs/rosedb/v2/utils" | ||
) | ||
|
||
// this file shows how to use the Merge feature of rosedb. | ||
// Merge is used to merge the data files in the database. | ||
// It is recommended to use it when the database is not busy. | ||
|
||
func main() { | ||
// specify the options | ||
options := rosedb.DefaultOptions | ||
options.DirPath = "/tmp/rosedb_merge" | ||
|
||
// open a database | ||
db, err := rosedb.Open(options) | ||
if err != nil { | ||
panic(err) | ||
} | ||
defer func() { | ||
_ = db.Close() | ||
}() | ||
|
||
// write some data | ||
for i := 0; i < 100000; i++ { | ||
_ = db.Put([]byte(utils.GetTestKey(i)), utils.RandomValue(128)) | ||
} | ||
// delete some data | ||
for i := 0; i < 100000/2; i++ { | ||
_ = db.Delete([]byte(utils.GetTestKey(i))) | ||
} | ||
|
||
// then merge the data files | ||
// all the invalid data will be removed, and the valid data will be merged into the new data files. | ||
_ = db.Merge() | ||
} |
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
Oops, something went wrong.