MCPcopy Create free account
hub / github.com/IceFireDB/IceFireDB / Open

Method Open

driver/oss/db.go:53–98  ·  view source on GitHub ↗
(path string, cfg *config.Config)

Source from the content-addressed store, hash-verified

51}
52
53func (s Store) Open(path string, cfg *config.Config) (driver.IDB, error) {
54 if err := os.MkdirAll(path, fs.ModePerm); err != nil {
55 return nil, err
56 }
57
58 db := new(DB)
59 db.path = path
60 db.cfg = &cfg.LevelDB
61
62 db.initOpts()
63
64 var err error
65 db.db, err = leveldb.OpenFile(db.path, db.opts)
66
67 if err != nil {
68 return nil, err
69 }
70 if OssDefaultConfig.HotCacheSize <= 0 {
71 OssDefaultConfig.HotCacheSize = defaultHotCacheSize
72 }
73 // here we use default value, later add config support
74 db.cache, err = ristretto.NewCache(&ristretto.Config{
75 MaxCost: OssDefaultConfig.HotCacheSize * MB,
76 NumCounters: defaultHotCacheNumCounters,
77 BufferItems: 64,
78 Metrics: true,
79 Cost: func(value any) int64 {
80 return int64(len(value.([]byte)))
81 },
82 })
83
84 if err != nil {
85 return nil, err
86 }
87
88 db.options = Options{
89 BucketName: "gokv",
90 AWSaccessKeyID: OssDefaultConfig.AccessKey,
91 AWSsecretAccessKey: OssDefaultConfig.Secretkey,
92 Region: endpoints.UsEast1RegionID, //endpoints.UsWest2RegionID,
93 CustomEndpoint: OssDefaultConfig.EndPointConnection,
94 UsePathStyleAddressing: true,
95 Codec: encoding.Gob,
96 }
97 return db, nil
98}
99
100func (s Store) Repair(path string, cfg *config.Config) error {
101 db, err := leveldb.RecoverFile(path, newOptions(&cfg.LevelDB))

Callers 4

getTestConnFunction · 0.45
mainFunction · 0.45
InitSQLiteFunction · 0.45
decryptFunction · 0.45

Calls 1

initOptsMethod · 0.45

Tested by 1

getTestConnFunction · 0.36