tkalkirill commented on code in PR #1325:
URL: https://github.com/apache/ignite-3/pull/1325#discussion_r1031214080
##########
modules/page-memory/src/main/java/org/apache/ignite/internal/pagememory/persistence/store/GroupPageStoresMap.java:
##########
@@ -47,52 +50,156 @@ public GroupPageStoresMap(LongOperationAsyncExecutor
longOperationAsyncExecutor)
}
/**
- * Puts the page stores for the group.
+ * Puts the page store for the group partition.
+ *
+ * @param groupId Group ID.
+ * @param partitionId Partition ID.
+ * @param pageStore Page store.
+ * @return Previous page store.
+ */
+ public @Nullable T put(Integer groupId, Integer partitionId, T pageStore) {
+ return longOperationAsyncExecutor.afterAsyncCompletion(() -> {
+ PartitionPageStore<T> previous = groupIdPageStores
+ .computeIfAbsent(groupId, id -> new
GroupPageStores<>(groupId))
+ .partitionIdPageStore
+ .put(partitionId, new
PartitionPageStore<>(partitionId, pageStore));
+
+ return previous == null ? null : previous.pageStore;
+ }
+ );
+ }
+
+ /**
+ * Removes the page store for the group partition.
*
- * @param grpId Group ID.
- * @param pageStores Page stores.
- * @return Previous page stores.
+ * @param groupId Group ID.
+ * @param partitionId Partition ID.
+ * @return Removed page store.
*/
- public @Nullable List<T> put(Integer grpId, List<T> pageStores) {
- return longOperationAsyncExecutor.afterAsyncCompletion(() ->
groupPageStores.put(grpId, pageStores));
+ public @Nullable T remove(Integer groupId, Integer partitionId) {
+ AtomicReference<PartitionPageStore<T>> partitionPageStoreRef = new
AtomicReference<>();
+
+ groupIdPageStores.compute(groupId, (id, groupPageStores) -> {
+ if (groupPageStores == null) {
+ return null;
+ }
+
+
partitionPageStoreRef.set(groupPageStores.partitionIdPageStore.remove(partitionId));
+
+ if (groupPageStores.partitionIdPageStore.isEmpty()) {
+ return null;
+ }
+
+ return groupPageStores;
+ });
+
+ PartitionPageStore<T> partitionPageStore = partitionPageStoreRef.get();
+
+ return partitionPageStore == null ? null :
partitionPageStore.pageStore;
}
/**
* Returns the page stores for the group.
*
- * @param grpId Group ID.
+ * @param groupId Group ID.
*/
- public @Nullable List<T> get(Integer grpId) {
- return groupPageStores.get(grpId);
+ public @Nullable GroupPageStores<T> get(Integer groupId) {
+ return groupIdPageStores.get(groupId);
}
/**
- * Returns {@code true} if a page stores exists for the group.
+ * Returns {@code true} if a page store exists for the group partition.
*
- * @param grpId Group ID.
+ * @param groupId Group ID.
+ * @param partitionId Partition ID.
*/
- public boolean containsPageStores(Integer grpId) {
- return groupPageStores.containsKey(grpId);
+ public boolean contains(Integer groupId, Integer partitionId) {
+ GroupPageStores<T> groupPageStores = groupIdPageStores.get(groupId);
+
+ return groupPageStores != null &&
groupPageStores.partitionIdPageStore.containsKey(partitionId);
}
/**
- * Returns all page stores of all groups.
+ * Returns a view of all page stores of all groups.
*/
- public Collection<List<T>> allPageStores() {
- return groupPageStores.values();
+ public Collection<GroupPageStores<T>> getAll() {
+ return unmodifiableCollection(groupIdPageStores.values());
}
/**
* Clears all page stores of all groups.
*/
public void clear() {
- groupPageStores.clear();
+ groupIdPageStores.clear();
}
/**
* Returns the number of groups for which there are page stores.
*/
public int groupCount() {
- return groupPageStores.size();
+ return groupIdPageStores.size();
+ }
+
+ /**
+ * Group partition page stores.
+ */
+ public static class GroupPageStores<T extends PageStore> {
+ private final int groupId;
+
+ private final ConcurrentMap<Integer, PartitionPageStore<T>>
partitionIdPageStore = new ConcurrentHashMap<>();
+
+ private GroupPageStores(int groupId) {
+ this.groupId = groupId;
+ }
+
+ /**
+ * Returns the group ID.
+ */
+ public int groupId() {
+ return groupId;
+ }
+
+ /**
+ * Returns the partition's page store.
+ */
+ @Nullable
+ public PartitionPageStore<T> get(Integer partitionId) {
+ return partitionIdPageStore.get(partitionId);
+ }
+
+ /**
+ * Returns a view of the group's partition page stores.
+ */
+ public Collection<PartitionPageStore<T>> getAll() {
+ return unmodifiableCollection(partitionIdPageStore.values());
+ }
+ }
+
+ /**
+ * Partition page store.
+ */
+ public static class PartitionPageStore<T extends PageStore> {
+ private final int partitionId;
+
+ private final T pageStore;
Review Comment:
There is no getter, in general we can add it, but it is better in a separate
ticket.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]