robocanic commented on code in PR #1349:
URL: https://github.com/apache/dubbo-admin/pull/1349#discussion_r2486318731


##########
pkg/store/mysql/mysql.go:
##########
@@ -17,4 +17,705 @@
 
 package mysql
 
-// TODO implement memory resource store, refer to GORM https://gorm.io/docs/
+import (
+       "errors"
+       "fmt"
+       "reflect"
+       "sort"
+       "sync"
+
+       storecfg "github.com/apache/dubbo-admin/pkg/config/store"
+       "gorm.io/gorm"
+       "k8s.io/client-go/tools/cache"
+
+       "github.com/apache/dubbo-admin/pkg/common/bizerror"
+       "github.com/apache/dubbo-admin/pkg/core/logger"
+       "github.com/apache/dubbo-admin/pkg/core/resource/model"
+       "github.com/apache/dubbo-admin/pkg/core/runtime"
+       "github.com/apache/dubbo-admin/pkg/core/store"
+       "github.com/apache/dubbo-admin/pkg/store/dbcommon"
+)
+
+func init() {
+       store.RegisterFactory(&mysqlStoreFactory{})
+}
+
+// mysqlStoreFactory is the factory for creating MySQL store instances
+type mysqlStoreFactory struct{}
+
+var _ store.Factory = &mysqlStoreFactory{}
+
+// Support checks if this factory supports the given store type
+func (f *mysqlStoreFactory) Support(s storecfg.Type) bool {
+       return s == storecfg.MySQL
+}
+
+// New creates a new MySQL store instance for the specified resource kind
+func (f *mysqlStoreFactory) New(kind model.ResourceKind, cfg *storecfg.Config) 
(store.ManagedResourceStore, error) {
+       return NewMySQLStore(kind, cfg.Address)
+}
+
+// mysqlStore is a MySQL-backed store implementation for Dubbo resources
+// It uses GORM for database operations and maintains in-memory indices for 
fast lookups
+type mysqlStore struct {
+       pool        *dbcommon.ConnectionPool                  // Shared 
connection pool with reference counting
+       kind        model.ResourceKind                        // The resource 
kind this store manages
+       address     string                                    // MySQL 
connection address
+       indexers    cache.Indexers                            // Index 
functions for creating indices
+       indexerLock sync.RWMutex                              // Protects 
indexers map
+       indices     map[string]map[string]map[string]struct{} // In-memory 
index: map[indexName]map[indexedValue]set[resourceKey]

Review Comment:
   suggestion: 
这里可以考虑为索引定义一个单独的数据结构Index,现在这种多层的map结构易读性不太好,另外更新索引的原子操作可以放在这个Index里面完成,不用在外层加锁。其次是set这个结构可以考虑使用lancet的"github.com/duke-git/lancet/v2/datastructure/set"。lancet中还有其他的工具可以多多使用



-- 
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]

Reply via email to