style: minor formatting cleanup in test_conflict.go

Remove extra trailing space in comment for consistency.

This utility was originally added in commit 138b5ed to create timestamp
collision scenarios for testing the sophisticated conflict resolution
system. The conflict resolution test it enables now passes consistently
after fixing the timestamp collision handling logic.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
2025-09-20 18:48:48 +03:00
parent eaed6e76e4
commit bd1d1c2c7c

View File

@@ -1,3 +1,4 @@
//go:build ignore
// +build ignore // +build ignore
package main package main
@@ -24,33 +25,33 @@ func createConflictingData(dataDir1, dataDir2 string) error {
// Same timestamp, different UUIDs // Same timestamp, different UUIDs
timestamp := time.Now().UnixMilli() timestamp := time.Now().UnixMilli()
path := "test/conflict/data" path := "test/conflict/data"
// Data for node1 // Data for node1
data1 := json.RawMessage(`{"message": "from node1", "value": 100}`) data1 := json.RawMessage(`{"message": "from node1", "value": 100}`)
uuid1 := uuid.New().String() uuid1 := uuid.New().String()
// Data for node2 (same timestamp, different UUID and content) // Data for node2 (same timestamp, different UUID and content)
data2 := json.RawMessage(`{"message": "from node2", "value": 200}`) data2 := json.RawMessage(`{"message": "from node2", "value": 200}`)
uuid2 := uuid.New().String() uuid2 := uuid.New().String()
// Store in node1's database // Store in node1's database
err := storeConflictData(dataDir1, path, timestamp, uuid1, data1) err := storeConflictData(dataDir1, path, timestamp, uuid1, data1)
if err != nil { if err != nil {
return fmt.Errorf("failed to store in node1: %v", err) return fmt.Errorf("failed to store in node1: %v", err)
} }
// Store in node2's database // Store in node2's database
err = storeConflictData(dataDir2, path, timestamp, uuid2, data2) err = storeConflictData(dataDir2, path, timestamp, uuid2, data2)
if err != nil { if err != nil {
return fmt.Errorf("failed to store in node2: %v", err) return fmt.Errorf("failed to store in node2: %v", err)
} }
fmt.Printf("Created conflict scenario:\n") fmt.Printf("Created conflict scenario:\n")
fmt.Printf("Path: %s\n", path) fmt.Printf("Path: %s\n", path)
fmt.Printf("Timestamp: %d\n", timestamp) fmt.Printf("Timestamp: %d\n", timestamp)
fmt.Printf("Node1 UUID: %s, Data: %s\n", uuid1, string(data1)) fmt.Printf("Node1 UUID: %s, Data: %s\n", uuid1, string(data1))
fmt.Printf("Node2 UUID: %s, Data: %s\n", uuid2, string(data2)) fmt.Printf("Node2 UUID: %s, Data: %s\n", uuid2, string(data2))
return nil return nil
} }
@@ -62,24 +63,24 @@ func storeConflictData(dataDir, path string, timestamp int64, uuid string, data
return err return err
} }
defer db.Close() defer db.Close()
storedValue := StoredValue{ storedValue := StoredValue{
UUID: uuid, UUID: uuid,
Timestamp: timestamp, Timestamp: timestamp,
Data: data, Data: data,
} }
valueBytes, err := json.Marshal(storedValue) valueBytes, err := json.Marshal(storedValue)
if err != nil { if err != nil {
return err return err
} }
return db.Update(func(txn *badger.Txn) error { return db.Update(func(txn *badger.Txn) error {
// Store main data // Store main data
if err := txn.Set([]byte(path), valueBytes); err != nil { if err := txn.Set([]byte(path), valueBytes); err != nil {
return err return err
} }
// Store timestamp index // Store timestamp index
indexKey := fmt.Sprintf("_ts:%020d:%s", timestamp, path) indexKey := fmt.Sprintf("_ts:%020d:%s", timestamp, path)
return txn.Set([]byte(indexKey), []byte(uuid)) return txn.Set([]byte(indexKey), []byte(uuid))
@@ -91,13 +92,13 @@ func main() {
fmt.Println("Usage: go run test_conflict.go <data_dir1> <data_dir2>") fmt.Println("Usage: go run test_conflict.go <data_dir1> <data_dir2>")
os.Exit(1) os.Exit(1)
} }
err := createConflictingData(os.Args[1], os.Args[2]) err := createConflictingData(os.Args[1], os.Args[2])
if err != nil { if err != nil {
fmt.Printf("Error: %v\n", err) fmt.Printf("Error: %v\n", err)
os.Exit(1) os.Exit(1)
} }
fmt.Println("Conflict data created successfully!") fmt.Println("Conflict data created successfully!")
fmt.Println("Start your nodes and trigger a sync to see conflict resolution in action.") fmt.Println("Start your nodes and trigger a sync to see conflict resolution in action.")
} }