Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
GBPTree checkpoint/close can write header data
Which is stored in the selected state page, after the other state information. Checkpoint/close methods come in two variants, one with header writer and one w/o. The one with header writer will replace the header data with new data, whereas the variants w/o will keep/carry over the previous header data to the new state page. When opening a GBPTree the (newly introduced) supplied header reader can access the header data.
- Loading branch information
Showing
9 changed files
with
279 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 79 additions & 0 deletions
79
community/index/src/main/java/org/neo4j/index/internal/gbptree/Header.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
/* | ||
* Copyright (c) 2002-2017 "Neo Technology," | ||
* Network Engine for Objects in Lund AB [http://neotechnology.com] | ||
* | ||
* This file is part of Neo4j. | ||
* | ||
* Neo4j is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
package org.neo4j.index.internal.gbptree; | ||
|
||
import java.util.function.Consumer; | ||
|
||
import org.neo4j.io.pagecache.PageCache; | ||
import org.neo4j.io.pagecache.PageCursor; | ||
|
||
/** | ||
* Defines interfaces and common implementations of header reader/writer for {@link GBPTree}. | ||
*/ | ||
public class Header | ||
{ | ||
/** | ||
* Writes a header into a {@link GBPTree} state page during | ||
* {@link GBPTree#checkpoint(org.neo4j.io.pagecache.IOLimiter)}. | ||
*/ | ||
public interface Writer | ||
{ | ||
/** | ||
* Writes header data into {@code to} with previous valid header data found in {@code from} of {@code length} | ||
* bytes in size. | ||
* | ||
* @param from {@link PageCursor} positioned at the header data written in the previous check point. | ||
* @param length size in bytes of the previous header data. | ||
* @param to {@link PageCursor} to write new header into. | ||
*/ | ||
void write( PageCursor from, int length, PageCursor to ); | ||
} | ||
|
||
final Consumer<PageCursor> CARRY_OVER = cursor -> {}; | ||
|
||
static final Writer CARRY_OVER_PREVIOUS_HEADER = (from,length,to) -> | ||
{ | ||
from.copyTo( from.getOffset(), to, to.getOffset(), length ); | ||
}; | ||
|
||
static Writer replace( Consumer<PageCursor> writer ) | ||
{ | ||
// Discard the previous state, just write the new | ||
return (from,length,to) -> writer.accept( to ); | ||
} | ||
|
||
/** | ||
* Reads a header from a {@link GBPTree} state page during opening it. | ||
*/ | ||
public interface Reader | ||
{ | ||
/** | ||
* Called when it's time to read header data from the most up to date and valid state page. | ||
* Due to the nature of the underlying {@link PageCache} this method may be called several times, | ||
* some times with invalid data in the {@link PageCursor}. Because of this there mustn't be any | ||
* exceptions thrown or decisions made based on the read data until the GBPTree constructor has been | ||
* completely executed. | ||
* | ||
* @param from {@link PageCursor} positioned at beginning of the header data to read. | ||
* @param length number of bytes available to read in the header data. | ||
*/ | ||
void read( PageCursor from, int length ); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.