Skip to content

Commit

Permalink
NativeIndexHeaderReader handle state page with missing header
Browse files Browse the repository at this point in the history
This state indicate that index was never fully constructed or that it was
in some way abrupted while writing state page. This is not a condition we
can not recover from and index need to be rebuilt.

This should fix flaky text:
HalfAppliedConstraintRecoveryIT.recoverFromAndRecreateHalfCompositeNodeKeyConstraintAppliedBeforeCrash
  • Loading branch information
burqen committed Nov 29, 2018
1 parent 3e5b865 commit baf3e1c
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ class NativeIndexHeaderReader implements Header.Reader
@Override
public void read( ByteBuffer headerData )
{
if ( !headerData.hasRemaining() )
{
state = BYTE_FAILED;
failureMessage = "Initial state byte is missing. Index was never fully constructed and need to be recreated.";
return;
}
state = headerData.get();
if ( state == BYTE_FAILED )
{
Expand All @@ -55,7 +61,7 @@ public void read( ByteBuffer headerData )
* Alternative header readers should react to FAILED indexes by using this, because their specific headers will have been
* overwritten by the FailedHeaderWriter.
*/
public static String readFailureMessage( ByteBuffer headerData )
static String readFailureMessage( ByteBuffer headerData )
{
short messageLength = headerData.getShort();
byte[] failureMessageBytes = new byte[messageLength];
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* Copyright (c) 2002-2018 "Neo4j,"
* Neo4j Sweden AB [http://neo4j.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.kernel.impl.index.schema;

import org.junit.jupiter.api.Test;

import java.nio.ByteBuffer;

import org.neo4j.index.internal.gbptree.GBPTree;

import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertThat;
import static org.neo4j.kernel.impl.index.schema.NativeIndexPopulator.BYTE_FAILED;

class NativeIndexHeaderReaderTest
{
@Test
void mustReportFailedIfNoHeader()
{
ByteBuffer emptyBuffer = ByteBuffer.wrap( new byte[0] );
NativeIndexHeaderReader nativeIndexHeaderReader = new NativeIndexHeaderReader( GBPTree.NO_HEADER_READER );
nativeIndexHeaderReader.read( emptyBuffer );
assertThat( nativeIndexHeaderReader.state, is( BYTE_FAILED ) );
assertThat( nativeIndexHeaderReader.failureMessage,
is( "Initial state byte is missing. Index was never fully constructed and need to be recreated." ) );
}
}

0 comments on commit baf3e1c

Please sign in to comment.