mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-05 02:27:26 +01:00
* iceberg: keep concurrent namespace property changes UpdateNamespaceProperties merged the request into a copy read by GetNamespace and wrote the whole map back, so when two requests changed different properties of the same namespace at once, both answered 200 but only one change was kept. Apply the changes inside the compare-checked write instead, and answer 503 with Retry-After when every attempt loses. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * s3tables: keep stored namespace properties out of a PropertyChanges answer UpdateNamespace does not grant GetNamespace, so answering a PropertyChanges request with the merged map let a caller allowed only to update read every stored property, even with an empty change. Echo only what was sent, as the Properties form does. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * s3tables: describe the PropertyChanges form of UpdateNamespace Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: Chris Lu <chrislusf@users.noreply.github.com>
56 lines
1.8 KiB
Go
56 lines
1.8 KiB
Go
package s3tables
|
|
|
|
import (
|
|
"reflect"
|
|
"testing"
|
|
)
|
|
|
|
// These cases moved here from the Iceberg handler's own merge, which this
|
|
// function replaces; the summary semantics are unchanged.
|
|
func TestApplyNamespacePropertyChanges(t *testing.T) {
|
|
current := map[string]string{"foo": "bar", "prop": "yes"}
|
|
|
|
props, removed, missing := ApplyNamespacePropertyChanges(current, []string{"abc"}, map[string]string{"prop": "no"})
|
|
|
|
// Removal of a missing key reports missing, not removed.
|
|
if !reflect.DeepEqual(removed, []string{}) {
|
|
t.Errorf("removed = %v, want []", removed)
|
|
}
|
|
if !reflect.DeepEqual(missing, []string{"abc"}) {
|
|
t.Errorf("missing = %v, want [abc]", missing)
|
|
}
|
|
if props["prop"] != "no" || props["foo"] != "bar" {
|
|
t.Errorf("merged properties = %v, want foo=bar prop=no", props)
|
|
}
|
|
// Input map must not be mutated.
|
|
if current["prop"] != "yes" {
|
|
t.Errorf("source map mutated: prop = %q, want yes", current["prop"])
|
|
}
|
|
}
|
|
|
|
func TestApplyNamespacePropertyChangesRemoveExisting(t *testing.T) {
|
|
props, removed, missing := ApplyNamespacePropertyChanges(map[string]string{"a": "1", "b": "2"}, []string{"a"}, nil)
|
|
|
|
if !reflect.DeepEqual(removed, []string{"a"}) {
|
|
t.Errorf("removed = %v, want [a]", removed)
|
|
}
|
|
if _, ok := props["a"]; ok {
|
|
t.Errorf("key a should have been removed: %v", props)
|
|
}
|
|
if len(missing) != 0 || props["b"] != "2" {
|
|
t.Errorf("missing = %v, properties = %v", missing, props)
|
|
}
|
|
}
|
|
|
|
func TestApplyNamespacePropertyChangesDuplicateRemovals(t *testing.T) {
|
|
// A repeated removal key must not be reported as both removed and missing.
|
|
_, removed, missing := ApplyNamespacePropertyChanges(map[string]string{"a": "1"}, []string{"a", "a"}, nil)
|
|
|
|
if !reflect.DeepEqual(removed, []string{"a"}) {
|
|
t.Errorf("removed = %v, want [a]", removed)
|
|
}
|
|
if len(missing) != 0 {
|
|
t.Errorf("missing = %v, want []", missing)
|
|
}
|
|
}
|