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

Method Open

driver/ipfs-synckv/db.go:57–140  ·  view source on GitHub ↗
(path string, cfg *config.Config)

Source from the content-addressed store, hash-verified

55 return StorageName
56}
57
58func (s Store) Open(path string, cfg *config.Config) (driver.IDB, error) {
59 if err := os.MkdirAll(path, fs.ModePerm); err != nil {
60 return nil, err
61 }
62
63 db := new(DB)
64 db.path = path
65 db.cfg = &cfg.LevelDB
66 db.versions = make(map[string]uint64)
67
68 // Set encryption key if provided
69 if len(DefaultConfig.EncryptionKey) > 0 {
70 db.encryptionKey = []byte(DefaultConfig.EncryptionKey)
71 }
72
73 db.initOpts()
74
75 var err error
76 db.localDB, err = leveldb.OpenFile(db.path, db.opts)
77
78 if err != nil {
79 return nil, err
80 }
81 if DefaultConfig.HotCacheSize <= 0 {
82 DefaultConfig.HotCacheSize = defaultHotCacheSize
83 }
84
85 // here we use default value, later add config support
86 db.cache, err = ristretto.NewCache(&ristretto.Config{
87 MaxCost: DefaultConfig.HotCacheSize * MB,
88 NumCounters: defaultHotCacheNumCounters,
89 BufferItems: 64,
90 Metrics: true,
91 Cost: func(value interface{}) int64 {
92 return int64(len(value.([]byte)))
93 },
94 })
95
96 if err != nil {
97 return nil, err
98 }
99
100 sh := shell.NewShell(DefaultConfig.EndPointConnection)
101 db.remoteShell = sh
102
103 // Initialize ipfs-log components
104 db.ctx = context.Background()
105 db.logger = zap.NewNop()
106
107 // Create IPFS node and API
108 node, api, err := iflog.CreateNode(db.ctx, path)
109 if err != nil {
110 return nil, fmt.Errorf("failed to create IPFS node: %w", err)
111 }
112 db.ipfsNode = node
113
114 // Create ipfs-log event log with proper namespace

Callers 7

TestIteratorFunction · 0.95
TestIteratorPrefixFunction · 0.95
TestDBOpenFunction · 0.95
TestDBPutGetFunction · 0.95
TestDBDeleteFunction · 0.95
TestDBMetricsFunction · 0.95
decryptFunction · 0.45

Calls 3

LoadDiskMethod · 0.80
initOptsMethod · 0.45
AnnounceConnectMethod · 0.45

Tested by 6

TestIteratorFunction · 0.76
TestIteratorPrefixFunction · 0.76
TestDBOpenFunction · 0.76
TestDBPutGetFunction · 0.76
TestDBDeleteFunction · 0.76
TestDBMetricsFunction · 0.76