Skip to content

Commit

Permalink
choose record format based on current context.
Browse files Browse the repository at this point in the history
needed for import tool and consistency checker
in enterprise formats, since these tools are in the
community edition.
  • Loading branch information
Max Sumrall committed Feb 25, 2016
1 parent 4754d84 commit f8aed0d
Show file tree
Hide file tree
Showing 24 changed files with 219 additions and 117 deletions.
Expand Up @@ -33,11 +33,11 @@
import org.neo4j.io.pagecache.PageCache;
import org.neo4j.io.pagecache.PageCursor;
import org.neo4j.io.pagecache.PagedFile;
import org.neo4j.kernel.impl.store.id.IdGeneratorFactory;
import org.neo4j.kernel.impl.store.id.IdType;
import org.neo4j.kernel.configuration.Config;
import org.neo4j.kernel.impl.store.id.IdGenerator;
import org.neo4j.kernel.impl.store.id.IdGeneratorFactory;
import org.neo4j.kernel.impl.store.id.IdGeneratorImpl;
import org.neo4j.kernel.impl.store.id.IdType;
import org.neo4j.kernel.impl.store.record.AbstractBaseRecord;
import org.neo4j.kernel.impl.store.record.Record;
import org.neo4j.kernel.impl.store.record.RecordLoad;
Expand Down Expand Up @@ -67,12 +67,12 @@ public abstract class CommonAbstractStore<RECORD extends AbstractBaseRecord>
protected final IdGeneratorFactory idGeneratorFactory;
protected final Log log;
protected PagedFile storeFile;
protected final String storeVersion;
private IdGenerator idGenerator;
private boolean storeOk = true;
private Throwable causeOfStoreNotOk;
private final String typeDescriptor;

private final String storeVersion;

/**
* Opens and validates the store contained in <CODE>fileName</CODE>
Expand Down
Expand Up @@ -28,10 +28,9 @@
import org.neo4j.io.pagecache.PageCache;
import org.neo4j.io.pagecache.PageCursor;
import org.neo4j.io.pagecache.PagedFile;
import org.neo4j.kernel.impl.store.format.lowlimit.LowLimit;
import org.neo4j.kernel.configuration.Config;
import org.neo4j.kernel.impl.store.id.IdGeneratorFactory;
import org.neo4j.kernel.impl.store.id.IdType;
import org.neo4j.kernel.configuration.Config;
import org.neo4j.kernel.impl.store.record.NeoStoreActualRecord;
import org.neo4j.kernel.impl.store.record.NeoStoreRecord;
import org.neo4j.kernel.impl.store.record.Record;
Expand Down Expand Up @@ -152,7 +151,8 @@ protected void initialiseNewStoreFile( PagedFile file ) throws IOException
{
super.initialiseNewStoreFile( file );

StoreId storeId = new StoreId();
long storeVersionAsLong = MetaDataStore.versionStringToLong( storeVersion );
StoreId storeId = new StoreId( storeVersionAsLong );

storeFile = file;
setCreationTime( storeId.getCreationTime() );
Expand All @@ -164,7 +164,7 @@ protected void initialiseNewStoreFile( PagedFile file ) throws IOException
setCurrentLogVersion( 0 );
setLastCommittedAndClosedTransactionId(
BASE_TX_ID, BASE_TX_CHECKSUM, BASE_TX_LOG_VERSION, BASE_TX_LOG_BYTE_OFFSET );
setStoreVersion( MetaDataStore.versionStringToLong( LowLimit.STORE_VERSION ) );
setStoreVersion( storeVersionAsLong );
setGraphNextProp( -1 );
setLatestConstraintIntroducingTx( 0 );

Expand Down Expand Up @@ -298,7 +298,7 @@ static int getPageSize( PageCache pageCache )

public StoreId getStoreId()
{
return new StoreId( getCreationTime(), getRandomNumber(), getUpgradeTime(), upgradeTxIdField );
return new StoreId( getCreationTime(), getRandomNumber(), getStoreVersion(), getUpgradeTime(), upgradeTxIdField );
}

public long getUpgradeTime()
Expand Down
Expand Up @@ -34,7 +34,7 @@ public final class StoreId implements Externalizable
{
public static final long CURRENT_STORE_VERSION = versionStringToLong( LowLimit.STORE_VERSION );

public static final StoreId DEFAULT = new StoreId( -1, -1, -1, -1 );
public static final StoreId DEFAULT = new StoreId( -1, -1, -1, -1, -1 );

private static final Random r = new SecureRandom();

Expand All @@ -44,24 +44,23 @@ public final class StoreId implements Externalizable
private long upgradeTime;
private long upgradeId;

public StoreId()
private StoreId()
{
//For the readExternal method.
}

public StoreId( long storeVersion )
{
// If creationTime == upgradeTime && randomNumber == upgradeId then store has never been upgraded
long currentTimeMillis = System.currentTimeMillis();
long randomLong = r.nextLong();

this.storeVersion = storeVersion;
this.creationTime = currentTimeMillis;
this.randomId = randomLong;
this.storeVersion = CURRENT_STORE_VERSION;
this.upgradeTime = currentTimeMillis;
this.upgradeId = randomLong;
}

public StoreId( long creationTime, long randomId, long upgradeTime, long upgradeId )
{
this( creationTime, randomId, CURRENT_STORE_VERSION, upgradeTime, upgradeId );
}

public StoreId( long creationTime, long randomId, long storeVersion, long upgradeTime, long upgradeId )
{
this.creationTime = creationTime;
Expand Down Expand Up @@ -153,12 +152,12 @@ public int hashCode()
public String toString()
{
return "StoreId{" +
"creationTime=" + creationTime +
", randomId=" + randomId +
", storeVersion=" + storeVersion +
", upgradeTime=" + upgradeTime +
", upgradeId=" + upgradeId +
'}';
"creationTime=" + creationTime +
", randomId=" + randomId +
", storeVersion=" + storeVersion +
", upgradeTime=" + upgradeTime +
", upgradeId=" + upgradeId +
'}';
}

private static boolean equal( long first, long second )
Expand Down
Expand Up @@ -19,9 +19,7 @@
*/
package org.neo4j.kernel.impl.store.format;

import org.neo4j.helpers.Service;
import org.neo4j.kernel.configuration.Config;
import org.neo4j.kernel.impl.factory.GraphDatabaseFacadeFactory;
import org.neo4j.kernel.impl.store.format.lowlimit.LowLimit;

/**
* Selects format to use for databases in this JVM, using a system property. By default uses the safest
Expand All @@ -30,29 +28,13 @@
*/
public class InternalRecordFormatSelector
{
public static RecordFormats select( Config config )
public static RecordFormats select()
{
String key = config.get( GraphDatabaseFacadeFactory.Configuration.record_type );
RecordFormats.Factory potentialCandidate = null;
for ( RecordFormats.Factory candidate : Service.load( RecordFormats.Factory.class ) )
{
String candidateId = candidate.getKeys().iterator().next();
if ( candidateId.equals( key ) )
{
return candidate.newInstance();
}
else if ( potentialCandidate == null || candidateId.equals( "highlimit" ) )
{
potentialCandidate = candidate;
}
}
if ( key.equals( "" ) )
{
return potentialCandidate.newInstance();
}
else
{
throw new IllegalArgumentException( "Invalid configuration for record format." );
}
//todo: uncomment this loop once high-limits store migration is done.
// for ( RecordFormats.Factory candidate : Service.load( RecordFormats.Factory.class ) )
// {
// return candidate.newInstance();
// }
return LowLimit.RECORD_FORMATS;
}
}

This file was deleted.

@@ -0,0 +1,45 @@
/*
* Copyright (c) 2002-2016 "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.kernel.impl.store;

import org.neo4j.kernel.impl.store.format.InternalRecordFormatSelector;
import org.neo4j.kernel.impl.store.format.RecordFormats;

public class StoreIdTestFactory
{
private static long currentStoreVersionAsLong()
{
RecordFormats select = InternalRecordFormatSelector.select();
return MetaDataStore.versionStringToLong( select.storeVersion() );
}

public static StoreId newStoreIdForCurrentVersion()
{
return new StoreId( currentStoreVersionAsLong() );
}

public static StoreId newStoreIdForCurrentVersion( long creationTime, long randomId, long upgradeTime, long
upgradeId )
{
RecordFormats select = InternalRecordFormatSelector.select();
return new StoreId( creationTime, randomId, MetaDataStore.versionStringToLong( select.storeVersion() ),
upgradeTime, upgradeId );
}
}
@@ -0,0 +1,35 @@
/*
* Copyright (c) 2002-2016 "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.kernel.impl.store.format.lowlimit;

import org.junit.Test;

import org.neo4j.kernel.impl.store.format.InternalRecordFormatSelector;

import static org.junit.Assert.assertEquals;

public class LowLimitTest
{
@Test
public void shouldResolveLowLimitsRecordFormat() throws Exception
{
assertEquals( LowLimit.RECORD_FORMATS.storeVersion(), InternalRecordFormatSelector.select().storeVersion() );
}
}
Expand Up @@ -19,9 +19,10 @@
*/
package org.neo4j.com;

import org.neo4j.kernel.impl.store.StoreId;
import org.neo4j.test.subprocess.SubProcess;

import static org.neo4j.kernel.impl.store.StoreIdTestFactory.newStoreIdForCurrentVersion;

public class MadeUpServerProcess extends SubProcess<ServerInterface, StartupData> implements ServerInterface
{
private static final long serialVersionUID = 1L;
Expand All @@ -34,7 +35,7 @@ public class MadeUpServerProcess extends SubProcess<ServerInterface, StartupData
protected void startup( StartupData data ) throws Throwable
{
MadeUpCommunicationInterface implementation = new MadeUpServerImplementation(
new StoreId( data.creationTime, data.storeId, data.creationTime, data.storeId ) );
newStoreIdForCurrentVersion( data.creationTime, data.storeId, data.creationTime, data.storeId ) );
MadeUpServer localServer = new MadeUpServer( implementation, 8888, data.internalProtocolVersion,
data.applicationProtocolVersion, TxChecksumVerifier.ALWAYS_MATCH, data.chunkSize );
localServer.init();
Expand Down
Expand Up @@ -36,6 +36,8 @@
import org.neo4j.kernel.impl.transaction.log.TransactionIdStore;
import org.neo4j.kernel.lifecycle.LifeSupport;

import static java.lang.System.currentTimeMillis;
import static java.lang.Thread.yield;
import static org.hamcrest.Matchers.lessThanOrEqualTo;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
Expand All @@ -48,13 +50,10 @@
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoMoreInteractions;
import static org.mockito.Mockito.verifyZeroInteractions;

import static java.lang.System.currentTimeMillis;
import static java.lang.Thread.yield;

import static org.neo4j.com.MadeUpServer.FRAME_LENGTH;
import static org.neo4j.com.TxChecksumVerifier.ALWAYS_MATCH;
import static org.neo4j.com.storecopy.ResponseUnpacker.NO_OP_TX_HANDLER;
import static org.neo4j.kernel.impl.store.StoreIdTestFactory.newStoreIdForCurrentVersion;

public class TestCommunication
{
Expand All @@ -69,7 +68,7 @@ public class TestCommunication
@Before
public void doBefore()
{
storeIdToUse = new StoreId();
storeIdToUse = newStoreIdForCurrentVersion();
builder = new Builder();
}

Expand Down Expand Up @@ -109,7 +108,7 @@ private void waitUntilResponseHasBeenWritten( MadeUpServer server, int maxTime )
public void makeSureClientStoreIdsMustMatch() throws Throwable
{
MadeUpServer server = builder.server();
MadeUpClient client = builder.storeId( new StoreId( 10, 10, 10, 10 ) ).client();
MadeUpClient client = builder.storeId( newStoreIdForCurrentVersion( 10, 10, 10, 10 ) ).client();
addToLifeAndStart( server, client );

client.multiply( 1, 2 );
Expand All @@ -118,7 +117,7 @@ public void makeSureClientStoreIdsMustMatch() throws Throwable
@Test(expected = MismatchingStoreIdException.class)
public void makeSureServerStoreIdsMustMatch() throws Throwable
{
MadeUpServer server = builder.storeId( new StoreId( 10, 10, 10, 10 ) ).server();
MadeUpServer server = builder.storeId( newStoreIdForCurrentVersion( 10, 10, 10, 10 ) ).server();
MadeUpClient client = builder.client();
addToLifeAndStart( server, client );

Expand Down
Expand Up @@ -35,7 +35,6 @@
import org.neo4j.kernel.impl.store.MetaDataStore;
import org.neo4j.kernel.impl.store.NeoStores;
import org.neo4j.kernel.impl.store.StoreFactory;
import org.neo4j.kernel.impl.store.StoreId;
import org.neo4j.kernel.impl.transaction.CommittedTransactionRepresentation;
import org.neo4j.kernel.impl.transaction.log.LogicalTransactionStore;
import org.neo4j.kernel.monitoring.Monitors;
Expand All @@ -46,6 +45,7 @@
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock;
import static org.neo4j.kernel.impl.store.StoreIdTestFactory.newStoreIdForCurrentVersion;

public class ResponsePackerIT
{
Expand Down Expand Up @@ -77,7 +77,8 @@ public void shouldPackTheHighestTxCommittedAsObligation() throws Exception
final long expectedTxId = 8L;
store.transactionCommitted( expectedTxId, 777 );

ResponsePacker packer = new ResponsePacker( transactionStore, store, Suppliers.singleton( new StoreId() ) );
ResponsePacker packer =
new ResponsePacker( transactionStore, store, Suppliers.singleton( newStoreIdForCurrentVersion() ) );

// WHEN
Response<Object> response =
Expand Down
Expand Up @@ -29,7 +29,7 @@
import org.neo4j.cursor.IOCursor;
import org.neo4j.function.Suppliers;
import org.neo4j.helpers.collection.Visitor;
import org.neo4j.kernel.impl.store.StoreId;
import org.neo4j.kernel.impl.store.StoreIdTestFactory;
import org.neo4j.kernel.impl.transaction.CommittedTransactionRepresentation;
import org.neo4j.kernel.impl.transaction.DeadSimpleTransactionIdStore;
import org.neo4j.kernel.impl.transaction.log.LogicalTransactionStore;
Expand Down Expand Up @@ -57,7 +57,7 @@ public void shouldHaveFixedTargetTransactionIdEvenIfLastTransactionIdIsMoving()
final long targetTransactionId = 8L;
final TransactionIdStore transactionIdStore = new DeadSimpleTransactionIdStore( targetTransactionId, 0, 0, 0 );
ResponsePacker packer = new ResponsePacker( transactionStore, transactionIdStore,
Suppliers.singleton( new StoreId() ) );
Suppliers.singleton( StoreIdTestFactory.newStoreIdForCurrentVersion() ) );

// WHEN
Response<Object> response = packer.packTransactionStreamResponse( requestContextStartingAt( 5L ), null );
Expand Down

0 comments on commit f8aed0d

Please sign in to comment.