This is an automated email from the ASF dual-hosted git repository.

hanahmily pushed a commit to branch feat/trace-ctrl-bit
in repository https://gitbox.apache.org/repos/asf/skywalking-banyandb.git

commit 7c3b8115837f24490c3a632f418ed65ded7a8497
Author: Gao Hongtao <[email protected]>
AuthorDate: Thu Sep 25 07:52:27 2025 +0000

    Add TraceIDFormat constants and update trace handling logic
    
    - Introduced a new file `constants.go` to define `TraceIDFormat` constants 
for legacy and new trace ID formats.
    - Updated the trace query logic in `trace.go` to handle both formats, 
checking for the control bit to determine the appropriate trace ID 
representation.
    - Modified the `write_standalone.go` to prepend the control bit for new 
format trace IDs, ensuring backward compatibility.
---
 banyand/trace/constants.go        | 26 ++++++++++++++++++++++++++
 banyand/trace/trace.go            |  7 ++++++-
 banyand/trace/write_standalone.go |  7 ++++++-
 3 files changed, 38 insertions(+), 2 deletions(-)

diff --git a/banyand/trace/constants.go b/banyand/trace/constants.go
new file mode 100644
index 00000000..8c01cd30
--- /dev/null
+++ b/banyand/trace/constants.go
@@ -0,0 +1,26 @@
+// Licensed to Apache Software Foundation (ASF) under one or more contributor
+// license agreements. See the NOTICE file distributed with
+// this work for additional information regarding copyright
+// ownership. Apache Software Foundation (ASF) licenses this file to you under
+// the Apache License, Version 2.0 (the "License"); you may
+// not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package trace
+
+// idFormat represents the format version of trace ID data.
+type idFormat byte
+
+const (
+       // idFormatV1 represents the new format with control bit.
+       idFormatV1 idFormat = 0x01
+)
diff --git a/banyand/trace/trace.go b/banyand/trace/trace.go
index 327224a2..f1815671 100644
--- a/banyand/trace/trace.go
+++ b/banyand/trace/trace.go
@@ -182,7 +182,12 @@ func (t *trace) querySidxForTraceIDs(ctx context.Context, 
sidxInstances []sidx.S
 
        for i, data := range response.Data {
                if len(data) > 0 {
-                       traceID := string(data)
+                       var traceID string
+                       if len(data) > 0 && idFormat(data[0]) == idFormatV1 {
+                               traceID = string(data[1:])
+                       } else {
+                               logger.Panicf("invalid trace ID format: %x", 
data)
+                       }
                        if !seenTraceIDs[traceID] {
                                seenTraceIDs[traceID] = true
                                traceIDs = append(traceIDs, traceID)
diff --git a/banyand/trace/write_standalone.go 
b/banyand/trace/write_standalone.go
index 6ef873fd..da0e0214 100644
--- a/banyand/trace/write_standalone.go
+++ b/banyand/trace/write_standalone.go
@@ -291,8 +291,13 @@ func processTraces(schemaRepo *schemaRepo, tracesInTable 
*tracesInTable, writeEv
                        }
                }
 
+               // Add control bit at the first position for backward 
compatibility
+               data := make([]byte, len(traceID)+1)
+               data[0] = byte(idFormatV1) // Control bit indicating new format
+               copy(data[1:], traceID)
+
                writeReq := sidx.WriteRequest{
-                       Data:     []byte(traceID),
+                       Data:     data,
                        Tags:     filteredSidxTags,
                        SeriesID: series.ID,
                        Key:      key,

Reply via email to