Initial commit: archer, a Go-native MySQL/MariaDB table archiver
Renamed from arcdb: module path, cmd/archer, internal/archererr, docs, build scripts and ARCHER_* environment variables. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
commit
bc4a6b504f
99 files changed
+12752
No files matched your search
@@ -0,0 +1,63 @@
|
||||
package shard
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"archer/internal/row"
|
||||
)
|
||||
|
||||
// FinalName builds the sealed shard filename:
|
||||
// <seq:06d>.<lo>-<hi>.<format>[.<comp>]
|
||||
func FinalName(seq int64, lo, hi, format, compExt string) string {
|
||||
return fmt.Sprintf("%06d.%s-%s.%s%s", seq, safeNamePart(lo), safeNamePart(hi), format, compExt)
|
||||
}
|
||||
|
||||
// KeyFilePart renders a key tuple into a filename-safe fragment.
|
||||
func KeyFilePart(k row.Key) string {
|
||||
if len(k) == 0 {
|
||||
return "NULL"
|
||||
}
|
||||
parts := make([]string, len(k))
|
||||
for i, p := range k {
|
||||
if p.Null {
|
||||
parts[i] = "NULL"
|
||||
} else {
|
||||
parts[i] = p.Val
|
||||
}
|
||||
}
|
||||
return strings.Join(parts, ",")
|
||||
}
|
||||
|
||||
func safeNamePart(s string) string {
|
||||
if s == "" {
|
||||
return "_"
|
||||
}
|
||||
var b strings.Builder
|
||||
for _, r := range s {
|
||||
switch {
|
||||
case r >= 'a' && r <= 'z', r >= 'A' && r <= 'Z', r >= '0' && r <= '9':
|
||||
b.WriteRune(r)
|
||||
case r == '.', r == '_', r == '-':
|
||||
b.WriteRune(r)
|
||||
default:
|
||||
b.WriteByte('_')
|
||||
}
|
||||
if b.Len() >= 96 {
|
||||
break
|
||||
}
|
||||
}
|
||||
if b.Len() == 0 {
|
||||
return "_"
|
||||
}
|
||||
return b.String()
|
||||
}
|
||||
|
||||
// BucketDir returns the directory that holds shards for a bucket.
|
||||
func BucketDir(root, bucket string) string {
|
||||
if bucket == "" {
|
||||
return root
|
||||
}
|
||||
return filepath.Join(root, "date="+safeNamePart(bucket))
|
||||
}
|
||||
Reference in new issue
Block a user