You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@skywalking.apache.org by "mrproliu (via GitHub)" <gi...@apache.org> on 2026/01/22 03:30:04 UTC

[PR] Change the data storage path structure for property model [skywalking-banyandb]

mrproliu opened a new pull request, #955:
URL: https://github.com/apache/skywalking-banyandb/pull/955

   
   - [ ] If this pull request closes/resolves/fixes an existing issue, replace the issue number. Fixes apache/skywalking#<issue number>.
   - [x] Update the [`CHANGES` log](https://github.com/apache/skywalking-banyandb/blob/main/CHANGES.md).
   


-- 
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: notifications-unsubscribe@skywalking.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Change the data storage path structure for property model [skywalking-banyandb]

Posted by "hanahmily (via GitHub)" <gi...@apache.org>.
hanahmily commented on code in PR #955:
URL: https://github.com/apache/skywalking-banyandb/pull/955#discussion_r2715369989


##########
banyand/property/listener.go:
##########
@@ -234,30 +234,38 @@ func (s *snapshotListener) Rev(ctx context.Context, message bus.Message) bus.Mes
 	defer s.snapshotMux.Unlock()
 	storage.DeleteStaleSnapshots(s.s.snapshotDir, s.s.maxFileSnapshotNum, s.s.minFileSnapshotAge, s.s.lfs)
 	sn := s.snapshotName()
-	shardsRef := s.s.db.sLst.Load()
-	if shardsRef == nil {
-		return bus.NewMessage(bus.MessageID(time.Now().UnixNano()), nil)
-	}
-	shards := *shardsRef
-	for _, shard := range shards {
-		select {
-		case <-ctx.Done():
-			return bus.NewMessage(bus.MessageID(time.Now().UnixNano()), nil)
-		default:
+	var snapshotResult *databasev1.Snapshot
+	s.s.db.groups.Range(func(_, value any) bool {
+		gs := value.(*groupShards)
+		sLst := gs.shards.Load()
+		if sLst == nil {
+			return true
 		}
-		snpDir := path.Join(s.s.snapshotDir, sn, storage.DataDir, filepath.Base(shard.location))
-		lfs.MkdirPanicIfExist(snpDir, storage.DirPerm)
-		err := shard.store.TakeFileSnapshot(snpDir)
-		if err != nil {
-			s.s.l.Error().Err(err).Str("shard", filepath.Base(shard.location)).Msg("fail to take shard snapshot")
-			return bus.NewMessage(bus.MessageID(time.Now().UnixNano()), &databasev1.Snapshot{
-				Name:    sn,
-				Catalog: commonv1.Catalog_CATALOG_PROPERTY,
-				Error:   err.Error(),
-			})
+		for _, shardRef := range *sLst {
+			select {
+			case <-ctx.Done():

Review Comment:
   @mrproliu, could you check this suggestion, which seems to make sense. 



-- 
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: notifications-unsubscribe@skywalking.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Change the data storage path structure for property model [skywalking-banyandb]

Posted by "hanahmily (via GitHub)" <gi...@apache.org>.
hanahmily merged PR #955:
URL: https://github.com/apache/skywalking-banyandb/pull/955


-- 
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: notifications-unsubscribe@skywalking.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Change the data storage path structure for property model [skywalking-banyandb]

Posted by "mrproliu (via GitHub)" <gi...@apache.org>.
mrproliu commented on code in PR #955:
URL: https://github.com/apache/skywalking-banyandb/pull/955#discussion_r2715372911


##########
banyand/property/listener.go:
##########
@@ -234,30 +234,38 @@ func (s *snapshotListener) Rev(ctx context.Context, message bus.Message) bus.Mes
 	defer s.snapshotMux.Unlock()
 	storage.DeleteStaleSnapshots(s.s.snapshotDir, s.s.maxFileSnapshotNum, s.s.minFileSnapshotAge, s.s.lfs)
 	sn := s.snapshotName()
-	shardsRef := s.s.db.sLst.Load()
-	if shardsRef == nil {
-		return bus.NewMessage(bus.MessageID(time.Now().UnixNano()), nil)
-	}
-	shards := *shardsRef
-	for _, shard := range shards {
-		select {
-		case <-ctx.Done():
-			return bus.NewMessage(bus.MessageID(time.Now().UnixNano()), nil)
-		default:
+	var snapshotResult *databasev1.Snapshot
+	s.s.db.groups.Range(func(_, value any) bool {
+		gs := value.(*groupShards)
+		sLst := gs.shards.Load()
+		if sLst == nil {
+			return true
 		}
-		snpDir := path.Join(s.s.snapshotDir, sn, storage.DataDir, filepath.Base(shard.location))
-		lfs.MkdirPanicIfExist(snpDir, storage.DirPerm)
-		err := shard.store.TakeFileSnapshot(snpDir)
-		if err != nil {
-			s.s.l.Error().Err(err).Str("shard", filepath.Base(shard.location)).Msg("fail to take shard snapshot")
-			return bus.NewMessage(bus.MessageID(time.Now().UnixNano()), &databasev1.Snapshot{
-				Name:    sn,
-				Catalog: commonv1.Catalog_CATALOG_PROPERTY,
-				Error:   err.Error(),
-			})
+		for _, shardRef := range *sLst {
+			select {
+			case <-ctx.Done():

Review Comment:
   Done. It makes sense that if the context is canceled, then it should return an error. 



-- 
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: notifications-unsubscribe@skywalking.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Change the data storage path structure for property model [skywalking-banyandb]

Posted by "hanahmily (via GitHub)" <gi...@apache.org>.
hanahmily commented on code in PR #955:
URL: https://github.com/apache/skywalking-banyandb/pull/955#discussion_r2715192113


##########
banyand/property/db.go:
##########
@@ -216,34 +248,87 @@ func (db *database) query(ctx context.Context, req *propertyv1.QueryRequest) ([]
 	return result, nil
 }
 
-func (db *database) loadShard(ctx context.Context, id common.ShardID) (*shard, error) {
+func (db *database) collectGroupShards(groupsMap *map[string]*groupShards, requestedGroups map[string]bool) []*shard {
+	var shards []*shard
+	for groupName, gs := range *groupsMap {
+		if len(requestedGroups) > 0 {
+			if _, ok := requestedGroups[groupName]; !ok {
+				continue
+			}
+		}
+		sLst := gs.shards.Load()
+		if sLst == nil {
+			continue
+		}
+		shards = append(shards, *sLst...)
+	}
+	return shards
+}
+
+func (db *database) loadShard(ctx context.Context, group string, id common.ShardID) (*shard, error) {
 	if db.closed.Load() {
 		return nil, errors.New("database is closed")
 	}
-	if s, ok := db.getShard(id); ok {
+	if s, ok := db.getShard(group, id); ok {
 		return s, nil
 	}
 	db.mu.Lock()
 	defer db.mu.Unlock()
-	if s, ok := db.getShard(id); ok {
+	if s, ok := db.getShard(group, id); ok {
 		return s, nil
 	}
-	sd, err := db.newShard(context.WithValue(ctx, logger.ContextKey, db.logger), id, int64(db.flushInterval.Seconds()),
+
+	gs := db.getOrCreateGroupShards(group)
+	sd, err := db.newShard(context.WithValue(ctx, logger.ContextKey, db.logger),
+		group, id, int64(db.flushInterval.Seconds()),
 		int64(db.expireDelete.Seconds()), db.repairBaseDir, db.repairTreeSlotCount)
 	if err != nil {
 		return nil, err
 	}
-	sLst := db.sLst.Load()
+
+	gs.mu.Lock()
+	sLst := gs.shards.Load()
 	if sLst == nil {
 		sLst = &[]*shard{}
 	}
-	*sLst = append(*sLst, sd)
-	db.sLst.Store(sLst)
+	newList := append(*sLst, sd)
+	gs.shards.Store(&newList)
+	gs.mu.Unlock()
 	return sd, nil
 }
 
-func (db *database) getShard(id common.ShardID) (*shard, bool) {
-	sLst := db.sLst.Load()
+func (db *database) getOrCreateGroupShards(group string) *groupShards {
+	groupsMap := db.groups.Load()
+	if groupsMap != nil {
+		if gs, ok := (*groupsMap)[group]; ok {
+			return gs
+		}
+	}
+	gs := &groupShards{
+		group:    group,
+		location: filepath.Join(db.location, group),
+	}
+	if groupsMap == nil {
+		newMap := make(map[string]*groupShards)
+		newMap[group] = gs
+		db.groups.Store(&newMap)
+	} else {
+		(*groupsMap)[group] = gs
+		db.groups.Store(groupsMap)

Review Comment:
   Use sync.Map to fix it.



##########
banyand/property/db.go:
##########
@@ -216,34 +248,87 @@ func (db *database) query(ctx context.Context, req *propertyv1.QueryRequest) ([]
 	return result, nil
 }
 
-func (db *database) loadShard(ctx context.Context, id common.ShardID) (*shard, error) {
+func (db *database) collectGroupShards(groupsMap *map[string]*groupShards, requestedGroups map[string]bool) []*shard {
+	var shards []*shard
+	for groupName, gs := range *groupsMap {
+		if len(requestedGroups) > 0 {
+			if _, ok := requestedGroups[groupName]; !ok {
+				continue
+			}
+		}
+		sLst := gs.shards.Load()
+		if sLst == nil {
+			continue
+		}
+		shards = append(shards, *sLst...)
+	}
+	return shards
+}
+
+func (db *database) loadShard(ctx context.Context, group string, id common.ShardID) (*shard, error) {
 	if db.closed.Load() {
 		return nil, errors.New("database is closed")
 	}
-	if s, ok := db.getShard(id); ok {
+	if s, ok := db.getShard(group, id); ok {
 		return s, nil
 	}
 	db.mu.Lock()
 	defer db.mu.Unlock()
-	if s, ok := db.getShard(id); ok {
+	if s, ok := db.getShard(group, id); ok {
 		return s, nil
 	}
-	sd, err := db.newShard(context.WithValue(ctx, logger.ContextKey, db.logger), id, int64(db.flushInterval.Seconds()),
+
+	gs := db.getOrCreateGroupShards(group)
+	sd, err := db.newShard(context.WithValue(ctx, logger.ContextKey, db.logger),
+		group, id, int64(db.flushInterval.Seconds()),
 		int64(db.expireDelete.Seconds()), db.repairBaseDir, db.repairTreeSlotCount)
 	if err != nil {
 		return nil, err
 	}
-	sLst := db.sLst.Load()
+
+	gs.mu.Lock()
+	sLst := gs.shards.Load()
 	if sLst == nil {
 		sLst = &[]*shard{}
 	}
-	*sLst = append(*sLst, sd)
-	db.sLst.Store(sLst)
+	newList := append(*sLst, sd)
+	gs.shards.Store(&newList)

Review Comment:
   fix it.



##########
banyand/property/db.go:
##########
@@ -52,14 +52,21 @@ var (
 	propertyScope = observability.RootScope.SubScope("property")
 )
 
+type groupShards struct {
+	shards   atomic.Pointer[[]*shard]
+	group    string
+	location string
+	mu       sync.RWMutex
+}
+
 type database struct {
 	metadata            metadata.Repo
 	omr                 observability.MetricsRegistry
 	lfs                 fs.FileSystem
 	lock                fs.File
 	logger              *logger.Logger
 	repairScheduler     *repairScheduler
-	sLst                atomic.Pointer[[]*shard]
+	groups              atomic.Pointer[map[string]*groupShards]

Review Comment:
   An atomic pointer cannot guarantee the safe operation on the map. Use sync.Map instead. 



-- 
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: notifications-unsubscribe@skywalking.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Change the data storage path structure for property model [skywalking-banyandb]

Posted by "codecov-commenter (via GitHub)" <gi...@apache.org>.
codecov-commenter commented on PR #955:
URL: https://github.com/apache/skywalking-banyandb/pull/955#issuecomment-3782387176

   ## [Codecov](https://app.codecov.io/gh/apache/skywalking-banyandb/pull/955?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) Report
   :white_check_mark: All modified and coverable lines are covered by tests.
   :white_check_mark: Project coverage is 29.36%. Comparing base ([`3530dd9`](https://app.codecov.io/gh/apache/skywalking-banyandb/commit/3530dd9b5cefaa4fef60eec91ecbfbdfcaf243c5?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)) to head ([`f5a0f87`](https://app.codecov.io/gh/apache/skywalking-banyandb/commit/f5a0f87f3fc5b263ed90b7138027a8cc078ddc4a?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)).
   :warning: Report is 120 commits behind head on main.
   > :exclamation:  There is a different number of reports uploaded between BASE (3530dd9) and HEAD (f5a0f87). Click for more details.
   > 
   > <details><summary>HEAD has 1 upload less than BASE</summary>
   >
   >| Flag | BASE (3530dd9) | HEAD (f5a0f87) |
   >|------|------|------|
   >||1|0|
   ></details>
   
   <details><summary>Additional details and impacted files</summary>
   
   
   
   ```diff
   @@             Coverage Diff             @@
   ##             main     #955       +/-   ##
   ===========================================
   - Coverage   45.97%   29.36%   -16.62%     
   ===========================================
     Files         328      118      -210     
     Lines       55505    12286    -43219     
   ===========================================
   - Hits        25520     3608    -21912     
   + Misses      27909     8338    -19571     
   + Partials     2076      340     -1736     
   ```
   
   | [Flag](https://app.codecov.io/gh/apache/skywalking-banyandb/pull/955/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | Coverage Δ | |
   |---|---|---|
   | [pkg](https://app.codecov.io/gh/apache/skywalking-banyandb/pull/955/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `29.36% <ø> (?)` | |
   
   Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#carryforward-flags-in-the-pull-request-comment) to find out more.
   </details>
   
   [:umbrella: View full report in Codecov by Sentry](https://app.codecov.io/gh/apache/skywalking-banyandb/pull/955?dropdown=coverage&src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).   
   :loudspeaker: Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).
   <details><summary> :rocket: New features to boost your workflow: </summary>
   
   - :snowflake: [Test Analytics](https://docs.codecov.com/docs/test-analytics): Detect flaky tests, report on failures, and find test suite problems.
   - :package: [JS Bundle Analysis](https://docs.codecov.com/docs/javascript-bundle-analysis): Save yourself from yourself by tracking and limiting bundle sizes in JS merges.
   </details>


-- 
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: notifications-unsubscribe@skywalking.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Change the data storage path structure for property model [skywalking-banyandb]

Posted by "Copilot (via GitHub)" <gi...@apache.org>.
Copilot commented on code in PR #955:
URL: https://github.com/apache/skywalking-banyandb/pull/955#discussion_r2715180526


##########
CHANGES.md:
##########
@@ -18,6 +18,9 @@ Release Notes.
 - Update the dump tool to support analyzing the parts with smeta files.
 - Activate the property repair mechanism by default.
 - Add snapshot time retention policy to ensure the snapshot only can be deleted after the configured minimum age(time).
+- **Breaking Change**: Change the data storage path structure for property model:
+  - From: `<data-dir>/property/<shard>/...`
+  - To: `<data-dir>/property/group/<shard>/...`

Review Comment:
   The new on-disk layout implemented by the code is `<data-dir>/property/<group>/<shard>/...` (group name as a directory). The CHANGES entry currently says `<data-dir>/property/group/<shard>/...`, which reads like a literal `group` directory and is likely misleading—please update the text to match the actual layout (and consider including the `shard-<id>` naming).
   ```suggestion
     - From: `<data-dir>/property/shard-<id>/...`
     - To: `<data-dir>/property/<group>/shard-<id>/...`
   ```



##########
banyand/property/db.go:
##########
@@ -216,34 +248,87 @@ func (db *database) query(ctx context.Context, req *propertyv1.QueryRequest) ([]
 	return result, nil
 }
 
-func (db *database) loadShard(ctx context.Context, id common.ShardID) (*shard, error) {
+func (db *database) collectGroupShards(groupsMap *map[string]*groupShards, requestedGroups map[string]bool) []*shard {
+	var shards []*shard
+	for groupName, gs := range *groupsMap {
+		if len(requestedGroups) > 0 {
+			if _, ok := requestedGroups[groupName]; !ok {
+				continue
+			}
+		}
+		sLst := gs.shards.Load()
+		if sLst == nil {
+			continue
+		}
+		shards = append(shards, *sLst...)
+	}
+	return shards
+}
+
+func (db *database) loadShard(ctx context.Context, group string, id common.ShardID) (*shard, error) {
 	if db.closed.Load() {
 		return nil, errors.New("database is closed")
 	}
-	if s, ok := db.getShard(id); ok {
+	if s, ok := db.getShard(group, id); ok {
 		return s, nil
 	}
 	db.mu.Lock()
 	defer db.mu.Unlock()
-	if s, ok := db.getShard(id); ok {
+	if s, ok := db.getShard(group, id); ok {
 		return s, nil
 	}
-	sd, err := db.newShard(context.WithValue(ctx, logger.ContextKey, db.logger), id, int64(db.flushInterval.Seconds()),
+
+	gs := db.getOrCreateGroupShards(group)
+	sd, err := db.newShard(context.WithValue(ctx, logger.ContextKey, db.logger),
+		group, id, int64(db.flushInterval.Seconds()),
 		int64(db.expireDelete.Seconds()), db.repairBaseDir, db.repairTreeSlotCount)
 	if err != nil {
 		return nil, err
 	}
-	sLst := db.sLst.Load()
+
+	gs.mu.Lock()
+	sLst := gs.shards.Load()
 	if sLst == nil {
 		sLst = &[]*shard{}
 	}
-	*sLst = append(*sLst, sd)
-	db.sLst.Store(sLst)
+	newList := append(*sLst, sd)
+	gs.shards.Store(&newList)

Review Comment:
   `newList := append(*sLst, sd)` can reuse the backing array of `*sLst` and mutate it in-place. Since readers access `gs.shards.Load()` without taking `gs.mu`, this can cause data races / inconsistent reads. Build the new slice with a guaranteed new backing array (e.g., copy to a fresh slice before appending) before storing it.



##########
banyand/property/repair.go:
##########
@@ -710,31 +686,30 @@ func (r *repairTreeComposer) append(id, shaVal string) (err error) {
 	return file.append(idBytes, shaValBytes)
 }
 
-// composeNextGroupAndSave composes the current group of slot files into a repair tree file.
+// composeAndSave composes the slot files into a repair tree file.
 // tree file format: [leaf nodes]+[slot nodes]+[root node]+[metadata]
 // leaf nodes: each node contains: [entity]+[sha value]
 // slot nodes: each node contains: [slot index]+[sha value]+[leaf nodes start offset]+[leaf nodes count]
 // root node: contains [sha value]
 // metadata: contains footer([slot nodes start offset]+[slot nodes count]+[root node start offset]+[root node length])+[footer length(data binary)]
-func (r *repairTreeComposer) composeNextGroupAndSave(group string) (err error) {
-	treeFilePath := fmt.Sprintf(r.treeFileFmt, group)
-	treeBuilder, err := newRepairTreeBuilder(treeFilePath)
+func (r *repairTreeComposer) composeAndSave() (err error) {
+	treeBuilder, err := newRepairTreeBuilder(r.treeFilePath)
 	if err != nil {
-		return fmt.Errorf("creating repair tree builder for group %s failure: %w", group, err)
+		return fmt.Errorf("creating repair tree builder failure: %w", err)
 	}
 	defer func() {
 		if closeErr := treeBuilder.close(); closeErr != nil {
-			err = multierr.Append(err, fmt.Errorf("closing repair tree builder for group %s failure: %w", group, closeErr))
+			err = multierr.Append(err, fmt.Errorf("closing repair tree builder failure: %w", closeErr))
 		}

Review Comment:
   With a single `state-tree.data` file being overwritten, make sure the tree file is truncated/rewritten atomically. `newRepairTreeBuilder` currently opens the file without `O_TRUNC` (and doesn’t call `Truncate(0)`), so rebuilding a smaller tree can leave stale bytes at the end and cause `treeReader()` to read the old footer. Fix by truncating/removing the file before writing (or opening with `os.O_TRUNC`).



##########
banyand/property/db.go:
##########
@@ -216,34 +248,87 @@ func (db *database) query(ctx context.Context, req *propertyv1.QueryRequest) ([]
 	return result, nil
 }
 
-func (db *database) loadShard(ctx context.Context, id common.ShardID) (*shard, error) {
+func (db *database) collectGroupShards(groupsMap *map[string]*groupShards, requestedGroups map[string]bool) []*shard {
+	var shards []*shard
+	for groupName, gs := range *groupsMap {
+		if len(requestedGroups) > 0 {
+			if _, ok := requestedGroups[groupName]; !ok {
+				continue
+			}
+		}
+		sLst := gs.shards.Load()
+		if sLst == nil {
+			continue
+		}
+		shards = append(shards, *sLst...)
+	}
+	return shards
+}
+
+func (db *database) loadShard(ctx context.Context, group string, id common.ShardID) (*shard, error) {
 	if db.closed.Load() {
 		return nil, errors.New("database is closed")
 	}
-	if s, ok := db.getShard(id); ok {
+	if s, ok := db.getShard(group, id); ok {
 		return s, nil
 	}
 	db.mu.Lock()
 	defer db.mu.Unlock()
-	if s, ok := db.getShard(id); ok {
+	if s, ok := db.getShard(group, id); ok {
 		return s, nil
 	}
-	sd, err := db.newShard(context.WithValue(ctx, logger.ContextKey, db.logger), id, int64(db.flushInterval.Seconds()),
+
+	gs := db.getOrCreateGroupShards(group)
+	sd, err := db.newShard(context.WithValue(ctx, logger.ContextKey, db.logger),
+		group, id, int64(db.flushInterval.Seconds()),
 		int64(db.expireDelete.Seconds()), db.repairBaseDir, db.repairTreeSlotCount)
 	if err != nil {
 		return nil, err
 	}
-	sLst := db.sLst.Load()
+
+	gs.mu.Lock()
+	sLst := gs.shards.Load()
 	if sLst == nil {
 		sLst = &[]*shard{}
 	}
-	*sLst = append(*sLst, sd)
-	db.sLst.Store(sLst)
+	newList := append(*sLst, sd)
+	gs.shards.Store(&newList)
+	gs.mu.Unlock()
 	return sd, nil
 }
 
-func (db *database) getShard(id common.ShardID) (*shard, bool) {
-	sLst := db.sLst.Load()
+func (db *database) getOrCreateGroupShards(group string) *groupShards {
+	groupsMap := db.groups.Load()
+	if groupsMap != nil {
+		if gs, ok := (*groupsMap)[group]; ok {
+			return gs
+		}
+	}
+	gs := &groupShards{
+		group:    group,
+		location: filepath.Join(db.location, group),
+	}
+	if groupsMap == nil {
+		newMap := make(map[string]*groupShards)
+		newMap[group] = gs
+		db.groups.Store(&newMap)
+	} else {
+		(*groupsMap)[group] = gs
+		db.groups.Store(groupsMap)

Review Comment:
   `getOrCreateGroupShards` mutates the existing `map[string]*groupShards` in-place (`(*groupsMap)[group] = gs`) and then re-stores the same map pointer. Callers like `delete/query/collect/close` iterate over `*groupsMap` without holding `db.mu`, so this can trigger `concurrent map iteration and map write` panics. Use copy-on-write (allocate a new map, copy entries, add the new group, then `Store` the new pointer) or protect all reads with the same lock used for writes.
   ```suggestion
   		// Use copy-on-write: create a new map, copy existing entries, then add the new group.
   		oldMap := *groupsMap
   		newMap := make(map[string]*groupShards, len(oldMap)+1)
   		for k, v := range oldMap {
   			newMap[k] = v
   		}
   		newMap[group] = gs
   		db.groups.Store(&newMap)
   ```



-- 
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: notifications-unsubscribe@skywalking.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Change the data storage path structure for property model [skywalking-banyandb]

Posted by "Copilot (via GitHub)" <gi...@apache.org>.
Copilot commented on code in PR #955:
URL: https://github.com/apache/skywalking-banyandb/pull/955#discussion_r2715364295


##########
banyand/property/listener.go:
##########
@@ -234,30 +234,38 @@ func (s *snapshotListener) Rev(ctx context.Context, message bus.Message) bus.Mes
 	defer s.snapshotMux.Unlock()
 	storage.DeleteStaleSnapshots(s.s.snapshotDir, s.s.maxFileSnapshotNum, s.s.minFileSnapshotAge, s.s.lfs)
 	sn := s.snapshotName()
-	shardsRef := s.s.db.sLst.Load()
-	if shardsRef == nil {
-		return bus.NewMessage(bus.MessageID(time.Now().UnixNano()), nil)
-	}
-	shards := *shardsRef
-	for _, shard := range shards {
-		select {
-		case <-ctx.Done():
-			return bus.NewMessage(bus.MessageID(time.Now().UnixNano()), nil)
-		default:
+	var snapshotResult *databasev1.Snapshot
+	s.s.db.groups.Range(func(_, value any) bool {
+		gs := value.(*groupShards)
+		sLst := gs.shards.Load()
+		if sLst == nil {
+			return true
 		}
-		snpDir := path.Join(s.s.snapshotDir, sn, storage.DataDir, filepath.Base(shard.location))
-		lfs.MkdirPanicIfExist(snpDir, storage.DirPerm)
-		err := shard.store.TakeFileSnapshot(snpDir)
-		if err != nil {
-			s.s.l.Error().Err(err).Str("shard", filepath.Base(shard.location)).Msg("fail to take shard snapshot")
-			return bus.NewMessage(bus.MessageID(time.Now().UnixNano()), &databasev1.Snapshot{
-				Name:    sn,
-				Catalog: commonv1.Catalog_CATALOG_PROPERTY,
-				Error:   err.Error(),
-			})
+		for _, shardRef := range *sLst {
+			select {
+			case <-ctx.Done():

Review Comment:
   If the snapshot context is cancelled, the callback returns false and stops iteration, but the function still falls through and returns a successful Snapshot (with no Error). This changes behavior vs the previous early-return on ctx.Done() and can report a snapshot that was never fully created. Consider tracking ctx.Err() (or setting snapshotResult to an error Snapshot) and returning early/with error when ctx is cancelled.
   ```suggestion
   			case <-ctx.Done():
   				// Context cancelled: record an error snapshot and stop iteration.
   				if err := ctx.Err(); err != nil {
   					snapshotResult = &databasev1.Snapshot{
   						Name:    sn,
   						Catalog: commonv1.Catalog_CATALOG_PROPERTY,
   						Error:   err.Error(),
   					}
   				}
   ```



##########
CHANGES.md:
##########
@@ -19,6 +19,9 @@ Release Notes.
 - Add replication integration test for measure.
 - Activate the property repair mechanism by default.
 - Add snapshot time retention policy to ensure the snapshot only can be deleted after the configured minimum age(time).
+- **Breaking Change**: Change the data storage path structure for property model:
+  - From: `<data-dir>/property/shard-<id>/...`
+  - To: `<data-dir>/property/<group>/shard-<id>/...`

Review Comment:
   The breaking-change paths here appear to miss the `data` segment. The property service opens the DB at `<root>/property/data` (see banyand/property/service.go:147), so the old/new shard paths are `<data-dir>/property/data/shard-<id>/...` -> `<data-dir>/property/data/<group>/shard-<id>/...`. Updating this avoids confusing operators during upgrade/migration.
   ```suggestion
     - From: `<data-dir>/property/data/shard-<id>/...`
     - To: `<data-dir>/property/data/<group>/shard-<id>/...`
   ```



-- 
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: notifications-unsubscribe@skywalking.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org