xtern commented on a change in pull request #7941: URL: https://github.com/apache/ignite/pull/7941#discussion_r503358192
########## File path: modules/core/src/main/java/org/apache/ignite/internal/managers/encryption/CacheGroupEncryptionKeys.java ########## @@ -0,0 +1,376 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ignite.internal.managers.encryption; + +import java.io.Serializable; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.ListIterator; +import java.util.Map; +import java.util.Set; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.ConcurrentLinkedQueue; +import java.util.concurrent.CopyOnWriteArrayList; +import org.apache.ignite.internal.util.typedef.F; +import org.apache.ignite.internal.util.typedef.internal.U; +import org.apache.ignite.spi.encryption.EncryptionSpi; +import org.jetbrains.annotations.Nullable; + +/** + * Serves for managing encryption keys and related datastructure located in the heap. + */ +class CacheGroupEncryptionKeys { + /** Group encryption keys. */ + private final Map<Integer, List<GroupKey>> grpKeys = new ConcurrentHashMap<>(); + + /** + * WAL segments encrypted with previous encryption keys prevent keys from being deleted + * until the associated segment is deleted. + */ + private final Collection<TrackedWalSegment> trackedWalSegments = new ConcurrentLinkedQueue<>(); Review comment: It is possible that the old key will not be deleted until the next key change. For example, we start with encryption key with ID = 0. added new WAL segment 0 (encrypted with key ID = 0) .. added new WAL segment 10 (encrypted with key ID = 0) change encryption key ID = 1 added new WAL segment 11 (encrypted with key ID = 1) .. added new WAL segment 15 (encrypted with key ID = 1) change encryption key ID = 2 added new WAL segment 16 (encrypted with key ID = 2) ... and so on. So, in order to read segment 3 of WAL (for example, for delta rebalancing), we need to keep the key with ID = 0 until the segment 10 is removed from the disk. ---------------------------------------------------------------- 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. For queries about this service, please contact Infrastructure at: [email protected]
