@@ -87,32 +87,24 @@ float* OnDiskEmbeddings::getEmbedding(transaction::Transaction* transaction,
87
87
return reinterpret_cast <float *>(dataVector->getData ()) + value.offset ;
88
88
}
89
89
90
- void InMemHNSWGraph::finalize (MemoryManager& mm,
90
+ // NOLINTNEXTLINE(readability-make-member-function-const): Semantically non-const function.
91
+ void InMemHNSWGraph::finalize (MemoryManager& mm, common::node_group_idx_t nodeGroupIdx,
91
92
const processor::PartitionerSharedState& partitionerSharedState) {
92
93
const auto & partitionBuffers = partitionerSharedState.partitioningBuffers [0 ]->partitions ;
93
- const auto numNodeGroups = (numNodes + common::StorageConfig::NODE_GROUP_SIZE - 1 ) /
94
- common::StorageConfig::NODE_GROUP_SIZE;
95
- KU_ASSERT (numNodeGroups == partitionerSharedState.numPartitions [0 ]);
96
- numRelsPerNodeGroup.resize (numNodeGroups);
97
- for (auto nodeGroupIdx = 0u ; nodeGroupIdx < numNodeGroups; nodeGroupIdx++) {
98
- auto numRels = 0u ;
99
- const auto startNodeOffset = StorageUtils::getStartOffsetOfNodeGroup (nodeGroupIdx);
100
- const auto numNodesInGroup =
101
- std::min (common::StorageConfig::NODE_GROUP_SIZE, numNodes - startNodeOffset);
102
- for (auto i = 0u ; i < numNodesInGroup; i++) {
103
- numRels += getCSRLength (startNodeOffset + i);
104
- }
105
- numRelsPerNodeGroup[nodeGroupIdx] = numRels;
106
- }
107
- for (auto nodeGroupIdx = 0u ; nodeGroupIdx < numNodeGroups; nodeGroupIdx++) {
108
- finalizeNodeGroup (mm, nodeGroupIdx, partitionerSharedState.srcNodeTable ->getTableID (),
109
- partitionerSharedState.dstNodeTable ->getTableID (),
110
- partitionerSharedState.relTable ->getTableID (), *partitionBuffers[nodeGroupIdx]);
94
+ auto numRels = 0u ;
95
+ const auto startNodeOffset = StorageUtils::getStartOffsetOfNodeGroup (nodeGroupIdx);
96
+ const auto numNodesInGroup =
97
+ std::min (common::StorageConfig::NODE_GROUP_SIZE, numNodes - startNodeOffset);
98
+ for (auto i = 0u ; i < numNodesInGroup; i++) {
99
+ numRels += getCSRLength (startNodeOffset + i);
111
100
}
101
+ finalizeNodeGroup (mm, nodeGroupIdx, numRels, partitionerSharedState.srcNodeTable ->getTableID (),
102
+ partitionerSharedState.dstNodeTable ->getTableID (),
103
+ partitionerSharedState.relTable ->getTableID (), *partitionBuffers[nodeGroupIdx]);
112
104
}
113
105
114
106
void InMemHNSWGraph::finalizeNodeGroup (MemoryManager& mm, common::node_group_idx_t nodeGroupIdx,
115
- common::table_id_t srcNodeTableID, common::table_id_t dstNodeTableID,
107
+ uint64_t numRels, common::table_id_t srcNodeTableID, common::table_id_t dstNodeTableID,
116
108
common::table_id_t relTableID, InMemChunkedNodeGroupCollection& partition) const {
117
109
const auto startNodeOffset = StorageUtils::getStartOffsetOfNodeGroup (nodeGroupIdx);
118
110
const auto numNodesInGroup =
@@ -122,10 +114,8 @@ void InMemHNSWGraph::finalizeNodeGroup(MemoryManager& mm, common::node_group_idx
122
114
columnTypes.push_back (common::LogicalType::INTERNAL_ID ());
123
115
columnTypes.push_back (common::LogicalType::INTERNAL_ID ());
124
116
columnTypes.push_back (common::LogicalType::INTERNAL_ID ());
125
- auto numRelsInGroup = numRelsPerNodeGroup[nodeGroupIdx];
126
- auto chunkedNodeGroup =
127
- std::make_unique<ChunkedNodeGroup>(mm, columnTypes, false /* enableCompression */ ,
128
- numRelsInGroup, 0 /* startRowIdx */ , ResidencyState::IN_MEMORY);
117
+ auto chunkedNodeGroup = std::make_unique<ChunkedNodeGroup>(mm, columnTypes,
118
+ false /* enableCompression */ , numRels, 0 /* startRowIdx */ , ResidencyState::IN_MEMORY);
129
119
130
120
auto currNumRels = 0u ;
131
121
auto & boundColumnChunk = chunkedNodeGroup->getColumnChunk (0 ).getData ();
@@ -158,23 +148,22 @@ void InMemHNSWGraph::finalizeNodeGroup(MemoryManager& mm, common::node_group_idx
158
148
partition.merge (std::move (chunkedNodeGroup));
159
149
}
160
150
161
- common::offset_vec_t InMemHNSWGraph::getNeighbors (transaction::Transaction* transaction,
162
- common::offset_t nodeOffset) const {
151
+ common::offset_vec_t InMemHNSWGraph::getNeighbors (common::offset_t nodeOffset) const {
163
152
const auto numNbrs = getCSRLength (nodeOffset);
164
- return getNeighbors (transaction, nodeOffset, numNbrs);
153
+ return getNeighbors (nodeOffset, numNbrs);
165
154
}
166
155
167
- common::offset_vec_t InMemHNSWGraph::getNeighbors (transaction::Transaction* ,
168
- common::offset_t nodeOffset, common:: length_t numNbrs) const {
156
+ common::offset_vec_t InMemHNSWGraph::getNeighbors (common:: offset_t nodeOffset ,
157
+ common::length_t numNbrs) const {
169
158
common::offset_vec_t neighbors;
170
159
neighbors.reserve (numNbrs);
171
160
for (common::offset_t i = 0 ; i < numNbrs; i++) {
172
161
auto nbr = getDstNode (nodeOffset * maxDegree + i);
173
162
// Note: we might have INVALID_OFFSET at the end of the array of neighbor nodes. This is due
174
- // to that when we append a new neighbor node to node x, we don't exclusively lock the x,
175
- // instead, we increment the csrLength first, then set the dstNode. This design eases lock
176
- // contentions. However, if this function (`getNeighbors`) is called before the dstNode is
177
- // set, we will get INVALID_OFFSET. As csrLength is always synchorized, this design
163
+ // to that when we append a new neighbor node to node x, we don't exclusively lock the
164
+ // x, instead, we increment the csrLength first, then set the dstNode. This design eases
165
+ // lock contentions. However, if this function (`getNeighbors`) is called before the dstNode
166
+ // is set, we will get INVALID_OFFSET. As csrLength is always synchorized, this design
178
167
// shouldn't have correctness issue.
179
168
if (nbr == common::INVALID_OFFSET) {
180
169
continue ;
0 commit comments