private void writePage()

in environment/src/main/java/jetbrains/exodus/log/BufferedDataWriter.java [794:870]


    private void writePage(MutablePage page) {
        byte[] bytes = page.bytes;

        final StreamingXXHash64 xxHash64 = page.xxHash64;
        final long pageAddress = page.pageAddress;

        final int writtenCount = page.writtenCount;
        final int committedCount = page.committedCount;

        final int len = writtenCount - committedCount;

        if (len > 0) {
            final int contentLen;
            if (writtenCount < pageSize) {
                contentLen = len;
            } else {
                contentLen = len - HASH_CODE_SIZE;
            }

            byte[] encryptedBytes = null;
            if (cipherProvider == null) {
                if (calculateHashCode) {
                    xxHash64.update(bytes, committedCount, contentLen);

                    if (writtenCount == pageSize) {
                        BindingUtils.writeLong(xxHash64.getValue(), bytes,
                                adjustedPageSize);
                    }
                }
            } else {
                encryptedBytes = EnvKryptKt.cryptBlocksImmutable(cipherProvider, cipherKey,
                        cipherBasicIV, pageAddress, bytes, committedCount, len, LogUtil.LOG_BLOCK_ALIGNMENT);

                if (calculateHashCode) {
                    xxHash64.update(encryptedBytes, 0, contentLen);

                    if (writtenCount == pageSize) {
                        BindingUtils.writeLong(xxHash64.getValue(), encryptedBytes, contentLen);
                    }
                }
            }

            writeBoundarySemaphore.acquireUninterruptibly();
            localWritesSemaphore.acquireUninterruptibly();

            assert writer.position() <= log.getFileLengthBound();
            assert writer.position() % log.getFileLengthBound() ==
                    (currentPage.pageAddress + currentPage.committedCount) % log.getFileLengthBound();

            addPageToWriteCache(pageAddress, 0, bytes);
            logCache.cachePage(log, pageAddress, bytes);

            Pair<Block, CompletableFuture<LongIntPair>> result;
            if (cipherProvider != null) {
                result = writer.asyncWrite(encryptedBytes, 0, len);
            } else {
                result = writer.asyncWrite(bytes, committedCount, len);
            }

            assert writer.position() <= log.getFileLengthBound();
            assert writer.position() % log.getFileLengthBound() ==
                    (currentPage.pageAddress + currentPage.writtenCount) % log.getFileLengthBound();

            var block = result.getFirst();
            var blockAddress = block.getAddress();

            assert blockSetMutable != null;

            if (!blockSetMutable.contains(blockAddress)) {
                blockSetMutable.add(block.getAddress(), block);
                blockSetWasChanged = false;
            }

            page.committedCount = page.writtenCount;
            result.getSecond().whenComplete(writeCompletionHandler);
        }
    }