Skip to content

Commit

Permalink
compat script
Browse files Browse the repository at this point in the history
  • Loading branch information
yuvalr1neo committed Apr 15, 2024
1 parent 374a353 commit 6ca575b
Show file tree
Hide file tree
Showing 4 changed files with 231 additions and 0 deletions.
18 changes: 18 additions & 0 deletions compatibility/5.19/neo4j-kernel-adapter/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
apply plugin: 'java-library'

description = 'Neo4j Graph Data Science :: Neo4j Kernel Adapter 5.19'

group = 'org.neo4j.gds'

dependencies {
annotationProcessor project(':annotations')
annotationProcessor group: 'org.neo4j', name: 'annotations', version: neos.'5.19'
annotationProcessor group: 'org.immutables', name: 'value', version: ver.'immutables'

compileOnly project(':annotations')
compileOnly group: 'org.neo4j', name: 'annotations', version: neos.'5.19'
compileOnly group: 'org.neo4j', name: 'neo4j', version: neos.'5.19'
compileOnly group: 'org.immutables', name: 'value-annotations', version: ver.'immutables'

implementation project(':neo4j-kernel-adapter-api')
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* Copyright (c) "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.gds.compat._519;

import org.neo4j.annotations.service.ServiceProvider;
import org.neo4j.gds.compat.Neo4jProxyApi;
import org.neo4j.gds.compat.Neo4jProxyFactory;
import org.neo4j.gds.compat.Neo4jVersion;

@ServiceProvider
public final class Neo4jProxyFactoryImpl implements Neo4jProxyFactory {

@Override
public boolean canLoad(Neo4jVersion version) {
return version == Neo4jVersion.V_Dev;
}

@Override
public Neo4jProxyApi load() {
return new Neo4jProxyImpl();
}

@Override
public String description() {
return "Neo4j 5.19";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
/*
* Copyright (c) "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.gds.compat._519;

import org.neo4j.common.DependencyResolver;
import org.neo4j.configuration.Config;
import org.neo4j.gds.compat.CompatMonitor;
import org.neo4j.gds.compat.Neo4jProxyApi;
import org.neo4j.internal.batchimport.AdditionalInitialIds;
import org.neo4j.internal.batchimport.BatchImporter;
import org.neo4j.internal.batchimport.Configuration;
import org.neo4j.internal.batchimport.Monitor;
import org.neo4j.internal.batchimport.input.Collector;
import org.neo4j.internal.kernel.api.NodeCursor;
import org.neo4j.internal.kernel.api.Read;
import org.neo4j.io.fs.FileSystemAbstraction;
import org.neo4j.io.layout.DatabaseLayout;
import org.neo4j.io.pagecache.context.CursorContextFactory;
import org.neo4j.io.pagecache.context.FixedVersionContextSupplier;
import org.neo4j.io.pagecache.tracing.PageCacheTracer;
import org.neo4j.kernel.api.KernelTransaction;
import org.neo4j.kernel.impl.index.schema.IndexImporterFactoryImpl;
import org.neo4j.kernel.impl.transaction.log.files.TransactionLogInitializer;
import org.neo4j.logging.internal.LogService;
import org.neo4j.memory.EmptyMemoryTracker;
import org.neo4j.scheduler.JobScheduler;
import org.neo4j.storageengine.api.StorageEngineFactory;

import java.io.PrintStream;
import java.nio.charset.StandardCharsets;
import java.util.Optional;
import java.util.function.Function;

public final class Neo4jProxyImpl implements Neo4jProxyApi {

private static final DependencyResolver EMPTY_DEPENDENCY_RESOLVER = new DependencyResolver() {
@Override
public <T> T resolveDependency(Class<T> type, SelectionStrategy selector) {
return null;
}

@Override
public boolean containsDependency(Class<?> type) {
return false;
}
};

@Override
public DependencyResolver emptyDependencyResolver() {
return EMPTY_DEPENDENCY_RESOLVER;
}

@Override
public CursorContextFactory cursorContextFactory(Optional<PageCacheTracer> pageCacheTracer) {
return pageCacheTracer.map(cacheTracer -> new CursorContextFactory(
cacheTracer,
FixedVersionContextSupplier.EMPTY_CONTEXT_SUPPLIER
)).orElse(CursorContextFactory.NULL_CONTEXT_FACTORY);
}

@Override
public String neo4jArrowServerAddressHeader() {
// TODO: replace this with a dependency to neo4j once we moved the corresponding piece to a public module
return "ArrowPluginAddress";
}

@Override
public <T> T nodeLabelTokenSet(
NodeCursor nodeCursor,
Function<int[], T> intsConstructor,
Function<long[], T> longsConstructor
) {
return intsConstructor.apply(nodeCursor.labels().all());
}

@Override
public String metricsManagerClass() {
return "com.neo4j.metrics.MetricsManager";
}

@Override
public long estimateNodeCount(Read read, int label) {
return read.estimateCountsForNode(label);
}

@Override
public long estimateRelationshipCount(Read read, int sourceLabel, int targetLabel, int type) {
return read.estimateCountsForRelationships(sourceLabel, type, targetLabel);
}

@Override
public void registerCloseableResource(KernelTransaction transaction, AutoCloseable autoCloseable) {
transaction.resourceMonitor().registerCloseableResource(autoCloseable);
}

@Override
public BatchImporter instantiateBlockBatchImporter(
DatabaseLayout databaseLayout,
FileSystemAbstraction fileSystem,
PageCacheTracer pageCacheTracer,
Configuration configuration,
CompatMonitor compatMonitor,
LogService logService,
AdditionalInitialIds additionalInitialIds,
Config dbConfig,
JobScheduler jobScheduler,
Collector badCollector
) {
var storageEngineFactory = StorageEngineFactory.selectStorageEngine(dbConfig);
var progressOutput = new PrintStream(PrintStream.nullOutputStream(), true, StandardCharsets.UTF_8);
var verboseProgressOutput = false;

return storageEngineFactory.batchImporter(
databaseLayout,
fileSystem,
pageCacheTracer,
configuration,
logService,
progressOutput,
verboseProgressOutput,
additionalInitialIds,
dbConfig,
toMonitor(compatMonitor),
jobScheduler,
badCollector,
TransactionLogInitializer.getLogFilesInitializer(),
new IndexImporterFactoryImpl(),
EmptyMemoryTracker.INSTANCE,
cursorContextFactory(Optional.empty())
);
}

private static Monitor toMonitor(CompatMonitor compatMonitor) {
return new Monitor() {
@Override
public void started() {
compatMonitor.started();
}

@Override
public void percentageCompleted(int percentage) {
compatMonitor.percentageCompleted(percentage);
}

@Override
public void completed(boolean success) {
compatMonitor.completed(success);
}
};
}
}
1 change: 1 addition & 0 deletions gradle/dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ ext {
'5.16': properties.getOrDefault('neo4jVersion516', '5.16.0'),
'5.17': properties.getOrDefault('neo4jVersion517', '5.17.0'),
'5.18': properties.getOrDefault('neo4jVersion518', '5.18.1'),
'5.19': properties.getOrDefault('neo4jVersion519', '5.19.0'),
]

neo4jDefault = neos.'5.17'
Expand Down

0 comments on commit 6ca575b

Please sign in to comment.