mdbx: expose Env.Copy* with MDBX_CP_OVERWRITE and add Env.Defrag#223
Open
JkLondon wants to merge 8 commits into
Open
mdbx: expose Env.Copy* with MDBX_CP_OVERWRITE and add Env.Defrag#223JkLondon wants to merge 8 commits into
JkLondon wants to merge 8 commits into
Conversation
- Uncomment Env.Copy/CopyFlag/CopyFD/CopyFDFlag and rewire them through the unified mdbx_env_copy / mdbx_env_copy2fd entry points. - Expose MDBX_CP_* flags (CopyDefaults, CopyForceDynamicSize, CopyDontFlush, CopyThrottleMVCC and the new CopyOverwrite for clobbering an existing target file). - Bind mdbx_env_defrag via a thin cgo helper (mdbxgo_env_defrag), expose DefragOptions / DefragResult and the MDBX_defrag_* stopping reasons. - Replace the long-commented Copy tests with working ones plus dedicated tests for the new CopyOverwrite flag and Env.Defrag.
On Windows mdbx_filehandle_t is HANDLE (void*), so the previous C.mdbx_filehandle_t(fd) where fd is uintptr would not compile under GOOS=windows. Route the call through a thin C helper that takes a uintptr_t and performs the platform-specific cast in C, so the Go side stays identical on every target. The CopyFD test now runs on Windows as well.
r.spent_time_dot16 is already typed C.uint64_t, so the explicit conversion is flagged by unconvert.
mdbx_env_defrag opens its own write transaction via txn_basal_start, and on Windows it trips ERROR_LOCK_VIOLATION against the env's own LockFileEx region when run on a handle that has just committed writes. The defrag API binding itself is fine — only the test scenario hits the libmdbx Windows locking interaction.
Keep the failure visible in CI until libmdbx clarifies the expected mdbx_env_defrag calling sequence on Windows / fixes the LockFileEx region conflict that ERROR_LOCK_VIOLATIONs on a freshly written env.
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Env.Copy/CopyFlag/CopyFD/CopyFDFlagmethods and rewires them onto the modernmdbx_env_copy(env, dest, flags)/mdbx_env_copy2fd(env, fd, flags)entry points (the oldmdbx_env_copy2/mdbx_env_copyfd2API the bindings used no longer exists).CopyDefaults,CopyForceDynamicSize,CopyDontFlush,CopyThrottleMVCC, andCopyOverwrite(=MDBX_CP_OVERWRITE) so callers can clobber an existing target file.mdbx_env_defragfor explicit in-place defragmentation (no full copy needed): introducesEnv.Defrag(DefragOptions) (*DefragResult, error), aDefragResultstruct mirroringMDBX_defrag_result_t, and constants forMDBX_defrag_stopping_reasons_t(DefragStepSize,DefragLargeChunk,DefragLaggardReader,DefragEnoughThreshold,DefragTimeLimit,DefragAborted,DefragError, ...). The libmdbx-side progress callback is intentionally left out for now (alwaysNULL); the final metrics are still returned.TestEnv_Copy*skeletons with working tests and adds dedicated coverage forCopyOverwriteandEnv.Defrag.Windows portability
mdbx_filehandle_tisHANDLE(i.e.void*) on Windows andinton POSIX, so writingC.mdbx_filehandle_t(fd)over a Gouintptrdoes not compile underGOOS=windows. The fix is a tiny cgo wrappermdbxgo_env_copy2fd(MDBX_env*, uintptr_t, MDBX_copy_flags_t)that performs the platform-specific cast in C, so the Go side stays identical on every target. Cross-checked withGOOS=windows GOARCH=amd64 CGO_ENABLED=1 CC=x86_64-w64-mingw32-gcc go buildandgo test -c.Test plan
go build ./...go test -count=1 ./mdbx/...(darwin/arm64) — all green, including the newTestEnv_Copy,TestEnv_CopyFD,TestEnv_CopyFlag_Overwrite,TestEnv_DefragGOOS=windows GOARCH=amd64 CGO_ENABLED=1 CC=x86_64-w64-mingw32-gcc go build ./mdbx/...— cross-compiles cleanlygo test -cfor the same Windows target — produces a valid PE32+ test binary