Compare commits

..

3 Commits

Author SHA1 Message Date
James Mills
4ec5b07eea Fix install target 2023-08-12 20:19:26 +10:00
James Mills
5ed43e5a20 Fix install target and versioning 2023-08-12 20:19:00 +10:00
edd32cad0a update sift to match docstring (#245)
Closes #244.

Reviewed-on: https://git.mills.io/prologic/bitcask/pulls/245
Reviewed-by: James Mills <james@mills.io>
Co-authored-by: Tai Groot <tai@taigrr.com>
Co-committed-by: Tai Groot <tai@taigrr.com>
2022-02-04 22:37:43 +00:00
3 changed files with 64 additions and 18 deletions

View File

@@ -3,6 +3,10 @@
CGO_ENABLED=0 CGO_ENABLED=0
VERSION=$(shell git describe --abbrev=0 --tags) VERSION=$(shell git describe --abbrev=0 --tags)
COMMIT=$(shell git rev-parse --short HEAD) COMMIT=$(shell git rev-parse --short HEAD)
BUILD=$(shell git show -s --pretty=format:%cI)
GOCMD=go
DESTDIR=/usr/local/bin
all: dev all: dev
@@ -11,21 +15,21 @@ dev: build
@./bitcaskd --version @./bitcaskd --version
build: clean generate build: clean generate
@go build \ @$(GOCMD) build \
-tags "netgo static_build" -installsuffix netgo \ -tags "netgo static_build" -installsuffix netgo \
-ldflags "-w -X $(shell go list)/internal.Version=$(VERSION) -X $(shell go list)/internal.Commit=$(COMMIT)" \ -ldflags "-w -X $(shell go list)/internal.Version=$(VERSION) -X $(shell go list)/internal.Commit=$(COMMIT) -X $(shell go list)/internal.Build=$(BUILD)" \
./cmd/bitcask/... ./cmd/bitcask/...
@go build \ @$(GOCMD) build \
-tags "netgo static_build" -installsuffix netgo \ -tags "netgo static_build" -installsuffix netgo \
-ldflags "-w -X $(shell go list)/internal.Version=$(VERSION) -X $(shell go list)/internal.Commit=$(COMMIT)" \ -ldflags "-w -X $(shell go list)/internal.Version=$(VERSION) -X $(shell go list)/internal.Commit=$(COMMIT) -X $(shell go list)/internal.Build=$(BUILD)" \
./cmd/bitcaskd/... ./cmd/bitcaskd/...
generate: generate:
@go generate $(shell go list)/... @$(GOCMD) generate $(shell go list)/...
install: build install: build
@go install ./cmd/bitcask/... @install -D -m 755 bitcask $(DESTDIR)/bitcask
@go install ./cmd/bitcaskd/... @install -D -m 755 bitcaskd $(DESTDIR)/bitcaskd
ifeq ($(PUBLISH), 1) ifeq ($(PUBLISH), 1)
image: image:
@@ -40,23 +44,23 @@ release:
@./tools/release.sh @./tools/release.sh
profile: build profile: build
@go test -cpuprofile cpu.prof -memprofile mem.prof -v -bench . @$(GOCMD) test -cpuprofile cpu.prof -memprofile mem.prof -v -bench .
bench: build bench: build
@go test -v -run=XXX -benchmem -bench=. . @$(GOCMD) test -v -run=XXX -benchmem -bench=. .
mocks: mocks:
@mockery -all -case underscore -output ./internal/mocks -recursive @mockery -all -case underscore -output ./internal/mocks -recursive
test: build test: build
@go test -v \ @$(GOCMD) test -v \
-cover -coverprofile=coverage.txt -covermode=atomic \ -cover -coverprofile=coverage.txt -covermode=atomic \
-coverpkg=$(shell go list) \ -coverpkg=$(shell go list) \
-race \ -race \
. .
setup: setup:
@go get github.com/vektra/mockery/... @$(GOCMD) get github.com/vektra/mockery/...
clean: clean:
@git clean -f -d -X @git clean -f -d -X

View File

@@ -264,7 +264,9 @@ func (b *Bitcask) Sift(f func(key []byte) (bool, error)) (err error) {
return true return true
}) })
b.mu.RUnlock() b.mu.RUnlock()
if err != nil {
return
}
b.mu.Lock() b.mu.Lock()
defer b.mu.Unlock() defer b.mu.Unlock()
keysToDelete.ForEach(func(node art.Node) (cont bool) { keysToDelete.ForEach(func(node art.Node) (cont bool) {
@@ -343,6 +345,10 @@ func (b *Bitcask) SiftScan(prefix []byte, f func(key []byte) (bool, error)) (err
}) })
b.mu.RUnlock() b.mu.RUnlock()
if err != nil {
return
}
b.mu.Lock() b.mu.Lock()
defer b.mu.Unlock() defer b.mu.Unlock()
keysToDelete.ForEach(func(node art.Node) (cont bool) { keysToDelete.ForEach(func(node art.Node) (cont bool) {
@@ -422,6 +428,10 @@ func (b *Bitcask) SiftRange(start, end []byte, f func(key []byte) (bool, error))
}) })
b.mu.RUnlock() b.mu.RUnlock()
if err != nil {
return
}
b.mu.Lock() b.mu.Lock()
defer b.mu.Unlock() defer b.mu.Unlock()

View File

@@ -2,17 +2,49 @@ package internal
import ( import (
"fmt" "fmt"
"runtime/debug"
"strings"
)
const (
defaultVersion = "0.0.0"
defaultCommit = "HEAD"
defaultBuild = "0000-01-01:00:00+00:00"
) )
var ( var (
// Version release version // Version is the tagged release version in the form <major>.<minor>.<patch>
Version = "0.0.1" // following semantic versioning and is overwritten by the build system.
Version = defaultVersion
// Commit will be overwritten automatically by the build system // Commit is the commit sha of the build (normally from Git) and is overwritten
Commit = "HEAD" // by the build system.
Commit = defaultCommit
// Build is the date and time of the build as an RFC3339 formatted string
// and is overwritten by the build system.
Build = defaultBuild
) )
// FullVersion returns the full version and commit hash // FullVersion display the full version and build
func FullVersion() string { func FullVersion() string {
return fmt.Sprintf("%s@%s", Version, Commit) var sb strings.Builder
isDefault := Version == defaultVersion && Commit == defaultCommit && Build == defaultBuild
if !isDefault {
sb.WriteString(fmt.Sprintf("%s@%s %s", Version, Commit, Build))
}
if info, ok := debug.ReadBuildInfo(); ok {
if isDefault {
sb.WriteString(fmt.Sprintf(" %s", info.Main.Version))
}
sb.WriteString(fmt.Sprintf(" %s", info.GoVersion))
if info.Main.Sum != "" {
sb.WriteString(fmt.Sprintf(" %s", info.Main.Sum))
}
}
return sb.String()
} }