mirror of
				https://github.com/taigrr/bitcask
				synced 2025-01-18 04:03:17 -08:00 
			
		
		
		
	Fixed concurrency bug with reopening datafiles when maxDatafileSize is exceeded
This commit is contained in:
		
							parent
							
								
									c593bc966f
								
							
						
					
					
						commit
						7149cb9afe
					
				| @ -8,6 +8,7 @@ import ( | |||||||
| 	"os" | 	"os" | ||||||
| 	"path/filepath" | 	"path/filepath" | ||||||
| 	"strings" | 	"strings" | ||||||
|  | 	"sync" | ||||||
| 
 | 
 | ||||||
| 	"github.com/gofrs/flock" | 	"github.com/gofrs/flock" | ||||||
| 	"github.com/prologic/trie" | 	"github.com/prologic/trie" | ||||||
| @ -40,6 +41,8 @@ var ( | |||||||
| // and in-memory hash of key/value pairs as per the Bitcask paper and seen | // and in-memory hash of key/value pairs as per the Bitcask paper and seen | ||||||
| // in the Riak database. | // in the Riak database. | ||||||
| type Bitcask struct { | type Bitcask struct { | ||||||
|  | 	mu sync.RWMutex | ||||||
|  | 
 | ||||||
| 	*flock.Flock | 	*flock.Flock | ||||||
| 
 | 
 | ||||||
| 	config    *config | 	config    *config | ||||||
| @ -175,6 +178,9 @@ func (b *Bitcask) Fold(f func(key string) error) error { | |||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func (b *Bitcask) put(key string, value []byte) (int64, error) { | func (b *Bitcask) put(key string, value []byte) (int64, error) { | ||||||
|  | 	b.mu.Lock() | ||||||
|  | 	defer b.mu.Unlock() | ||||||
|  | 
 | ||||||
| 	size := b.curr.Size() | 	size := b.curr.Size() | ||||||
| 	if size >= int64(b.config.maxDatafileSize) { | 	if size >= int64(b.config.maxDatafileSize) { | ||||||
| 		err := b.curr.Close() | 		err := b.curr.Close() | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user