fix(nodes): share lightweight remote inbound catalog refreshes (#7313)

Replace full inbound/client-list downloads on cold remote ID lookups with an owner-scoped six-field catalog projected directly from the database. Coalesce concurrent catalog refreshes per remote while preserving independent caller cancellation and rejecting stale ID mappings after topology mutations.

Seed reconciliation from the catalog, create missing inbounds directly, preserve prefixed/adopted aliases and invalidate pushed state when remote IDs change. Avoid invalidating catalog generations on unchanged-ID settings pushes. Retain client-membership-aware reconciliation state and legacy full-list fallback only on HTTP 404/405.

Cover permissions, query projection, concurrent refresh/cancellation, deletion/recreation, reconciliation request counts and mixed-version node compatibility. Integrated CI and Docs CI passed, including race, node E2E and PostgreSQL catalog projection. Synthetic response-size comparison is not a production latency benchmark.

Fixes #7303.
This commit is contained in:
Hamed
2026-12-03 03:26:44 +03:30
committed by GitHub
parent 8a686cd8bd
commit 0afa11ddff
27 changed files with 990 additions and 104 deletions
+19 -2
View File
@@ -45,7 +45,7 @@ func TestNodeSnapshotVersionCompatibility(t *testing.T) {
token := node.mintToken("snapshot-link", "node-sync")
master.start()
node.start()
var lists, compact, full, unchanged, clientAdds atomic.Int32
var catalogs, lists, compact, full, unchanged, clientAdds atomic.Int32
target, err := url.Parse(node.url())
if err != nil {
t.Fatal(err)
@@ -90,6 +90,8 @@ func TestNodeSnapshotVersionCompatibility(t *testing.T) {
}
front := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
switch req.URL.Path {
case "/panel/api/inbounds/catalog":
catalogs.Add(1)
case "/panel/api/inbounds/list":
lists.Add(1)
case "/panel/api/inbounds/trafficSnapshot":
@@ -114,10 +116,25 @@ func TestNodeSnapshotVersionCompatibility(t *testing.T) {
if err := json.Unmarshal(node.call(http.MethodPost, "/panel/api/inbounds/add", vlessInbound("matrix", inboundPort, nil, vlessClient("matrix-first"))), &source); err != nil {
t.Fatal(err)
}
params := map[string]any{"name": "matrix-node", "scheme": "http", "address": address.Hostname(), "port": port, "basePath": "/", "apiToken": token, "enable": true, "allowPrivateAddress": true}
if version.master == current {
var options []inboundView
obj := master.call(http.MethodPost, "/panel/api/nodes/inbounds", params)
if err := json.Unmarshal(obj, &options); err != nil || len(options) != 1 || options[0].Id != source.Id {
t.Fatalf("read node options: %s, %v", obj, err)
}
var wantLists int32
if version.node != current {
wantLists = 1
}
if got := lists.Swap(0); catalogs.Load() != 1 || got != wantLists {
t.Fatalf("node options used catalog=%d and full list=%d, want 1 and %d", catalogs.Load(), got, wantLists)
}
}
if version.master == current {
node.call(http.MethodPost, "/panel/api/inbounds/add", vlessInbound("matrix-secondary", secondaryPort, nil))
}
master.call(http.MethodPost, "/panel/api/nodes/add", map[string]any{"name": "matrix-node", "scheme": "http", "address": address.Hostname(), "port": port, "basePath": "/", "apiToken": token, "enable": true, "allowPrivateAddress": true})
master.call(http.MethodPost, "/panel/api/nodes/add", params)
eventually(t, settleTimeout, "version pair synchronizes and reaches steady state", func() (bool, string) {
ib, ok := master.inboundOnPort(inboundPort)
ready := lists.Load() >= 3