MCPcopy Create free account
hub / github.com/nutsdb/nutsdb / RangeScanEntries

Method RangeScanEntries

tx_btree.go:293–338  ·  view source on GitHub ↗

RangeScanEntries query a range at given bucket, start and end slice. It will return keys and/or values based on the includeKeys and includeValues flags.

(bucket string, start, end []byte, includeKeys, includeValues bool)

Source from the content-addressed store, hash-verified

291// RangeScanEntries query a range at given bucket, start and end slice. It will
292// return keys and/or values based on the includeKeys and includeValues flags.
293func (tx *Tx) RangeScanEntries(bucket string, start, end []byte, includeKeys, includeValues bool) (keys, values [][]byte, err error) {
294 if err := tx.checkTxIsClosed(); err != nil {
295 return nil, nil, err
296 }
297 status, b := tx.getBucketAndItsStatus(DataStructureBTree, bucket)
298 if isBucketNotFoundStatus(status) {
299 return nil, nil, ErrNotFoundBucket
300 }
301 bucketId := b.Id
302 pendingKeys, pendingValues := tx.pendingWrites.getDataByRange(start, end, b.Name)
303 if index, ok := tx.db.Index.BTree.exist(bucketId); ok {
304 records := index.Range(start, end)
305
306 needKeysForMerge := includeKeys || len(pendingKeys) > 0
307
308 keys, values, err = tx.getHintIdxDataItemsWrapper(
309 records, ScanNoLimit, bucketId, needKeysForMerge, includeValues,
310 )
311 if err != nil && len(pendingKeys) == 0 && len(pendingValues) == 0 {
312 // If there is no item in pending and persist db,
313 // return error itself.
314 return nil, nil, err
315 }
316 }
317
318 if len(pendingKeys) > 0 || len(pendingValues) > 0 {
319 keys, values = mergeKeyValues(pendingKeys, pendingValues, keys, values)
320 }
321
322 // Check for empty results before setting to nil
323 if includeKeys && len(keys) == 0 {
324 return nil, nil, ErrRangeScan
325 }
326 if includeValues && len(values) == 0 {
327 return nil, nil, ErrRangeScan
328 }
329
330 if !includeKeys {
331 keys = nil
332 }
333 if !includeValues {
334 values = nil
335 }
336
337 return
338}
339
340// RangeScan query a range at given bucket, start and end slice.
341func (tx *Tx) RangeScan(bucket string, start, end []byte) (values [][]byte, err error) {

Callers 3

RangeScanMethod · 0.95

Calls 8

checkTxIsClosedMethod · 0.95
getBucketAndItsStatusMethod · 0.95
isBucketNotFoundStatusFunction · 0.85
mergeKeyValuesFunction · 0.85
getDataByRangeMethod · 0.80
existMethod · 0.80
RangeMethod · 0.65