xtern commented on a change in pull request #7941:
URL: https://github.com/apache/ignite/pull/7941#discussion_r496516367
##########
File path:
modules/core/src/test/java/org/apache/ignite/internal/encryption/AbstractEncryptionTest.java
##########
@@ -271,4 +313,185 @@ protected boolean checkMasterKeyName(String name) {
return true;
}
+
+ /**
+ * Load data into cache "{@link #cacheName()}" using node "{@link
#GRID_0}".
+ *
+ * @param cnt Count of entries.
+ */
+ protected void loadData(int cnt) {
+ loadData(cacheName(), cnt);
+ }
+
+ /**
+ * Load data into cache using node "{@link #GRID_0}".
+ *
+ * @param cnt Count of entries.
+ * @param cacheName Cache name.
+ */
+ protected void loadData(String cacheName, int cnt) {
+ info("Loading " + cnt + " entries into " + cacheName);
+
+ int start = grid(GRID_0).cache(cacheName).size();
+
+ try (IgniteDataStreamer<Long, Object> streamer =
grid(GRID_0).dataStreamer(cacheName)) {
+ for (long i = start; i < (cnt + start); i++)
+ streamer.addData(i, generateValue(i));
+ }
+
+ info("Load data finished");
+ }
+
+ /**
+ * Ensures that all pages of page store have expected encryption key
identifier.
+ *
+ * @param grpId Cache group ID.
+ * @param keyId Encryption key ID.
+ * @param timeout Timeout to wait for encryption to complete.
+ * @throws Exception If failed.
+ */
+ protected void checkGroupKey(int grpId, int keyId, long timeout) throws
Exception {
+ awaitEncryption(G.allGrids(), grpId, timeout);
+
+ for (Ignite g : G.allGrids()) {
+ info("Validating encryption key [node=" +
g.cluster().localNode().id() + ", grp=" + grpId + "]");
+
+ IgniteEx grid = (IgniteEx)g;
+
+ if (grid.context().clientNode())
+ continue;
+
+ GridEncryptionManager encryption = grid.context().encryption();
+
+ assertEquals(grid.localNode().id().toString(), (byte)keyId,
encryption.groupKey(grpId).id());
+
+ IgniteInternalFuture<Void> fut =
encryption.reencryptionFuture(grpId);
+
+ // The future will be completed after the checkpoint,
forcecheckpoint does nothing
+ // if the checkpoint has already been scheduled.
+ GridTestUtils.waitForCondition(() -> {
+ if (fut.isDone())
+ return true;
+
+ try {
+ forceCheckpoint(g);
+ }
+ catch (IgniteCheckedException e) {
+ throw new RuntimeException(e);
+ }
+
+ return fut.isDone();
+ }, timeout);
+
+ assertTrue(fut.isDone());
+
+ CacheGroupContext grp = grid.context().cache().cacheGroup(grpId);
+
+ List<Integer> parts = IntStream.range(0,
grp.shared().affinity().affinity(grpId).partitions())
+ .boxed().collect(Collectors.toList());
+
+ parts.add(INDEX_PARTITION);
+
+ int realPageSize =
grp.dataRegion().pageMemory().realPageSize(grpId);
+ int encryptionBlockSize =
grp.shared().kernalContext().config().getEncryptionSpi().blockSize();
+
+ for (int p : parts) {
+ FilePageStore pageStore =
+
(FilePageStore)((FilePageStoreManager)grp.shared().pageStore()).getStore(grpId,
p);
+
+ if (!pageStore.exists())
+ continue;
+
+ long state =
grid.context().encryption().getEncryptionState(grpId, p);
+
+ String msg = String.format("p=%d, off=%d, total=%d",
+ p, ReencryptStateUtils.pageIndex(state),
ReencryptStateUtils.pageCount(state));
+
+ assertEquals(msg, 0, ReencryptStateUtils.pageCount(state));
+ assertEquals(msg, 0, ReencryptStateUtils.pageIndex(state));
+
+ long startPageId = PageIdUtils.pageId(p,
PageIdAllocator.FLAG_DATA, 0);
+
+ int pagesCnt = pageStore.pages();
+ int pageSize = pageStore.getPageSize();
+
+ ByteBuffer pageBuf = ByteBuffer.allocate(pageSize);
+
+ Path path = new File(pageStore.getFileAbsolutePath()).toPath();
+
+ try (FileChannel ch = FileChannel.open(path,
StandardOpenOption.READ)) {
+ for (int n = 0; n < pagesCnt; n++) {
+ long pageId = startPageId + n;
+ long pageOff = pageStore.pageOffset(pageId);
+
+ pageBuf.position(0);
+
+ ch.position(pageOff);
+ ch.read(pageBuf);
+
+ pageBuf.position(realPageSize + encryptionBlockSize);
+
+ // If crc present
Review comment:
CRC can be calculated as "0" - it was my mistake.
But in rare cases, when scanning a partition on a disk, we find a blank
page. I added a special check for this case.
----------------------------------------------------------------
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]