-
-
Notifications
You must be signed in to change notification settings - Fork 239
/
NodePageTrx.java
687 lines (582 loc) · 25.5 KB
/
NodePageTrx.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
/*
* Copyright (c) 2011, University of Konstanz, Distributed Systems Group All rights reserved.
* <p>
* Redistribution and use in source and binary forms, with or without modification, are permitted
* provided that the following conditions are met: * Redistributions of source code must retain the
* above copyright notice, this list of conditions and the following disclaimer. * Redistributions
* in binary form must reproduce the above copyright notice, this list of conditions and the
* following disclaimer in the documentation and/or other materials provided with the distribution.
* * Neither the name of the University of Konstanz nor the names of its contributors may be used to
* endorse or promote products derived from this software without specific prior written permission.
* <p>
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package io.sirix.access.trx.page;
import io.sirix.access.ResourceConfiguration;
import io.sirix.access.User;
import io.sirix.access.trx.node.CommitCredentials;
import io.sirix.access.trx.node.IndexController;
import io.sirix.access.trx.node.xml.XmlIndexController;
import io.sirix.api.PageReadOnlyTrx;
import io.sirix.api.PageTrx;
import io.sirix.cache.IndexLogKey;
import io.sirix.cache.PageContainer;
import io.sirix.cache.TransactionIntentLog;
import io.sirix.exception.SirixIOException;
import io.sirix.index.IndexType;
import io.sirix.io.Writer;
import io.sirix.node.DeletedNode;
import io.sirix.node.NodeKind;
import io.sirix.node.SirixDeweyID;
import io.sirix.node.delegates.NodeDelegate;
import io.sirix.node.interfaces.DataRecord;
import io.sirix.node.interfaces.Node;
import io.sirix.page.*;
import io.sirix.page.interfaces.KeyValuePage;
import io.sirix.settings.Constants;
import io.sirix.settings.Fixed;
import io.sirix.settings.VersioningType;
import net.openhft.chronicle.bytes.Bytes;
import org.checkerframework.checker.index.qual.NonNegative;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.jetbrains.annotations.NotNull;
import java.io.IOException;
import java.io.OutputStream;
import java.nio.ByteBuffer;
import java.nio.file.Files;
import java.nio.file.Path;
import java.time.Instant;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.function.Function;
import static com.google.common.base.Preconditions.checkArgument;
import static java.nio.file.Files.deleteIfExists;
import static java.nio.file.Files.newOutputStream;
import static java.nio.file.StandardOpenOption.CREATE;
import static java.util.Objects.requireNonNull;
/**
* <p>
* Implements the {@link PageTrx} interface to provide write capabilities to the persistent storage
* layer.
* </p>
*
* @author Marc Kramis, Seabix AG
* @author Sebastian Graf, University of Konstanz
* @author Johannes Lichtenberger
*/
final class NodePageTrx extends AbstractForwardingPageReadOnlyTrx implements PageTrx {
private Bytes<ByteBuffer> bufferBytes = Bytes.elasticByteBuffer(Writer.FLUSH_SIZE);
/**
* Page writer to serialize.
*/
private final Writer storagePageReaderWriter;
/**
* Transaction intent log.
*/
TransactionIntentLog log;
/**
* Last reference to the actual revRoot.
*/
private final RevisionRootPage newRevisionRootPage;
/**
* {@link NodePageReadOnlyTrx} instance.
*/
private final NodePageReadOnlyTrx pageRtx;
/**
* Determines if transaction is closed.
*/
private volatile boolean isClosed;
/**
* {@link XmlIndexController} instance.
*/
private final IndexController<?, ?> indexController;
/**
* The tree modifier.
*/
private final TreeModifier treeModifier;
/**
* The revision to represent.
*/
private final int representRevision;
/**
* {@code true} if this page write trx will be bound to a node trx, {@code false} otherwise
*/
private final boolean isBoundToNodeTrx;
private record IndexLogKeyToPageContainer(IndexType indexType, long recordPageKey, int indexNumber,
int revisionNumber, PageContainer pageContainer) {
}
/**
* The most recent page container.
*/
private IndexLogKeyToPageContainer mostRecentPageContainer;
/**
* The second most recent page container.
*/
private IndexLogKeyToPageContainer secondMostRecentPageContainer;
/**
* The most recent path summary page container.
*/
private IndexLogKeyToPageContainer mostRecentPathSummaryPageContainer;
private final LinkedHashMap<IndexLogKey, PageContainer> pageContainerCache;
/**
* Constructor.
*
* @param writer the page writer
* @param log the transaction intent log
* @param revisionRootPage the revision root page
* @param pageRtx the page reading transaction used as a delegate
* @param indexController the index controller, which is used to update indexes
* @param representRevision the revision to represent
* @param isBoundToNodeTrx {@code true} if this page write trx will be bound to a node trx,
* {@code false} otherwise
*/
NodePageTrx(final TreeModifier treeModifier, final Writer writer, final TransactionIntentLog log,
final RevisionRootPage revisionRootPage, final NodePageReadOnlyTrx pageRtx,
final IndexController<?, ?> indexController, final int representRevision, final boolean isBoundToNodeTrx) {
this.treeModifier = requireNonNull(treeModifier);
storagePageReaderWriter = requireNonNull(writer);
this.log = requireNonNull(log);
newRevisionRootPage = requireNonNull(revisionRootPage);
this.pageRtx = requireNonNull(pageRtx);
this.indexController = requireNonNull(indexController);
checkArgument(representRevision >= 0, "The represented revision must be >= 0.");
this.representRevision = representRevision;
this.isBoundToNodeTrx = isBoundToNodeTrx;
mostRecentPageContainer = new IndexLogKeyToPageContainer(IndexType.DOCUMENT, -1, -1, -1, null);
secondMostRecentPageContainer = mostRecentPageContainer;
mostRecentPathSummaryPageContainer = new IndexLogKeyToPageContainer(IndexType.PATH_SUMMARY, -1, -1, -1, null);
pageContainerCache = new LinkedHashMap<>(2_500) {
@Override
protected boolean removeEldestEntry(Map.Entry<IndexLogKey, PageContainer> eldest) {
return size() > 2_500;
}
};
}
@Override
public Bytes<ByteBuffer> newBufferedBytesInstance() {
bufferBytes = Bytes.elasticByteBuffer(Writer.FLUSH_SIZE);
return bufferBytes;
}
@Override
public int getRevisionToRepresent() {
pageRtx.assertNotClosed();
return representRevision;
}
@Override
public TransactionIntentLog getLog() {
pageRtx.assertNotClosed();
return log;
}
@Override
public int getRevisionNumber() {
pageRtx.assertNotClosed();
return newRevisionRootPage.getRevision();
}
@Override
public DataRecord prepareRecordForModification(final long recordKey, @NonNull final IndexType indexType,
final int index) {
pageRtx.assertNotClosed();
checkArgument(recordKey >= 0, "recordKey must be >= 0!");
requireNonNull(indexType);
final long recordPageKey = pageRtx.pageKey(recordKey, indexType);
final PageContainer cont = prepareRecordPage(recordPageKey, index, indexType);
final var modifiedPage = cont.getModifiedAsUnorderedKeyValuePage();
DataRecord record = pageRtx.getValue(modifiedPage, recordKey);
if (record == null) {
final DataRecord oldRecord = pageRtx.getValue(cont.getCompleteAsUnorderedKeyValuePage(), recordKey);
if (oldRecord == null) {
throw new SirixIOException(
"Cannot retrieve record from cache: (key: " + recordKey + ") (indexType: " + indexType + ") (index: "
+ index + ")");
}
record = oldRecord;
modifiedPage.setRecord(record);
}
return record;
}
@Override
public DataRecord createRecord(@NonNull final DataRecord record, @NonNull final IndexType indexType,
@NonNegative final int index) {
pageRtx.assertNotClosed();
// Allocate record key and increment record count.
// $CASES-OMITTED$
final long createdRecordKey = switch (indexType) {
case DOCUMENT -> newRevisionRootPage.incrementAndGetMaxNodeKeyInDocumentIndex();
case CHANGED_NODES -> newRevisionRootPage.incrementAndGetMaxNodeKeyInChangedNodesIndex();
case RECORD_TO_REVISIONS -> newRevisionRootPage.incrementAndGetMaxNodeKeyInRecordToRevisionsIndex();
case PATH_SUMMARY -> {
final PathSummaryPage pathSummaryPage =
((PathSummaryPage) newRevisionRootPage.getPathSummaryPageReference().getPage());
yield pathSummaryPage.incrementAndGetMaxNodeKey(index);
}
case CAS -> {
final CASPage casPage = ((CASPage) newRevisionRootPage.getCASPageReference().getPage());
yield casPage.incrementAndGetMaxNodeKey(index);
}
case PATH -> {
final PathPage pathPage = ((PathPage) newRevisionRootPage.getPathPageReference().getPage());
yield pathPage.incrementAndGetMaxNodeKey(index);
}
case NAME -> {
final NamePage namePage = ((NamePage) newRevisionRootPage.getNamePageReference().getPage());
yield namePage.incrementAndGetMaxNodeKey(index);
}
default -> throw new IllegalStateException();
};
final long recordPageKey = pageRtx.pageKey(createdRecordKey, indexType);
final PageContainer cont = prepareRecordPage(recordPageKey, index, indexType);
final KeyValuePage<DataRecord> modified = cont.getModifiedAsUnorderedKeyValuePage();
modified.setRecord(record);
return record;
}
@Override
public void removeRecord(final long recordKey, @NonNull final IndexType indexType, final int index) {
pageRtx.assertNotClosed();
final long recordPageKey = pageRtx.pageKey(recordKey, indexType);
final PageContainer cont = prepareRecordPage(recordPageKey, index, indexType);
final DataRecord node = getRecord(recordKey, indexType, index);
if (node == null) {
throw new IllegalStateException("Node not found: " + recordKey);
}
final Node delNode = new DeletedNode(new NodeDelegate(node.getNodeKey(),
-1,
null,
-1,
pageRtx.getRevisionNumber(),
(SirixDeweyID) null));
cont.getModifiedAsUnorderedKeyValuePage().setRecord(delNode);
cont.getCompleteAsUnorderedKeyValuePage().setRecord(delNode);
}
@Override
public <V extends DataRecord> V getRecord(final long recordKey, @NonNull final IndexType indexType,
@NonNegative final int index) {
pageRtx.assertNotClosed();
checkArgument(recordKey >= Fixed.NULL_NODE_KEY.getStandardProperty());
requireNonNull(indexType);
// Calculate page.
final long recordPageKey = pageRtx.pageKey(recordKey, indexType);
final PageContainer pageCont = getPageContainer(recordPageKey, index, indexType);
if (pageCont == null) {
return pageRtx.getRecord(recordKey, indexType, index);
} else {
DataRecord node = pageRtx.getValue(((KeyValueLeafPage) pageCont.getModified()), recordKey);
if (node == null) {
node = pageRtx.getValue(((KeyValueLeafPage) pageCont.getComplete()), recordKey);
}
return (V) pageRtx.checkItemIfDeleted(node);
}
}
@Override
public String getName(final int nameKey, @NonNull final NodeKind nodeKind) {
pageRtx.assertNotClosed();
final NamePage currentNamePage = getNamePage(newRevisionRootPage);
return (currentNamePage == null || currentNamePage.getName(nameKey, nodeKind, pageRtx) == null) ? pageRtx.getName(
nameKey,
nodeKind) : currentNamePage.getName(nameKey, nodeKind, pageRtx);
}
@Override
public int createNameKey(final @Nullable String name, @NonNull final NodeKind nodeKind) {
pageRtx.assertNotClosed();
requireNonNull(nodeKind);
final String string = name == null ? "" : name;
final NamePage namePage = getNamePage(newRevisionRootPage);
return namePage.setName(string, nodeKind, this);
}
@Override
public void commit(final @Nullable PageReference reference) {
if (reference == null) {
return;
}
PageContainer container = log.get(reference);
if (container == null) {
return;
}
final var page = container.getModified();
reference.setPage(page);
// Recursively commit indirectly referenced pages and then write self.
page.commit(this);
storagePageReaderWriter.write(this, reference, bufferBytes);
container.getComplete().clearPage();
page.clearPage();
// Remove page reference.
reference.setPage(null);
}
@Override
public UberPage commit(@Nullable final String commitMessage, @Nullable final Instant commitTimestamp) {
pageRtx.assertNotClosed();
pageRtx.resourceSession.getCommitLock().lock();
try {
final Path commitFile = pageRtx.resourceSession.getCommitFile();
commitFile.toFile().deleteOnExit();
// Issues with windows that it's not created in the first time?
createIfAbsent(commitFile);
final PageReference uberPageReference = new PageReference();
final UberPage uberPage = pageRtx.getUberPage();
uberPageReference.setPage(uberPage);
setUserIfPresent();
setCommitMessageAndTimestampIfRequired(commitMessage, commitTimestamp);
parallelSerializationOfKeyValuePages();
// Recursively write indirectly referenced pages.
uberPage.commit(this);
uberPageReference.setPage(uberPage);
storagePageReaderWriter.writeUberPageReference(this, uberPageReference, bufferBytes);
uberPageReference.setPage(null);
final int revision = uberPage.getRevisionNumber();
serializeIndexDefinitions(revision);
log.clear();
pageContainerCache.clear();
// Delete commit file which denotes that a commit must write the log in the data file.
try {
deleteIfExists(commitFile);
} catch (final IOException e) {
throw new SirixIOException("Commit file couldn't be deleted!");
}
} finally {
pageRtx.resourceSession.getCommitLock().unlock();
}
return readUberPage();
}
private void setCommitMessageAndTimestampIfRequired(@org.jetbrains.annotations.Nullable String commitMessage,
@Nullable Instant commitTimestamp) {
if (commitMessage != null) {
newRevisionRootPage.setCommitMessage(commitMessage);
}
if (commitTimestamp != null) {
newRevisionRootPage.setCommitTimestamp(commitTimestamp);
}
}
private void serializeIndexDefinitions(int revision) {
if (!indexController.getIndexes().getIndexDefs().isEmpty()) {
final Path indexes = pageRtx.getResourceSession()
.getResourceConfig().resourcePath.resolve(ResourceConfiguration.ResourcePaths.INDEXES.getPath())
.resolve(revision + ".xml");
try (final OutputStream out = newOutputStream(indexes, CREATE)) {
indexController.serialize(out);
} catch (final IOException e) {
throw new SirixIOException("Index definitions couldn't be serialized!", e);
}
}
}
private void parallelSerializationOfKeyValuePages() {
log.getList()
.parallelStream()
.map(PageContainer::getModified)
.filter(page -> page instanceof KeyValueLeafPage)
.forEach(page -> {
final Bytes<ByteBuffer> bytes = Bytes.elasticByteBuffer(60_000);
PageKind.KEYVALUELEAFPAGE.serializePage(this, bytes, page, SerializationType.DATA);
});
}
private UberPage readUberPage() {
return (UberPage) storagePageReaderWriter.read(storagePageReaderWriter.readUberPageReference(), pageRtx);
}
private void createIfAbsent(final Path file) {
while (!Files.exists(file)) {
try {
Files.createFile(file);
} catch (final IOException e) {
throw new SirixIOException(e);
}
}
}
private void setUserIfPresent() {
final Optional<User> optionalUser = pageRtx.resourceSession.getUser();
optionalUser.ifPresent(newRevisionRootPage::setUser);
}
@Override
public UberPage rollback() {
pageRtx.assertNotClosed();
log.clear();
return readUberPage();
}
@Override
public synchronized void close() {
if (!isClosed) {
pageRtx.assertNotClosed();
final UberPage lastUberPage = readUberPage();
pageRtx.resourceSession.setLastCommittedUberPage(lastUberPage);
if (!isBoundToNodeTrx) {
pageRtx.resourceSession.closePageWriteTransaction(pageRtx.getTrxId());
}
log.close();
pageRtx.close();
storagePageReaderWriter.close();
isClosed = true;
}
}
@Override
public DeweyIDPage getDeweyIDPage(@NonNull RevisionRootPage revisionRoot) {
// TODO
return null;
}
private PageContainer getPageContainer(final @NonNegative long recordPageKey, final int indexNumber,
final IndexType indexType) {
PageContainer pageContainer =
getMostRecentPageContainer(indexType, recordPageKey, indexNumber, newRevisionRootPage.getRevision());
if (pageContainer != null) {
return pageContainer;
}
return pageContainerCache.computeIfAbsent(new IndexLogKey(indexType,
recordPageKey,
indexNumber,
newRevisionRootPage.getRevision()), (unused) -> {
final PageReference pageReference = pageRtx.getPageReference(newRevisionRootPage, indexType, indexNumber);
final var leafPageReference =
pageRtx.getLeafPageReference(pageReference, recordPageKey, indexNumber, indexType, newRevisionRootPage);
return log.get(leafPageReference);
});
}
@Nullable
private PageContainer getMostRecentPageContainer(IndexType indexType, long recordPageKey,
@NonNegative int indexNumber, @NonNegative int revisionNumber) {
if (indexType == IndexType.PATH_SUMMARY) {
return mostRecentPathSummaryPageContainer.indexType == indexType
&& mostRecentPathSummaryPageContainer.indexNumber == indexNumber
&& mostRecentPathSummaryPageContainer.recordPageKey == recordPageKey
&& mostRecentPathSummaryPageContainer.revisionNumber == revisionNumber
? mostRecentPathSummaryPageContainer.pageContainer
: null;
}
var pageContainer =
mostRecentPageContainer.indexType == indexType && mostRecentPageContainer.recordPageKey == recordPageKey
&& mostRecentPageContainer.indexNumber == indexNumber
&& mostRecentPageContainer.revisionNumber == revisionNumber ? mostRecentPageContainer.pageContainer : null;
if (pageContainer == null) {
pageContainer = secondMostRecentPageContainer.indexType == indexType
&& secondMostRecentPageContainer.recordPageKey == recordPageKey
&& secondMostRecentPageContainer.indexNumber == indexNumber
&& secondMostRecentPageContainer.revisionNumber == revisionNumber
? secondMostRecentPageContainer.pageContainer
: null;
}
return pageContainer;
}
/**
* Prepare record page.
*
* @param recordPageKey the key of the record page
* @param indexNumber the index number if it's a record-page of an index, {@code -1}, else
* @param indexType the index type
* @return {@link PageContainer} instance
* @throws SirixIOException if an I/O error occurs
*/
private PageContainer prepareRecordPage(final @NonNegative long recordPageKey, final int indexNumber,
final IndexType indexType) {
assert indexType != null;
PageContainer mostRecentPageContainer1 =
getMostRecentPageContainer(indexType, recordPageKey, indexNumber, newRevisionRootPage.getRevision());
if (mostRecentPageContainer1 != null) {
return mostRecentPageContainer1;
}
final Function<IndexLogKey, PageContainer> fetchPageContainer = (key) -> {
final PageReference pageReference = pageRtx.getPageReference(newRevisionRootPage, indexType, indexNumber);
// Get the reference to the unordered key/value page storing the records.
final PageReference reference = treeModifier.prepareLeafOfTree(pageRtx,
log,
getUberPage().getPageCountExp(indexType),
pageReference,
recordPageKey,
indexNumber,
indexType,
newRevisionRootPage);
var pageContainer = log.get(reference);
if (pageContainer != null) {
return pageContainer;
}
if (reference.getKey() == Constants.NULL_ID_LONG) {
final KeyValueLeafPage completePage = new KeyValueLeafPage(recordPageKey, indexType, pageRtx);
final KeyValueLeafPage modifyPage = new KeyValueLeafPage(completePage);
pageContainer = PageContainer.getInstance(completePage, modifyPage);
} else {
pageContainer = dereferenceRecordPageForModification(reference);
}
assert pageContainer != null;
// $CASES-OMITTED$
switch (indexType) {
case DOCUMENT, CHANGED_NODES, RECORD_TO_REVISIONS, DEWEYID_TO_RECORDID, PATH_SUMMARY, PATH, CAS, NAME ->
appendLogRecord(reference, pageContainer);
default -> throw new IllegalStateException("Page kind not known!");
}
return pageContainer;
};
var currPageContainer = pageContainerCache.computeIfAbsent(new IndexLogKey(indexType,
recordPageKey,
indexNumber,
newRevisionRootPage.getRevision()),
fetchPageContainer);
if (indexType == IndexType.PATH_SUMMARY) {
mostRecentPathSummaryPageContainer = new IndexLogKeyToPageContainer(indexType,
recordPageKey,
indexNumber,
newRevisionRootPage.getRevision(),
currPageContainer);
} else {
secondMostRecentPageContainer = mostRecentPageContainer;
mostRecentPageContainer = new IndexLogKeyToPageContainer(indexType,
recordPageKey,
indexNumber,
newRevisionRootPage.getRevision(),
currPageContainer);
}
return currPageContainer;
}
/**
* Dereference record page reference.
*
* @param reference reference to leaf, that is the record page
* @return dereferenced page
*/
private PageContainer dereferenceRecordPageForModification(final PageReference reference) {
final List<KeyValuePage<DataRecord>> pageFragments = pageRtx.getPageFragments(reference);
final VersioningType versioningType = pageRtx.resourceSession.getResourceConfig().versioningType;
final int mileStoneRevision = pageRtx.resourceSession.getResourceConfig().maxNumberOfRevisionsToRestore;
return versioningType.combineRecordPagesForModification(pageFragments, mileStoneRevision, pageRtx, reference, log);
}
@Override
public RevisionRootPage getActualRevisionRootPage() {
pageRtx.assertNotClosed();
return newRevisionRootPage;
}
@Override
protected @NotNull PageReadOnlyTrx delegate() {
return pageRtx;
}
@Override
public PageReadOnlyTrx getPageReadOnlyTrx() {
return pageRtx;
}
@Override
public PageTrx appendLogRecord(@NonNull final PageReference reference, @NonNull final PageContainer pageContainer) {
requireNonNull(pageContainer);
log.put(reference, pageContainer);
return this;
}
@Override
public PageContainer getLogRecord(final PageReference reference) {
requireNonNull(reference);
return log.get(reference);
}
@Override
public PageTrx truncateTo(final int revision) {
storagePageReaderWriter.truncateTo(this, revision);
return this;
}
@Override
public long getTrxId() {
return pageRtx.getTrxId();
}
@Override
public CommitCredentials getCommitCredentials() {
return pageRtx.getCommitCredentials();
}
}