MCPcopy Index your code
hub / github.com/ByteStorage/FlyDB / NewDB

Function NewDB

engine/db.go:59–101  ·  view source on GitHub ↗

NewDB open a new db instance

(options config.Options)

Source from the content-addressed store, hash-verified

57
58// NewDB open a new db instance
59func NewDB(options config.Options) (*DB, error) {
60 zap.L().Info("open db", zap.Any("options", options))
61 // check options first
62 if err := checkOptions(options); err != nil {
63 return nil, err
64 }
65
66 // check data dir, if not exist, create it
67 if _, err := os.Stat(options.DirPath); os.IsNotExist(err) {
68 if err := os.MkdirAll(options.DirPath, os.ModePerm); err != nil {
69 return nil, err
70 }
71 }
72
73 // init db instance
74 db := &DB{
75 options: options,
76 lock: new(sync.RWMutex),
77 olderFiles: make(map[uint32]*data2.DataFile),
78 index: index.NewIndexer(options.IndexType, options.DirPath),
79 }
80
81 // load merge files
82 if err := db.loadMergeFiles(); err != nil {
83 return nil, err
84 }
85
86 // load data files
87 if err := db.loadDataFiles(); err != nil {
88 return nil, err
89 }
90
91 // load index from hint file
92 if err := db.loadIndexFromHintFile(); err != nil {
93 return nil, err
94 }
95
96 // load index from data files
97 if err := db.loadIndexFromDataFiles(); err != nil {
98 return nil, err
99 }
100 return db, nil
101}
102
103func checkOptions(options config.Options) error {
104 if options.DirPath == "" {

Callers 15

newHttpHandlerFunction · 0.92
NewLogFlyDbStorageFunction · 0.92
NewRaftClusterFunction · 0.92
NewBitMapStructureFunction · 0.92
NewSetStructureFunction · 0.92
NewHashStructureFunction · 0.92
NewStringStructureFunction · 0.92
NewZSetStructureFunction · 0.92
NewStreamStructureFunction · 0.92
NewExpireStructureFunction · 0.92
NewBitmapFunction · 0.92
NewListStructureFunction · 0.92

Calls 6

loadMergeFilesMethod · 0.95
loadDataFilesMethod · 0.95
loadIndexFromHintFileMethod · 0.95
NewIndexerFunction · 0.92
checkOptionsFunction · 0.85

Tested by 15

newHttpHandlerFunction · 0.74
ReturnNewDBFunction · 0.74
TestDB_WriteBatchFunction · 0.68
TestDB_WriteBatchRestartFunction · 0.68
TestDB_WriteBatch1Function · 0.68
TestDB_NewIteratorFunction · 0.68
TestPutAndGetFunction · 0.68
TestNewFlyDBFunction · 0.68
TestDB_PutFunction · 0.68
TestDB_ConcurrentPutFunction · 0.68