MCPcopy Create free account
hub / github.com/ethstorage/es-node / createDataFile

Function createDataFile

cmd/es-node/utils.go:193–228  ·  view source on GitHub ↗
(cfg *storage.StorageConfig, shardIdxList []uint64, datadir string, encodingType int)

Source from the content-addressed store, hash-verified

191}
192
193func createDataFile(cfg *storage.StorageConfig, shardIdxList []uint64, datadir string, encodingType int) ([]string, error) {
194 lg.Info("Creating data files", "shardIdxList", shardIdxList, "dataDir", datadir)
195 if _, err := os.Stat(datadir); os.IsNotExist(err) {
196 if err := os.Mkdir(datadir, 0755); err != nil {
197 lg.Error("Creating data directory", "error", err)
198 return nil, err
199 }
200 }
201 var files []string
202 for _, shardIdx := range shardIdxList {
203 dataFile := filepath.Join(datadir, fmt.Sprintf(fileName, shardIdx))
204 if _, err := os.Stat(dataFile); err == nil {
205 lg.Warn("Creating data file", "error", "file already exists, will not overwrite", "file", dataFile)
206 continue
207 }
208 if cfg.ChunkSize == 0 {
209 return nil, fmt.Errorf("chunk size should not be 0")
210 }
211 if cfg.KvSize%cfg.ChunkSize != 0 {
212 return nil, fmt.Errorf("max kv size %% chunk size should be 0")
213 }
214 chunkPerKv := cfg.KvSize / cfg.ChunkSize
215 startChunkId := shardIdx * cfg.KvEntriesPerShard * chunkPerKv
216 chunkIdxLen := chunkPerKv * cfg.KvEntriesPerShard
217 lg.Info("Creating data file", "chunkIdxStart", startChunkId, "chunkIdxLen", chunkIdxLen, "chunkSize", cfg.ChunkSize, "miner", cfg.Miner, "encodeType", encodingType)
218
219 df, err := es.Create(dataFile, startChunkId, chunkPerKv*cfg.KvEntriesPerShard, 0, cfg.KvSize, uint64(encodingType), cfg.Miner, cfg.ChunkSize)
220 if err != nil {
221 lg.Error("Creating data file", "error", err)
222 return nil, err
223 }
224 lg.Info("Data file created", "shard", shardIdx, "file", dataFile, "kvIdxStart", df.KvIdxStart(), "kvIdxEnd", df.KvIdxEnd(), "miner", df.Miner())
225 files = append(files, dataFile)
226 }
227 return files, nil
228}
229
230func sortBigIntSlice(slice []*big.Int) []int {
231 indices := make([]int, len(slice))

Callers 2

TestCreateDataFileFunction · 0.85
EsNodeInitFunction · 0.85

Calls 4

KvIdxStartMethod · 0.80
KvIdxEndMethod · 0.80
ErrorMethod · 0.45
MinerMethod · 0.45

Tested by 1

TestCreateDataFileFunction · 0.68