| 864 | |
| 865 | template <bool ReadOnly> |
| 866 | rocksdb::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 | |
| 917 | template rocksdb::Status Bitmap::bitfield<false>(engine::Context &ctx, const Slice &, |
| 918 | const std::vector<BitfieldOperation> &, |
nothing calls this directly
no test coverage detected