Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
jianoaix committed May 7, 2024
1 parent 8ec570b commit 0a33d44
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions node/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ func (s *Store) deleteNBatches(currentTimeUnixSec int64, numBatches int) (int, e
//
// These entries will be stored atomically, i.e. either all or none entries will be stored.
func (s *Store) StoreBatch(ctx context.Context, header *core.BatchHeader, blobs []*core.BlobMessage, blobsProto []*node.Blob) (*[][]byte, error) {

log := s.logger
batchHeaderHash, err := header.GetBatchHeaderHash()
if err != nil {
Expand Down Expand Up @@ -218,6 +219,7 @@ func (s *Store) StoreBatch(ctx context.Context, header *core.BatchHeader, blobs

// Generate key/value pairs for all blob headers and blob chunks .
size := int64(0)
var serializationDuration, encodingDuration time.Duration
for idx, blob := range blobs {
// blob header
blobHeaderKey, err := EncodeBlobHeaderKey(batchHeaderHash, idx)
Expand All @@ -241,6 +243,7 @@ func (s *Store) StoreBatch(ctx context.Context, header *core.BatchHeader, blobs
return nil, err
}

start := time.Now()
bundleRaw := make([][]byte, len(bundle))
for i, chunk := range bundle {
bundleRaw[i], err = chunk.Serialize()
Expand All @@ -249,10 +252,13 @@ func (s *Store) StoreBatch(ctx context.Context, header *core.BatchHeader, blobs
return nil, err
}
}
serializationDuration += time.Since(start)
start = time.Now()
chunkBytes, err := encodeChunks(bundleRaw)
if err != nil {
return nil, err
}
encodingDuration += time.Since(start)
size += int64(len(chunkBytes))

keys = append(keys, key)
Expand All @@ -261,12 +267,14 @@ func (s *Store) StoreBatch(ctx context.Context, header *core.BatchHeader, blobs
}
}

start := time.Now()
// Write all the key/value pairs to the local database atomically.
err = s.db.WriteBatch(keys, values)
if err != nil {
log.Error("Failed to write the batch into local database:", "err", err)
return nil, err
}
log.Debug("StoreBatch succeeded", "chunk serialization duration", serializationDuration, "bytes encoding duration", encodingDuration, "write batch duration", time.Since(start))

return &keys, nil
}
Expand Down

0 comments on commit 0a33d44

Please sign in to comment.