Skip to content

Commit

Permalink
Update to 3.3.4, release-zip, adapted copy-store script
Browse files Browse the repository at this point in the history
  • Loading branch information
jexp committed Mar 22, 2018
1 parent d073da9 commit d5ccfc3
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 28 deletions.
19 changes: 17 additions & 2 deletions copy-store.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/bin/bash

# NEO4J_HOME=${NEO4J_HOME-/var/lib/neo4j}
EDITION=${1-community}
shift
SRC=$1
Expand All @@ -13,6 +14,7 @@ HEAP=4G
CACHE=2G
CACHE_SRC=1G
#$CACHE
echo "To use your existing Neo4j 3.3.x installation set NEO4J_HOME to your Neo4j directory. Currently set to: $NEO4J_HOME"
echo "Usage: copy-store.sh [community|enterprise] source.db target.db [RELS,TO,SKIP] [props,to,skip] [Labels,To,Skip] [Labels,To,Delete,Nodes]"

if [[ "$EDITION" != "enterprise" && "$EDITION" != "community" ]]
Expand All @@ -32,13 +34,26 @@ then
exit
fi

echo
echo "Using: Heap $HEAP Pagecache $CACHE Edition '$EDITION' from '$SRC' to '$DST' skipping labels: '$SKIP_LABELS', removing nodes with labels: '$DELETE_NODES' rels: '$SKIP_RELS' props '$SKIP_PROPS' Keeping Node Ids: $KEEP_NODE_IDS"
echo
echo "Please note that you will need this memory ($CACHE + $CACHE_SRC + $HEAP) as it opens 2 databases one for reading and one for writing."
echo
# heap config
export MAVEN_OPTS="-Xmx$HEAP -Xms$HEAP -XX:+UseG1GC"
MAVEN=`which mvn`
JARFILE=`echo store-util-*.jar`

mvn clean compile exec:java -P${EDITION} -e -Dexec.mainClass="org.neo4j.tool.StoreCopy" -Ddbms.pagecache.memory=$CACHE -Ddbms.pagecache.memory.source=$CACHE_SRC \
-Dexec.args="$SRC $DST $SKIP_RELS $SKIP_PROPS $SKIP_LABELS $DELETE_NODES $KEEP_NODE_IDS"
if [[ -d "$NEO4J_HOME" && -f "$JARFILE" ]]; then
java $MAVEN_OPTS -Ddbms.pagecache.memory=$CACHE -Ddbms.pagecache.memory.source=$CACHE_SRC -classpath "$NEO4J_HOME/lib/*":$JARFILE org.neo4j.tool.StoreCopy \
$SRC $DST $SKIP_RELS $SKIP_PROPS $SKIP_LABELS $DELETE_NODES $KEEP_NODE_IDS
else
if [[ ! -f $MAVEN ]]; then
echo "Apache Maven not installed"
else
$MAVEN clean compile exec:java -P${EDITION} -e -Dexec.mainClass="org.neo4j.tool.StoreCopy" -Ddbms.pagecache.memory=$CACHE -Ddbms.pagecache.memory.source=$CACHE_SRC \
-Dexec.args="$SRC $DST $SKIP_RELS $SKIP_PROPS $SKIP_LABELS $DELETE_NODES $KEEP_NODE_IDS"
fi
fi

#-Dneo4j.version=2.3.0
25 changes: 16 additions & 9 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<groupId>org.neo4j</groupId>
<artifactId>store-util</artifactId>
<version>3.3.0</version>
<version>3.3.4</version>
<packaging>jar</packaging>

<name>store-util</name>
Expand Down Expand Up @@ -69,17 +69,24 @@
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.1.0</version>
<configuration>
<archive>
<manifest>
<mainClass>org.neo4j.tool.StoreCopy</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<formats><format>zip</format></formats>
<descriptors>
<descriptor>src/assembly/assembly.xml</descriptor>
</descriptors>
<finalName>store-util-${project.version}</finalName>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>

<plugin>
Expand Down
24 changes: 24 additions & 0 deletions src/assembly/assembly.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<assembly xmlns="http://maven.apache.org/ASSEMBLY/2.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/ASSEMBLY/2.0.0 http://maven.apache.org/xsd/assembly-2.0.0.xsd">
<id>release</id>
<formats>
<format>zip</format>
</formats>
<fileSets>
<fileSet>
<includes>
<include>readme.md</include>
<include>copy-store.sh</include>
</includes>
<outputDirectory>/</outputDirectory>
</fileSet>
<fileSet>
<directory>${basedir}/target</directory>
<includes>
<include>store-util*.jar</include>
</includes>
<outputDirectory>/</outputDirectory>
</fileSet>
</fileSets>
</assembly>
27 changes: 10 additions & 17 deletions src/main/java/org/neo4j/tool/StoreCopy.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ private static void copyStore(String sourceDir, String targetDir, Set<String> ig
final File target = new File(targetDir);
final File source = new File(sourceDir);
if (target.exists()) {
FileUtils.deleteRecursively(target);
// throw new IllegalArgumentException("Target Directory already exists "+target);
// FileUtils.deleteRecursively(target);
throw new IllegalArgumentException("Target Directory already exists "+target);
}
if (!source.exists()) throw new IllegalArgumentException("Source Database does not exist " + source);

Expand All @@ -87,7 +87,7 @@ private static void copyStore(String sourceDir, String targetDir, Set<String> ig
logs.append(String.format("Noncritical error closing the source database:%n%s", Exceptions.stringify(e)));
}
logs.close();
copyIndex(source, target);
if (stableNodeIds) copyIndex(source, target);
}

private static Flusher getFlusher(BatchInserter db) {
Expand Down Expand Up @@ -188,12 +188,12 @@ private static long firstNode(BatchInserter sourceDb, long highestNodeId) {
}

private static void flushCache(BatchInserter sourceDb, long node) {
Map<String, Value> nodeProperties = sourceDb.getNodeProperties(node);
Iterator<Map.Entry<String, Value>> iterator = nodeProperties.entrySet().iterator();
Map<String, Object> nodeProperties = sourceDb.getNodeProperties(node);
Iterator<Map.Entry<String, Object>> iterator = nodeProperties.entrySet().iterator();
if (iterator.hasNext()) {
Map.Entry<String, Value> firstProp = iterator.next();
Map.Entry<String, Object> firstProp = iterator.next();
sourceDb.nodeHasProperty(node,firstProp.getKey());
sourceDb.setNodeProperty(node, firstProp.getKey(), firstProp.getValue().asObject()); // force flush
sourceDb.setNodeProperty(node, firstProp.getKey(), firstProp.getValue()); // force flush
System.out.print(" flush");
}
}
Expand Down Expand Up @@ -270,24 +270,17 @@ private static Label[] labelsArray(BatchInserter db, long node, Set<String> igno
Collection<Label> labels = Iterables.asCollection(db.getNodeLabels(node));
if (labels.isEmpty()) return NO_LABELS;
if (!ignoreLabels.isEmpty()) {
for (Iterator<Label> it = labels.iterator(); it.hasNext(); ) {
Label label = it.next();
if (ignoreLabels.contains(label.name())) {
it.remove();
}
}
labels.removeIf(label -> ignoreLabels.contains(label.name()));
}
return labels.toArray(new Label[labels.size()]);
}

private static Map<String, Object> getProperties(Map<String, Value> pc, Set<String> ignoreProperties) {
private static Map<String, Object> getProperties(Map<String, Object> pc, Set<String> ignoreProperties) {
if (pc.isEmpty()) return Collections.emptyMap();
Map<String,Object> result = new HashMap<>(pc.size());
if (!ignoreProperties.isEmpty()) {
pc.keySet().removeAll(ignoreProperties);
}
pc.forEach((k,v) -> result.put(k,v.asObject()));
return result;
return pc;
}

private static void addLog(BatchRelationship rel, String property, String message) {
Expand Down

0 comments on commit d5ccfc3

Please sign in to comment.