Skip to content

Commit

Permalink
Rename the legacy database files (#13)
Browse files Browse the repository at this point in the history
  • Loading branch information
M. Mert Yıldıran authored Mar 2, 2022
1 parent d211135 commit 8b3c009
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"net"
"os"
"os/signal"
"path"
"path/filepath"
"strconv"
"strings"
Expand Down Expand Up @@ -101,6 +102,7 @@ const (

// Constants defines the database filename's prefix and file extension.
const DB_FILE string = "data"
const LEGACY_DB_FILE_EXT string = "bin"
const DB_FILE_EXT string = "db"

// Slice that stores the TCP connections
Expand Down Expand Up @@ -190,6 +192,9 @@ func main() {
// Parse the command-line arguments.
flag.Parse()

// Rename the legacy database files
renameLegacyDatabaseFiles()

// If persistent mode is enabled, try to restore the core.
if *persistent {
restoreCore()
Expand Down Expand Up @@ -241,7 +246,7 @@ func main() {
}
}

// newParitition crates a new database paritition. The filename format is data_000000000.bin
// newParitition crates a new database paritition. The filename format is data_000000000.db
// Such that the filename increments according to the partition index.
func newPartition() *os.File {
cs.Lock()
Expand Down Expand Up @@ -361,13 +366,24 @@ func restoreCore() {

// removeDatabaseFiles cleans up all of the database files.
func removeDatabaseFiles() {
files, err := filepath.Glob("./data_*.bin")
files, err := filepath.Glob(fmt.Sprintf("./data_*.%s", DB_FILE_EXT))
check(err)
for _, f := range files {
os.Remove(f)
}
}

// renameLegacyDatabaseFiles cleans up all of the database files.
func renameLegacyDatabaseFiles() {
files, err := filepath.Glob(fmt.Sprintf("./data_*.%s", LEGACY_DB_FILE_EXT))
check(err)
for _, infile := range files {
ext := path.Ext(infile)
outfile := infile[0:len(infile)-len(ext)] + "." + DB_FILE_EXT
os.Rename(infile, outfile)
}
}

func getLastTimestampOfPartition(discardedPartitionIndex int64) (timestamp int64, err error) {
cs.RLock()
offsets := cs.offsets
Expand Down

0 comments on commit 8b3c009

Please sign in to comment.