mirror of
https://github.com/dolthub/dolt.git
synced 2026-04-21 19:39:04 -05:00
Merge pull request #6943 from dolthub/fulghum/reflog
Adding an env var to disable reflog data tracking
This commit is contained in:
@@ -30,6 +30,7 @@ const (
|
||||
EnvDefaultBinFormat = "DOLT_DEFAULT_BIN_FORMAT"
|
||||
EnvTestForceOpenEditor = "DOLT_TEST_FORCE_OPEN_EDITOR"
|
||||
EnvDisableChunkJournal = "DOLT_DISABLE_CHUNK_JOURNAL"
|
||||
EnvDisableReflog = "DOLT_DISABLE_REFLOG"
|
||||
EnvOssEndpoint = "OSS_ENDPOINT"
|
||||
EnvOssAccessKeyID = "OSS_ACCESS_KEY_ID"
|
||||
EnvOssAccessKeySecret = "OSS_ACCESS_KEY_SECRET"
|
||||
|
||||
+28
-15
@@ -27,6 +27,7 @@ import (
|
||||
|
||||
"github.com/dolthub/fslock"
|
||||
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/dconfig"
|
||||
"github.com/dolthub/dolt/go/store/chunks"
|
||||
"github.com/dolthub/dolt/go/store/hash"
|
||||
)
|
||||
@@ -35,6 +36,14 @@ const (
|
||||
chunkJournalName = chunkJournalAddr // todo
|
||||
)
|
||||
|
||||
var reflogDisabled = false
|
||||
|
||||
func init() {
|
||||
if os.Getenv(dconfig.EnvDisableReflog) != "" {
|
||||
reflogDisabled = true
|
||||
}
|
||||
}
|
||||
|
||||
// ChunkJournal is a persistence abstraction for a NomsBlockStore.
|
||||
// It implements both manifest and tablePersister, durably writing
|
||||
// both memTable persists and manifest updates to a single file.
|
||||
@@ -356,10 +365,12 @@ func (j *ChunkJournal) Update(ctx context.Context, lastLock addr, next manifestC
|
||||
j.contents = next
|
||||
|
||||
// Update the in-memory structures so that the ChunkJournal can be queried for reflog data
|
||||
j.mu.Lock()
|
||||
defer j.mu.Unlock()
|
||||
j.roots = append(j.roots, next.root.String())
|
||||
j.rootTimestamps = append(j.rootTimestamps, time.Now())
|
||||
if !reflogDisabled {
|
||||
j.mu.Lock()
|
||||
defer j.mu.Unlock()
|
||||
j.roots = append(j.roots, next.root.String())
|
||||
j.rootTimestamps = append(j.rootTimestamps, time.Now())
|
||||
}
|
||||
|
||||
return j.contents, nil
|
||||
}
|
||||
@@ -398,17 +409,19 @@ func (j *ChunkJournal) UpdateGCGen(ctx context.Context, lastLock addr, next mani
|
||||
|
||||
// Truncate the in-memory root and root timestamp metadata to the most recent
|
||||
// entry, and double check that it matches the root stored in the manifest.
|
||||
j.mu.Lock()
|
||||
defer j.mu.Unlock()
|
||||
if len(j.roots) == 0 {
|
||||
return manifestContents{}, fmt.Errorf(
|
||||
"ChunkJournal roots not intialized; no roots in memory")
|
||||
}
|
||||
j.roots = j.roots[len(j.roots)-1:]
|
||||
j.rootTimestamps = j.rootTimestamps[len(j.rootTimestamps)-1:]
|
||||
if j.roots[0] != latest.root.String() {
|
||||
return manifestContents{}, fmt.Errorf(
|
||||
"ChunkJournal root doesn't match manifest root")
|
||||
if !reflogDisabled {
|
||||
j.mu.Lock()
|
||||
defer j.mu.Unlock()
|
||||
if len(j.roots) == 0 {
|
||||
return manifestContents{}, fmt.Errorf(
|
||||
"ChunkJournal roots not intialized; no roots in memory")
|
||||
}
|
||||
j.roots = j.roots[len(j.roots)-1:]
|
||||
j.rootTimestamps = j.rootTimestamps[len(j.rootTimestamps)-1:]
|
||||
if j.roots[0] != latest.root.String() {
|
||||
return manifestContents{}, fmt.Errorf(
|
||||
"ChunkJournal root doesn't match manifest root")
|
||||
}
|
||||
}
|
||||
|
||||
return latest, nil
|
||||
|
||||
@@ -271,8 +271,10 @@ func (wr *journalWriter) bootstrapJournal(ctx context.Context) (last hash.Hash,
|
||||
|
||||
case rootHashJournalRecKind:
|
||||
last = hash.Hash(r.address)
|
||||
roots = append(roots, r.address.String())
|
||||
times = append(times, r.timestamp)
|
||||
if !reflogDisabled {
|
||||
roots = append(roots, r.address.String())
|
||||
times = append(times, r.timestamp)
|
||||
}
|
||||
|
||||
default:
|
||||
return fmt.Errorf("unknown journal record kind (%d)", r.kind)
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
#!/usr/bin/env bats
|
||||
load $BATS_TEST_DIRNAME/helper/common.bash
|
||||
|
||||
teardown() {
|
||||
assert_feature_version
|
||||
teardown_common
|
||||
}
|
||||
|
||||
@test "reflog: disabled with DOLT_DISABLE_REFLOG" {
|
||||
export DOLT_DISABLE_REFLOG=true
|
||||
setup_common
|
||||
dolt sql -q "create table t (i int primary key, j int);"
|
||||
dolt sql -q "insert into t values (1, 1), (2, 2), (3, 3)";
|
||||
dolt commit -Am "initial commit"
|
||||
|
||||
run dolt sql -q "select * from dolt_reflog();"
|
||||
[ "$status" -eq 0 ]
|
||||
[ "${#lines[@]}" -eq 0 ]
|
||||
}
|
||||
|
||||
@test "reflog: enabled by default" {
|
||||
setup_common
|
||||
dolt sql -q "create table t (i int primary key, j int);"
|
||||
dolt sql -q "insert into t values (1, 1), (2, 2), (3, 3)";
|
||||
dolt commit -Am "initial commit"
|
||||
|
||||
run dolt sql -q "select * from dolt_reflog();"
|
||||
[ "$status" -eq 0 ]
|
||||
[ "${#lines[@]}" -eq 6 ]
|
||||
[[ "$output" =~ "initial commit" ]] || false
|
||||
[[ "$output" =~ "Initialize data repository" ]] || false
|
||||
}
|
||||
Reference in New Issue
Block a user