mirror of
				https://github.com/TeaOSLab/EdgeNode.git
				synced 2025-11-04 07:40:56 +08:00 
			
		
		
		
	为KV存储增加文件锁
This commit is contained in:
		@@ -14,7 +14,7 @@ type DB struct {
 | 
			
		||||
	namespace string
 | 
			
		||||
	tableMap  map[string]TableInterface
 | 
			
		||||
 | 
			
		||||
	locker sync.RWMutex
 | 
			
		||||
	mu sync.RWMutex
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func NewDB(store *Store, dbName string) (*DB, error) {
 | 
			
		||||
@@ -34,8 +34,8 @@ func (this *DB) AddTable(table TableInterface) {
 | 
			
		||||
	table.SetNamespace([]byte(this.Namespace() + table.Name() + "$"))
 | 
			
		||||
	table.SetDB(this)
 | 
			
		||||
 | 
			
		||||
	this.locker.Lock()
 | 
			
		||||
	defer this.locker.Unlock()
 | 
			
		||||
	this.mu.Lock()
 | 
			
		||||
	defer this.mu.Unlock()
 | 
			
		||||
 | 
			
		||||
	this.tableMap[table.Name()] = table
 | 
			
		||||
}
 | 
			
		||||
@@ -53,8 +53,8 @@ func (this *DB) Store() *Store {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (this *DB) Close() error {
 | 
			
		||||
	this.locker.Lock()
 | 
			
		||||
	defer this.locker.Unlock()
 | 
			
		||||
	this.mu.Lock()
 | 
			
		||||
	defer this.mu.Unlock()
 | 
			
		||||
 | 
			
		||||
	var lastErr error
 | 
			
		||||
	for _, table := range this.tableMap {
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user