Skip to content

Commit 0971cca

Browse files
iamirzhanmeta-codesync[bot]
authored andcommitted
Back out D88004735-D88260777
Summary: There are multiple issues with that stack: * glean CI is broken (and we don't now how to fix it) 3867100#commitcomment-172635196 * It degraded the time of fillOwnership processing * We really need to test `configerator` db first, because we use chronos write server there and the complete step already takes 37 GB. (see the spike on memory usage https://www.internalfb.com/chronos/job_instance/gp/81064803470734278/info). And having u64 sets will only increase it. * I face a crash trying to connect to the db which was produced with this change: `test.1/1: couldn't open: corrupt database - invalid FIRST_UNIT_ID` * There are also couple of comments from Simon Marlow about not using justknob in `database` target and using a db version for controlling the format. So, given all that we have to revert it before it publishes on Monday. After that I think we don't need to move to U64 format at all, just change TrieArray implementation with proper profiling. Reviewed By: jjuliamolin, phlalx Differential Revision: D89051067 fbshipit-source-id: 0c6858ab1ffd42b8d2d6d33a5d2e795d3b40bf41
1 parent 54dc58f commit 0971cca

18 files changed

Lines changed: 160 additions & 1492 deletions

File tree

glean/db/Glean/Database/Ownership.hs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import Data.ByteString (ByteString)
1616
import Data.Coerce
1717
import Data.Maybe
1818
import qualified Data.Vector.Storable as Vector
19+
import Data.Word
1920

2021
import Util.STM
2122

@@ -55,7 +56,7 @@ factOwnership env repo fid = do
5556
Nothing -> getUnit unitId rest
5657

5758
getUset usetId [] = throwIO $ ErrorCall $
58-
"unknown UsetId: " <> show usetId
59+
"unknown UsetId: " <> show (coerce usetId :: Word32)
5960
getUset usetId (own : owns) = do
6061
maybeExpr <- getOwnershipSet own usetId
6162
case maybeExpr of

glean/hs/Glean/RTS/Foreign/Ownership.hsc

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -79,12 +79,12 @@ instance Static UnitIterator where
7979
destroyStatic = glean_ownership_unit_iterator_free
8080

8181
-- | Id of a unit
82-
newtype UnitId = UnitId Word64
82+
newtype UnitId = UnitId Word32
8383
deriving (Storable, Show)
8484

8585
-- | Id of an ownership set
86-
newtype UsetId = UsetId Word64
87-
deriving (Storable, Show)
86+
newtype UsetId = UsetId Word32
87+
deriving (Storable)
8888

8989
firstUsetId :: UsetId
9090
firstUsetId = UsetId 0
@@ -288,7 +288,7 @@ getOwnershipSet ownership usetid =
288288
let op | cop == (#const facebook::glean::rts::Or) = Or
289289
| cop == (#const facebook::glean::rts::And) = And
290290
| otherwise = error "unknown SetOp"
291-
return $ Just (op, unsafeCoerceVector (vec :: VS.Vector Word64))
291+
return $ Just (op, unsafeCoerceVector (vec :: VS.Vector Word32))
292292
)
293293

294294
data OwnershipStats = OwnershipStats
@@ -420,14 +420,14 @@ foreign import ccall safe glean_ownership_compute
420420
foreign import ccall unsafe glean_get_fact_owner
421421
:: Ptr Lookup
422422
-> Word64
423-
-> Ptr Word64
423+
-> Ptr Word32
424424
-> IO CString
425425

426426
foreign import ccall unsafe glean_get_ownership_set
427427
:: Ptr Ownership
428428
-> UsetId
429429
-> Ptr CInt
430-
-> Ptr (Ptr (HsArray Word64))
430+
-> Ptr (Ptr (HsArray Word32))
431431
-> IO CString
432432

433433
foreign import ccall safe glean_derived_ownership_compute
@@ -445,7 +445,7 @@ foreign import ccall unsafe "&glean_computed_ownership_free"
445445

446446
foreign import ccall safe glean_slice_compute
447447
:: Ptr Ownership
448-
-> Ptr Word64
448+
-> Ptr Word32
449449
-> CSize
450450
-> CInt
451451
-> Ptr (Ptr Slice)

glean/rocksdb/database-impl.cpp

Lines changed: 1 addition & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,6 @@
1111

1212
#include "glean/rts/timer.h"
1313

14-
#ifndef OSS
15-
#include "justknobs/JustKnobProxy.h"
16-
#endif
17-
1814
namespace facebook {
1915
namespace glean {
2016
namespace rocks {
@@ -29,49 +25,18 @@ const char* admin_names[] = {
2925
"FIRST_UNIT_ID",
3026
"NEXT_UNIT_ID",
3127
"ORPHAN_FACTS",
32-
"OWNERSHIP_FORMAT_VERSION",
3328
};
3429

3530
namespace {
3631

37-
// Read an admin value with backward compatibility for 32-bit -> 64-bit
38-
// migration. If the stored value is 4 bytes (32-bit) and we expect 8 bytes
39-
// (64-bit), read the 32-bit value and widen it.
40-
template <typename T>
41-
folly::Optional<T> readAdminValueCompat(ContainerImpl& container_, AdminId id) {
42-
rocksdb::PinnableSlice val;
43-
auto s = container_.db->Get(
44-
rocksdb::ReadOptions(),
45-
container_.family(Family::admin),
46-
toSlice(id),
47-
&val);
48-
if (s.IsNotFound()) {
49-
return folly::none;
50-
}
51-
check(s);
52-
53-
// Handle backward compatibility: if stored as 32-bit but expected as 64-bit
54-
if constexpr (sizeof(T) == 8) {
55-
if (val.size() == 4) {
56-
// Old 32-bit value, widen to 64-bit
57-
binary::Input inp(byteRange(val));
58-
return static_cast<T>(inp.fixed<uint32_t>());
59-
}
60-
}
61-
62-
// Normal case: size matches expected
63-
binary::Input inp(byteRange(val));
64-
return inp.fixed<T>();
65-
}
66-
6732
template <typename T, typename F>
6833
T initAdminValue(
6934
ContainerImpl& container_,
7035
AdminId id,
7136
T def,
7237
bool write,
7338
F&& notFound) {
74-
auto current = readAdminValueCompat<T>(container_, id);
39+
auto current = readAdminValue<T>(container_, id);
7540
if (current.hasValue()) {
7641
return *current;
7742
} else {
@@ -150,44 +115,6 @@ DatabaseImpl::DatabaseImpl(
150115
rts::error("unexpected database version {}", db_version);
151116
}
152117

153-
// Initialize ownership format version
154-
// For new DBs: Check JustKnob to decide whether to use 64-bit or 32-bit
155-
// format. For existing DBs: if no version marker exists, assume 32-bit format
156-
// Both formats are always readable regardless of gatekeeper value
157-
if (container_.mode == Mode::Create) {
158-
// New DB: check JustKnob to determine format
159-
#ifndef OSS
160-
static facebook::jk::BooleanKnob use64BitOwnership(
161-
"glean/ownership:64_bit_ids");
162-
uint32_t format_to_use = use64BitOwnership()
163-
? OWNERSHIP_FORMAT_VERSION_64BIT
164-
: OWNERSHIP_FORMAT_VERSION_32BIT;
165-
#else
166-
// OSS builds always use 32-bit format for now
167-
uint32_t format_to_use = OWNERSHIP_FORMAT_VERSION_32BIT;
168-
#endif
169-
ownership_format_version = static_cast<uint32_t>(initAdminValue(
170-
container_,
171-
AdminId::OWNERSHIP_FORMAT_VERSION,
172-
static_cast<uint64_t>(format_to_use),
173-
true, // write
174-
[] {}));
175-
} else {
176-
// Existing DB: read format version, default to 32-bit if not present
177-
ownership_format_version = static_cast<uint32_t>(initAdminValue(
178-
container_,
179-
AdminId::OWNERSHIP_FORMAT_VERSION,
180-
static_cast<uint64_t>(OWNERSHIP_FORMAT_VERSION_32BIT),
181-
false, // don't write
182-
[] {}));
183-
}
184-
185-
VLOG(1) << folly::sformat(
186-
"ownership_format_version: {} ({})",
187-
ownership_format_version,
188-
ownership_format_version == OWNERSHIP_FORMAT_VERSION_32BIT ? "32-bit"
189-
: "64-bit");
190-
191118
stats_.set(loadStats());
192119

193120
if (container_.mode != Mode::ReadOnly) {

glean/rocksdb/database-impl.h

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,8 @@ enum class AdminId : uint32_t {
2929
FIRST_UNIT_ID,
3030
NEXT_UNIT_ID,
3131
ORPHAN_FACTS,
32-
OWNERSHIP_FORMAT_VERSION,
3332
};
3433

35-
// Ownership format versions for backward compatibility:
36-
// - Version 1 (32-bit/absent): 32-bit UnitId and UsetId
37-
// - Version 2: 64-bit UnitId and UsetId
38-
constexpr uint32_t OWNERSHIP_FORMAT_VERSION_32BIT = 1;
39-
constexpr uint32_t OWNERSHIP_FORMAT_VERSION_64BIT = 2;
40-
constexpr uint32_t OWNERSHIP_FORMAT_VERSION_CURRENT =
41-
OWNERSHIP_FORMAT_VERSION_64BIT;
42-
4334
struct DatabaseImpl final : Database {
4435
int64_t db_version;
4536
ContainerImpl container_;
@@ -51,11 +42,6 @@ struct DatabaseImpl final : Database {
5142
std::vector<size_t> ownership_unit_counters;
5243
folly::F14FastMap<uint64_t, size_t> ownership_derived_counters;
5344

54-
// Ownership format version for backward compatibility
55-
// OWNERSHIP_FORMAT_VERSION_32BIT (1): 32-bit UnitId/UsetId (or absent =
56-
// 32-bit) OWNERSHIP_FORMAT_VERSION_64BIT (2): 64-bit UnitId/UsetId
57-
uint32_t ownership_format_version;
58-
5945
// Cached ownership sets, only used when writing.
6046
// Note: must only be accessed under the write lock
6147
std::unique_ptr<rts::Usets> usets_;
@@ -124,8 +110,8 @@ struct DatabaseImpl final : Database {
124110

125111
/// Ownership
126112

127-
folly::Optional<rts::UnitId> getUnitId(folly::ByteRange unit) override;
128-
folly::Optional<std::string> getUnit(rts::UnitId unit_id) override;
113+
folly::Optional<uint32_t> getUnitId(folly::ByteRange unit) override;
114+
folly::Optional<std::string> getUnit(uint32_t unit_id) override;
129115

130116
void addOwnership(const std::vector<OwnershipSet>& ownership) override;
131117

@@ -191,7 +177,7 @@ struct DatabaseImpl final : Database {
191177

192178
struct FactOwnerCache {
193179
static void prepare(ContainerImpl& container);
194-
void enable(ContainerImpl& container, uint32_t ownership_format_version);
180+
void enable(ContainerImpl& container);
195181

196182
// Lookup in the cache. Returns none if the cache is not enabled
197183
std::optional<rts::UsetId> getOwner(ContainerImpl& container, Id id);
@@ -204,18 +190,14 @@ struct DatabaseImpl final : Database {
204190
static rts::UsetId lookup(const Page& page, Id id);
205191
static std::unique_ptr<Page> readPage(
206192
ContainerImpl& container,
207-
uint64_t prefix,
208-
uint32_t ownership_format_version);
193+
uint64_t prefix);
209194

210195
struct Cache {
211196
std::vector<rts::UsetId> index;
212197
std::vector<std::unique_ptr<Page>> pages;
213198

214199
// tracks the memory usage of the cache
215200
size_t size_;
216-
217-
// ownership format version for legacy compatibility
218-
uint32_t ownership_format_version_;
219201
};
220202

221203
// nullptr means the cache is disabled (while the DB is writable)

0 commit comments

Comments
 (0)