mrproliu commented on code in PR #1142:
URL:
https://github.com/apache/skywalking-banyandb/pull/1142#discussion_r3301273476
##########
banyand/stream/test_helper.go:
##########
@@ -18,75 +18,162 @@
package stream
import (
+ "fmt"
+ "path/filepath"
"time"
"github.com/apache/skywalking-banyandb/api/common"
+ databasev1
"github.com/apache/skywalking-banyandb/api/proto/banyandb/database/v1"
+ modelv1
"github.com/apache/skywalking-banyandb/api/proto/banyandb/model/v1"
+ "github.com/apache/skywalking-banyandb/banyand/internal/storage"
"github.com/apache/skywalking-banyandb/pkg/convert"
"github.com/apache/skywalking-banyandb/pkg/fs"
- pbv1 "github.com/apache/skywalking-banyandb/pkg/pb/v1"
+ "github.com/apache/skywalking-banyandb/pkg/index"
)
-// CreateTestPartForDump creates a test stream part for testing the dump tool.
-// It takes a temporary path and a file system as input, generates test
elements with various tag types,
-// creates a memory part, flushes it to disk, and returns the path to the
created part directory.
-// Parameters:
-//
-// tmpPath: the base directory where the part will be created.
-// fileSystem: the file system to use for writing the part.
-//
-// Returns:
-//
-// The path to the created part directory and a cleanup function.
-func CreateTestPartForDump(tmpPath string, fileSystem fs.FileSystem) (string,
func()) {
- now := time.Now().UnixNano()
+// DumpTag describes one tag of a stream row for the dump test builder. Value
is a
+// Go-native value (string, int64, []string, []int64 or []byte) encoded through
+// the production encodeTagValue path.
+type DumpTag struct {
+ Value any
+ Family string
+ Name string
+}
- // Create test elements with various tag types
- es := &elements{
- seriesIDs: []common.SeriesID{1, 2, 3},
- timestamps: []int64{now, now + 1000, now + 2000},
- elementIDs: []uint64{11, 21, 31},
- tagFamilies: [][]tagValues{
- {
- {
- tag: "arrTag",
- values: []*tagValue{
- {tag: "strArrTag", valueType:
pbv1.ValueTypeStrArr, value: nil, valueArr: [][]byte{[]byte("value1"),
[]byte("value2")}},
- {tag: "intArrTag", valueType:
pbv1.ValueTypeInt64Arr, value: nil, valueArr:
[][]byte{convert.Int64ToBytes(25), convert.Int64ToBytes(30)}},
- },
- },
- {
- tag: "singleTag",
- values: []*tagValue{
- {tag: "strTag", valueType:
pbv1.ValueTypeStr, value: []byte("test-value"), valueArr: nil},
- {tag: "intTag", valueType:
pbv1.ValueTypeInt64, value: convert.Int64ToBytes(100), valueArr: nil},
- },
- },
- },
- {
- {
- tag: "singleTag",
- values: []*tagValue{
- {tag: "strTag1", valueType:
pbv1.ValueTypeStr, value: []byte("tag1"), valueArr: nil},
- {tag: "strTag2", valueType:
pbv1.ValueTypeStr, value: []byte("tag2"), valueArr: nil},
- },
- },
- },
- {}, // empty tagFamilies for seriesID 3
- },
+// DumpRow is one stream element for BuildPartForDump. When Entity is set the
+// SeriesID is derived as hash(Entity) and (optionally) written to smeta.bin.
+type DumpRow struct {
+ Entity string
+ Tags []DumpTag
+ SeriesID common.SeriesID
+ Timestamp int64
+ ElementID uint64
+}
+
+// BuildPartForDump writes rows into a stream part at root/<partID>, returning
the
+// part directory, the rows (with resolved SeriesID) for verification and a
+// cleanup func. When writeSeriesMeta is true a matching smeta.bin is written
for
+// every row that carries an Entity.
+func BuildPartForDump(tmpPath string, fileSystem fs.FileSystem, partID uint64,
rows []DumpRow) (string, []DumpRow, func()) {
+ es := &elements{}
+ for i := range rows {
+ r := &rows[i]
+ if r.Entity != "" {
+ r.SeriesID =
common.SeriesID(convert.Hash([]byte(r.Entity)))
+ }
+ es.seriesIDs = append(es.seriesIDs, r.SeriesID)
+ es.timestamps = append(es.timestamps, r.Timestamp)
+ es.elementIDs = append(es.elementIDs, r.ElementID)
+ es.tagFamilies = append(es.tagFamilies,
buildDumpTagFamilies(r.Tags))
}
- // Create memPart and flush
mp := generateMemPart()
mp.mustInitFromElements(es)
-
- epoch := uint64(12345)
- path := partPath(tmpPath, epoch)
+ path := partPath(tmpPath, partID)
mp.mustFlush(fileSystem, path)
- cleanup := func() {
- // Cleanup is handled by the caller's test.Space cleanup
+ return path, rows, func() {
releaseMemPart(mp)
Review Comment:
Update to using `generateDataPoints()` and `releaseDataPoints` to generate
and release the data points.
--
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]