MCPcopy Create free account
hub / github.com/apache/kvrocks / runBitfieldOperationsWithCache

Method runBitfieldOperationsWithCache

src/types/redis_bitmap.cc:866–915  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

864
865template <bool ReadOnly>
866rocksdb::Status Bitmap::runBitfieldOperationsWithCache(engine::Context &ctx, SegmentCacheStore &cache,
867 const std::vector<BitfieldOperation> &ops,
868 std::vector<std::optional<BitfieldValue>> *rets) {
869 ArrayBitfieldBitmap bitfield;
870 for (BitfieldOperation op : ops) {
871 // found all bytes that contents the bitfield.
872 uint32_t first_byte = op.offset / 8;
873 uint32_t last_bytes = (op.offset + op.encoding.Bits() - 1) / 8 + 1;
874 uint32_t bytes = last_bytes - first_byte;
875
876 auto segment_status = CopySegmentsBytesToBitfield(ctx, cache, first_byte, bytes, &bitfield);
877 if (!segment_status.ok()) {
878 return segment_status;
879 }
880
881 // Convert the bitfield from a buffer to an integer.
882 uint64_t unsigned_old_value = 0;
883 auto s = GetBitfieldInteger(bitfield, op.offset, op.encoding, &unsigned_old_value);
884 if (!s.ok()) {
885 return s;
886 }
887
888 if constexpr (ReadOnly) {
889 rets->emplace_back() = {op.encoding, unsigned_old_value};
890 continue;
891 }
892
893 auto &ret = rets->emplace_back();
894 uint64_t unsigned_new_value = 0;
895 // BitfieldOp failed only when the length or bits illegal.
896 // BitfieldOperation already check above case in construction function.
897 if (BitfieldOp(op, unsigned_old_value, &unsigned_new_value).GetValue()) {
898 if (op.type != BitfieldOperation::Type::kGet) {
899 Status _ = bitfield.SetBitfield(op.offset, op.encoding.Bits(), unsigned_new_value);
900 s = CopyBitfieldBytesToSegments(ctx, cache, bitfield, first_byte, bytes);
901 if (!s.ok()) {
902 return s;
903 }
904 }
905
906 if (op.type == BitfieldOperation::Type::kSet) {
907 unsigned_new_value = unsigned_old_value;
908 }
909
910 ret = {op.encoding, unsigned_new_value};
911 }
912 }
913
914 return rocksdb::Status::OK();
915}
916
917template rocksdb::Status Bitmap::bitfield<false>(engine::Context &ctx, const Slice &,
918 const std::vector<BitfieldOperation> &,

Callers

nothing calls this directly

Calls 7

GetBitfieldIntegerFunction · 0.85
BitfieldOpFunction · 0.85
BitsMethod · 0.80
GetValueMethod · 0.80
SetBitfieldMethod · 0.80

Tested by

no test coverage detected