-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: server improvements, validations for data
- Loading branch information
Showing
14 changed files
with
629 additions
and
74 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,4 +16,5 @@ | |
|
||
barrel*.lock | ||
barrel*.db | ||
barrel.hints | ||
barrel.hints | ||
config.toml |
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,30 @@ | ||
LAST_COMMIT := $(shell git rev-parse --short HEAD) | ||
LAST_COMMIT_DATE := $(shell git show -s --format=%ci ${LAST_COMMIT}) | ||
VERSION := $(shell git describe --abbrev=1) | ||
BUILDSTR := ${VERSION} (build "\\\#"${LAST_COMMIT} $(shell date '+%Y-%m-%d %H:%M:%S')) | ||
|
||
BIN := ./bin/barreldb.bin | ||
|
||
.PHONY: build | ||
build: $(BIN) | ||
|
||
$(BIN): $(shell find . -type f -name "*.go") | ||
CGO_ENABLED=0 go build -o ${BIN} -ldflags="-s -w -X 'main.buildString=${BUILDSTR}'" ./cmd/server/*.go | ||
|
||
.PHONY: run | ||
run: | ||
CGO_ENABLED=0 go run -ldflags="-s -w -X 'main.buildString=${BUILDSTR}'" ./cmd/server --config=cmd/server/config.toml | ||
|
||
.PHONY: test | ||
test: | ||
go test ./... | ||
|
||
# Use goreleaser to do a dry run producing local builds. | ||
.PHONY: release-dry | ||
release-dry: | ||
goreleaser --parallelism 1 --rm-dist --snapshot --skip-validate --skip-publish | ||
|
||
# Use goreleaser to build production releases and publish them. | ||
.PHONY: release | ||
release: | ||
goreleaser --parallelism 1 --rm-dist --skip-validate |
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,12 @@ | ||
[server] | ||
address = ":6379" | ||
|
||
[app] | ||
debug = false # Enable debug logging | ||
dir = "/data/barreldb" # Directory to store .db files | ||
read_only = false # Whether to run barreldb in a read only mode. Write operations are not allowed in this mode. | ||
always_fsync = false # Whether to call `fsync(2)` on every write call. This significantly affects the performance but if data durability is a big concern, consider turning it on. | ||
fsync_interval = "5s" # If always_fsync is turned off, barreldb can flush filesystem buffers periodically at this given interval. | ||
max_file_size = 1000000 # Maximum size of one datafile (.db file) in bytes. After this size has reached, it'll get rotated and a new .db file will be used for storing newer data. | ||
eval_file_size_interval = "1m" # Periodic interval to check if the size of the active .db file has reached `max_file_size`. | ||
compaction_interval = "6h" # Periodic interval to perform compaction for optimising disk usage. It cleans up deleted/expired keys and merges old datafiles into a single file. |
This file was deleted.
Oops, something went wrong.
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,61 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"strings" | ||
|
||
flag "github.com/spf13/pflag" | ||
|
||
"github.com/knadh/koanf" | ||
"github.com/knadh/koanf/parsers/toml" | ||
"github.com/knadh/koanf/providers/env" | ||
"github.com/knadh/koanf/providers/file" | ||
"github.com/zerodha/logf" | ||
) | ||
|
||
// initLogger initializes logger instance. | ||
func initLogger(ko *koanf.Koanf) logf.Logger { | ||
opts := logf.Opts{EnableCaller: true} | ||
if ko.String("app.log") == "debug" { | ||
opts.Level = logf.DebugLevel | ||
opts.EnableColor = true | ||
} | ||
return logf.New(opts) | ||
} | ||
|
||
// initConfig loads config to `ko` object. | ||
func initConfig() (*koanf.Koanf, error) { | ||
var ( | ||
ko = koanf.New(".") | ||
f = flag.NewFlagSet("front", flag.ContinueOnError) | ||
) | ||
|
||
// Configure Flags. | ||
f.Usage = func() { | ||
fmt.Println(f.FlagUsages()) | ||
os.Exit(0) | ||
} | ||
|
||
// Register `--config` flag. | ||
cfgPath := f.String("config", "config.sample.toml", "Path to a config file to load.") | ||
|
||
// Parse and Load Flags. | ||
err := f.Parse(os.Args[1:]) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
err = ko.Load(file.Provider(*cfgPath), toml.Parser()) | ||
if err != nil { | ||
return nil, err | ||
} | ||
err = ko.Load(env.Provider("BARRELDB_", ".", func(s string) string { | ||
return strings.Replace(strings.ToLower( | ||
strings.TrimPrefix(s, "BARRELDB_")), "__", ".", -1) | ||
}), nil) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return ko, 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
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.