Similarityoung commented on code in PR #1071:
URL: https://github.com/apache/dubbo-go-pixiu/pull/1071#discussion_r4462407535
##########
admin/logic/route_binding.go:
##########
@@ -791,16 +858,23 @@ func runtimeMethodRouteFromKV(
}
func findRuntimeRouteConflict(candidate *compiledRouteEntry, runtimeRoutes
[]runtimeRouteBinding) error {
- candidatePath := strings.ToLower(candidate.legacy.Resource.Path)
- candidateVerb := strings.TrimSpace(candidate.legacy.Method.HTTPVerb)
+ candidateRoute := runtimeRouteBinding{
+ path: candidate.legacy.Resource.Path,
+ httpVerb: candidate.legacy.Method.HTTPVerb,
+ }
for _, route := range runtimeRoutes {
- if strings.ToLower(route.path) == candidatePath &&
strings.EqualFold(route.httpVerb, candidateVerb) {
- return fmt.Errorf("%w: %s %s already exists at %q",
ErrRouteBindingRuntimeConflict, candidateVerb, candidate.legacy.Resource.Path,
route.key)
+ if runtimeRouteConflicts(candidateRoute, route) {
+ return fmt.Errorf("%w: %s %s already exists at %q",
ErrRouteBindingRuntimeConflict, strings.TrimSpace(candidateRoute.httpVerb),
candidateRoute.path, route.key)
}
}
return nil
}
+func runtimeRouteConflicts(candidate, existing runtimeRouteBinding) bool {
Review Comment:
**High: publish-time conflict detection does not match runtime path
normalization.**
`runtimeRouteConflicts` (and the `compileSnapshot` route key around line
1277) compares raw path strings, while `router.getTrieKey` removes one trailing
slash and the trie stores every path variable at the same node regardless of
its name. As a result, both `/api/users` + `/api/users/` and `/api/users/:id` +
`/api/users/:name` pass `Publish`, but `router.PutAPI` rejects the second route
as already existing. I reproduced this with the store fake and
`router.NewRoute()`, so a successfully published configuration cannot be fully
loaded.
Please use one canonical route key shared by publish validation and the
router (normalize trailing slashes and wildcard segments), or reject these
equivalent forms during schema validation, and add regression tests for both
cases.
##########
admin/web/src/features/config/ConfigPages.tsx:
##########
@@ -692,6 +755,28 @@ export function ResourcePage({
setDeletingRoute(null)
}
}
+ const openHistory = async (summary: RouteBindingHistorySummary) => {
+ setHistoryDialog({ name: summary.name, entries: [], loading: true,
rollingBack: null })
+ try {
+ const entries = await routeBindingApi.history(summary.name)
+ setHistoryDialog({ name: summary.name, entries, loading: false,
rollingBack: null })
+ } catch (e) {
+ setHistoryDialog(null)
+ setError(e instanceof Error ? e.message : tx('加载路由历史失败'))
+ }
+ }
+ const rollbackHistory = async (name: string, revision: string) => {
+ if (historyDialog?.rollingBack != null) return
+ setHistoryDialog((current) => (current ? { ...current, rollingBack:
revision } : current))
+ try {
+ await routeBindingApi.rollback(name, revision)
Review Comment:
**High: history-only rollback is not concurrency-safe and can delete a
recreated route.**
This call omits `expectedRevision`, so the backend receives `0`. For a
non-delete snapshot, `Rollback` calls `SaveDraft(..., 0)`, which can overwrite
a newer draft; for a deletion snapshot it calls `DeleteAndPublish(..., 0)`,
with no precondition tying the action to the state shown when the history
drawer was opened. Reproduction: publish route A, delete A, recreate/publish A,
then roll back the old deletion snapshot from the stale history page; the newly
published route is deleted without a conflict. The editor flow passes its
captured revision correctly, so this affects the history-only path.
Please pass a draft revision captured when the page state was loaded. When
the route is absent, use an explicit expected-absent precondition rather than
`0`; the backend should require one of those states for rollback. Add a
regression test for delete -> recreate -> rollback-old-deletion.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]