Re: [Neo4j] how many relationships?
thanks for that, I only had embedded-examples changed, but it looks like I was doing the git pull wrong, that is I was using `git fetch from upstream` instead of `git pull`... I actually never had to use this before :) I was only ever committing with git (used svn/mercurial before though) For some reason I remembered (from a friend) that fetch was the way to pull. So I did the git pull and it worked (the counting worked as expected too, hooray!). Thus my bad, soz :) I am glad I didn't have to wait 3 days, I even looked into Organizations on github as an alternative way of getting limited (read-only) access to the committers' repo. Now I can continue ... xD On Fri, Jul 22, 2011 at 7:51 AM, Michael Hunger michael.hun...@neotechnology.com wrote: github has no separate repo for the readonly url most probably your git pull failed due to local changes git stash them or use git pull --rebase Michael mobile mail please excuse brevity and typos Am 22.07.2011 um 04:32 schrieb cyuczi eekc cyuczie...@gmail.com: Hey, btw, the issue was fixed: https://trac.neo4j.org/ticket/356#comment:1 However, github didn't yet sync the git-readonly (ie. git:// github.com/neo4j/community.git ) and looks like I am 3-4 days back, since my HEAD is at: Minor fix to the cypher/identifiers section. https://github.com/neo4j/community/commit/dc260c269ae4e09362ada181d7b9a42e6c86560e nawroth https://github.com/nawroth (author) 3 days ago as seen here: https://github.com/neo4j/community/commits/master/ I guess that is why you didn't say anything yet (because me fetching from git would not be able to get the fix yet, 3 more days geezuz xD) Anyway, I'm only saying this just in case you were not aware this was fixed (apparently by someone else) and you were still working on it. Sorry, I already had made a ticket about this before you last replied. Thank you all, can't wait to test :) On Thu, Jul 21, 2011 at 12:13 PM, Michael Hunger michael.hun...@neotechnology.com wrote: We're already on it. Looking through the causes for that issue and will keep you and everyone else informed. Michael Am 21.07.2011 um 06:52 schrieb cyuczi eekc: about this, should I create an issue? ___ Neo4j mailing list User@lists.neo4j.org https://lists.neo4j.org/mailman/listinfo/user ___ Neo4j mailing list User@lists.neo4j.org https://lists.neo4j.org/mailman/listinfo/user ___ Neo4j mailing list User@lists.neo4j.org https://lists.neo4j.org/mailman/listinfo/user ___ Neo4j mailing list User@lists.neo4j.org https://lists.neo4j.org/mailman/listinfo/user
[Neo4j] nested transactions feature ?
Hello. Are nested transaction supported? From what I'm testing here, it looks like unless I specify .failure() on the nested transaction, before it reaches .finish() the transaction is considered to be successful (even if I didn't call .success() on it). Though if I do call .failure() then the root transaction will be rolled back with exception: Exception in thread main org.neo4j.graphdb.TransactionFailureException: Unable to commit transaction at org.neo4j.kernel.TopLevelTransaction.finish(TopLevelTransaction.java:98) at org.neo4j.examples.CalculateShortestPath.main(CalculateShortestPath.java:116) Caused by: javax.transaction.RollbackException: Failed to commit, transaction rolledback at org.neo4j.kernel.impl.transaction.TxManager.rollbackCommit(TxManager.java:811) at org.neo4j.kernel.impl.transaction.TxManager.commit(TxManager.java:645) at org.neo4j.kernel.impl.transaction.TransactionImpl.commit(TransactionImpl.java:109) at org.neo4j.kernel.TopLevelTransaction.finish(TopLevelTransaction.java:85) ... 1 more In the root transaction however, if I don't explicitly call .success() it is considered failure and rolled back on finish. This seem to be the main difference between root transaction and the nested transaction; was this intended? here's a sample program to test: (points 1. and 2. are important to me) 1. run it as it is, to see that nested transaction doesn't default to failure when none of .failure() or .success() are specified before reaching .finish(); is this a feature? (I just remembered that possibly someone told me about this yesterday? I cannot find the message) 2. uncomment // nestyTx.failure(); to see what happens when specifically stating that the nested transaction failed == the root one will rollback with exception, which might be fine, I guess... though maybe I would expect that the root transaction not be affected by a rolled back child transaction, I mean, I might retry the child transaction and succeed the second time, but the root will fail because some child transaction failed before... to get the idea of this, use this code block (you'll know where to put it, replacing the old part): Transaction nestyTx = graphDb.beginTx(); try { Relationship rel = one.createRelationshipTo( graphDb.createNode(), moo ); if ( i % 2 == 0 ) { nestyTx.success();// no need to uncomment this, for nested this is the default, not intended? } else { nestyTx.failure();// XXX: uncomment this to cause rootTx to fail } } finally { nestyTx.finish(); } 3. comment out the rootTx (all of begin/success/finish at once) to see the speed that nestyTx has when it isn't a nested transaction == way slower than when it's nested - though I guess this might make sense, since nothing is really committed unless the root transaction commits. /** * Licensed to Neo Technology under one or more contributor * license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright * ownership. Neo Technology licenses this file to you under * the Apache License, Version 2.0 (the License); you may * not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * AS IS BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ package org.neo4j.examples; import java.io.*; import java.text.*; import org.neo4j.graphdb.*; import org.neo4j.graphdb.index.*; import org.neo4j.kernel.*; public class CalculateShortestPath { private static final int SHOWINFO_IF_COUNTING_REL_TOOK_MORE_THAN_ns= 2 * 300; private static final intSHOWINFO_IF_REL_TOOK_MORE_THAN_ns = 3; private static final intSHOWEVERY_xTH_REL = 1; private static final intHOWMANY_RELATIONSHIPS = 9000; private static final StringDB_PATH = neo4j-shortest-path; private static final StringNAME_KEY = name; private static RelationshipTypeKNOWS = DynamicRelationshipType .withName( KNOWS ); private static GraphDatabaseServicegraphDb; private static IndexNodeindexService; private static DecimalFormatcommaDelimitedFormatter = new DecimalFormat( ###,### ); public static String number( double val ) { return commaDelimitedFormatter.format( val ); } public static void main( final String[] args ) { //
Re: [Neo4j] how many relationships?
Hey, btw, the issue was fixed: https://trac.neo4j.org/ticket/356#comment:1 However, github didn't yet sync the git-readonly (ie. git:// github.com/neo4j/community.git ) and looks like I am 3-4 days back, since my HEAD is at: Minor fix to the cypher/identifiers section. https://github.com/neo4j/community/commit/dc260c269ae4e09362ada181d7b9a42e6c86560e nawroth https://github.com/nawroth (author) 3 days ago as seen here: https://github.com/neo4j/community/commits/master/ I guess that is why you didn't say anything yet (because me fetching from git would not be able to get the fix yet, 3 more days geezuz xD) Anyway, I'm only saying this just in case you were not aware this was fixed (apparently by someone else) and you were still working on it. Sorry, I already had made a ticket about this before you last replied. Thank you all, can't wait to test :) On Thu, Jul 21, 2011 at 12:13 PM, Michael Hunger michael.hun...@neotechnology.com wrote: We're already on it. Looking through the causes for that issue and will keep you and everyone else informed. Michael Am 21.07.2011 um 06:52 schrieb cyuczi eekc: about this, should I create an issue? ___ Neo4j mailing list User@lists.neo4j.org https://lists.neo4j.org/mailman/listinfo/user ___ Neo4j mailing list User@lists.neo4j.org https://lists.neo4j.org/mailman/listinfo/user
[Neo4j] No index provider 'lucene' found
Hi! I've been trying to fix this error, and I've kind of succeeded. My context is, that I've pulled neo4j sources from github and using them in eclipse (without maven and such), and I have the neo4j-community sources as a project, and I am including this project in any of my projects that require neo4j, instead of using the neo4j precompiled jars So far so good, except I get that error. And my current workaround is: unzip the file: META-INF\services\org.neo4j.graphdb.index.IndexProvider from this jar: neo4j-lucene-index-1.4.jar preserving the path into the neo4j-community project's bin folder so it looks like: ...\workspace\neo4j-community\bin\META-INF\services\org.neo4j.graphdb.index.IndexProvider and the content for this file (for informational reasons): org.neo4j.index.lucene.LuceneIndexProvider (without quotes) So this works, ie. in another project I include this neo4j-community project and run something that uses lucene index (ie. org.neo4j.examples.CalculateShortestPath) and I don't get that error anymore, simply works. My question is, what is a better way to fix this error ? perhaps by using java code instead ? Or I don't know, why doesn't it use a default? Can I specify it from code? Assume that I don't know much, and I've only discovered neo4j this week, but I am into it and I want to build some things on top of it. this is the line that is causing the error (when I don't fix it as I said above): indexService = graphDb.index().forNodes( nodes ); and this is the full stacktrace for the error: Exception in thread main java.lang.IllegalArgumentException: No index provider 'lucene' found at org.neo4j.kernel.IndexManagerImpl.getIndexProvider(IndexManagerImpl.java:76) at org.neo4j.kernel.IndexManagerImpl.findIndexConfig(IndexManagerImpl.java:116) at org.neo4j.kernel.IndexManagerImpl.getOrCreateIndexConfig(IndexManagerImpl.java:178) at org.neo4j.kernel.IndexManagerImpl.getOrCreateNodeIndex(IndexManagerImpl.java:267) at org.neo4j.kernel.IndexManagerImpl.forNodes(IndexManagerImpl.java:255) at org.neo4j.kernel.IndexManagerImpl.forNodes(IndexManagerImpl.java:249) at org.neo4j.examples.CalculateShortestPath.main(CalculateShortestPath.java:43) Thanks! ___ Neo4j mailing list User@lists.neo4j.org https://lists.neo4j.org/mailman/listinfo/user
[Neo4j] how many relationships?
Is there a way to get the number of relationships without having to iterate through (and count++) them? ie. rels=firstNode.getRelationships(); rels.size(); //doesn't actually exist ___ Neo4j mailing list User@lists.neo4j.org https://lists.neo4j.org/mailman/listinfo/user
Re: [Neo4j] No index provider 'lucene' found
but but I don't know what osgi and project bundle stuff really is :) I don't think I would need that for what I want. (if those mean building as .jar or using jars) What I actually want is to keep the neo4j-community project (which is git linked to the github sources), keep this as source only (without having it bundled or exported as jar, but probably having it compiled as classes aka build project) and have this project used by other projects(by simply including the project instead of its .jars or anything else), so that I can see the javadoc(and jump to the source) and even eventually edit a few parts (of neo4j) and add ie. a System.out.println() (if it were bundled I couldn't do that, unless I'd rebundle it, that would be a headache to do on each modify or git fetch). In other words, I want to be able to use neo4j, from the sources (no .jars). I've been able to use other projects like this before (ie. jmonkeyengine aka jme3). In this regard, is there a better fix? Thank you. On Wed, Jul 20, 2011 at 7:17 PM, Peter Neubauer neubauer.pe...@gmail.comwrote: Hi there, That again is OSGi playing against Java Service Loader. Look at the neo4j / osgi / bundle project to build a working superbundle with the default community jars and report back! /peter Sent from my phone. On Jul 20, 2011 7:02 PM, cyuczi eekc cyuczie...@gmail.com wrote: Hi! I've been trying to fix this error, and I've kind of succeeded. My context is, that I've pulled neo4j sources from github and using them in eclipse (without maven and such), and I have the neo4j-community sources as a project, and I am including this project in any of my projects that require neo4j, instead of using the neo4j precompiled jars So far so good, except I get that error. And my current workaround is: unzip the file: META-INF\services\org.neo4j.graphdb.index.IndexProvider from this jar: neo4j-lucene-index-1.4.jar preserving the path into the neo4j-community project's bin folder so it looks like: ...\workspace\neo4j-community\bin\META-INF\services\org.neo4j.graphdb.index.IndexProvider and the content for this file (for informational reasons): org.neo4j.index.lucene.LuceneIndexProvider (without quotes) So this works, ie. in another project I include this neo4j-community project and run something that uses lucene index (ie. org.neo4j.examples.CalculateShortestPath) and I don't get that error anymore, simply works. My question is, what is a better way to fix this error ? perhaps by using java code instead ? Or I don't know, why doesn't it use a default? Can I specify it from code? Assume that I don't know much, and I've only discovered neo4j this week, but I am into it and I want to build some things on top of it. this is the line that is causing the error (when I don't fix it as I said above): indexService = graphDb.index().forNodes( nodes ); and this is the full stacktrace for the error: Exception in thread main java.lang.IllegalArgumentException: No index provider 'lucene' found at org.neo4j.kernel.IndexManagerImpl.getIndexProvider(IndexManagerImpl.java:76) at org.neo4j.kernel.IndexManagerImpl.findIndexConfig(IndexManagerImpl.java:116) at org.neo4j.kernel.IndexManagerImpl.getOrCreateIndexConfig(IndexManagerImpl.java:178) at org.neo4j.kernel.IndexManagerImpl.getOrCreateNodeIndex(IndexManagerImpl.java:267) at org.neo4j.kernel.IndexManagerImpl.forNodes(IndexManagerImpl.java:255) at org.neo4j.kernel.IndexManagerImpl.forNodes(IndexManagerImpl.java:249) at org.neo4j.examples.CalculateShortestPath.main(CalculateShortestPath.java:43) Thanks! ___ Neo4j mailing list User@lists.neo4j.org https://lists.neo4j.org/mailman/listinfo/user ___ Neo4j mailing list User@lists.neo4j.org https://lists.neo4j.org/mailman/listinfo/user ___ Neo4j mailing list User@lists.neo4j.org https://lists.neo4j.org/mailman/listinfo/user
Re: [Neo4j] No index provider 'lucene' found
that is awesome! that file is there: ..\workspace\neo4j-community\lucene-index\src\main\resources\META-INF\services\ though if I add lucene-index\src\main\resources\ as source folder, i get some weird java exception and no-class def found error :)) but you probably only wanted me to add it in class path or something, let's see ... Yeah that works, so in eclipse: Project-Properties-Java Build Path-Libraries- Add Class Folder: neo4j-community\lucene-index\src\main\resources\ where in my case neo4j-community is the name of the project which I chose when I git cloned or something And it works! Yeahhh, me happy ;) hey it's better than pulling out that file from the .jar :) is there any other way to do this from code? ie. without neo4j having to use that specific file ? maybe I could call some method and tell it to use the lucene index? Even so, this was great progress! Thank you so mucho haha :P On Wed, Jul 20, 2011 at 7:46 PM, Peter Neubauer peter.neuba...@neotechnology.com wrote: For sources, I guess you would need to mount the src/main/resources folders as source folders in order to have the META-INF/services files on the classpath. Does that work? Cheers, /peter neubauer GTalk: neubauer.peter Skype peter.neubauer Phone +46 704 106975 LinkedIn http://www.linkedin.com/in/neubauer Twitter http://twitter.com/peterneubauer http://www.neo4j.org - Your high performance graph database. http://startupbootcamp.org/- Öresund - Innovation happens HERE. http://www.thoughtmade.com - Scandinavia's coolest Bring-a-Thing party. On Wed, Jul 20, 2011 at 7:43 PM, cyuczi eekc cyuczie...@gmail.com wrote: but but I don't know what osgi and project bundle stuff really is :) I don't think I would need that for what I want. (if those mean building as .jar or using jars) What I actually want is to keep the neo4j-community project (which is git linked to the github sources), keep this as source only (without having it bundled or exported as jar, but probably having it compiled as classes aka build project) and have this project used by other projects(by simply including the project instead of its .jars or anything else), so that I can see the javadoc(and jump to the source) and even eventually edit a few parts (of neo4j) and add ie. a System.out.println() (if it were bundled I couldn't do that, unless I'd rebundle it, that would be a headache to do on each modify or git fetch). In other words, I want to be able to use neo4j, from the sources (no .jars). I've been able to use other projects like this before (ie. jmonkeyengine aka jme3). In this regard, is there a better fix? Thank you. On Wed, Jul 20, 2011 at 7:17 PM, Peter Neubauer neubauer.pe...@gmail.comwrote: Hi there, That again is OSGi playing against Java Service Loader. Look at the neo4j / osgi / bundle project to build a working superbundle with the default community jars and report back! /peter Sent from my phone. On Jul 20, 2011 7:02 PM, cyuczi eekc cyuczie...@gmail.com wrote: Hi! I've been trying to fix this error, and I've kind of succeeded. My context is, that I've pulled neo4j sources from github and using them in eclipse (without maven and such), and I have the neo4j-community sources as a project, and I am including this project in any of my projects that require neo4j, instead of using the neo4j precompiled jars So far so good, except I get that error. And my current workaround is: unzip the file: META-INF\services\org.neo4j.graphdb.index.IndexProvider from this jar: neo4j-lucene-index-1.4.jar preserving the path into the neo4j-community project's bin folder so it looks like: ...\workspace\neo4j-community\bin\META-INF\services\org.neo4j.graphdb.index.IndexProvider and the content for this file (for informational reasons): org.neo4j.index.lucene.LuceneIndexProvider (without quotes) So this works, ie. in another project I include this neo4j-community project and run something that uses lucene index (ie. org.neo4j.examples.CalculateShortestPath) and I don't get that error anymore, simply works. My question is, what is a better way to fix this error ? perhaps by using java code instead ? Or I don't know, why doesn't it use a default? Can I specify it from code? Assume that I don't know much, and I've only discovered neo4j this week, but I am into it and I want to build some things on top of it. this is the line that is causing the error (when I don't fix it as I said above): indexService = graphDb.index().forNodes( nodes ); and this is the full stacktrace for the error: Exception in thread main java.lang.IllegalArgumentException: No index provider 'lucene' found at org.neo4j.kernel.IndexManagerImpl.getIndexProvider(IndexManagerImpl.java:76) at org.neo4j.kernel.IndexManagerImpl.findIndexConfig
[Neo4j] retrieve all relationships of a certain type (java)
How would I go about retrieving all nodes for a certain relationship Type (ie. assuming I don't know any of them nodes) ? (in java code, the other variants rest/cypher I will probably not need to use) ie. rel.getAllNodes(Direction.INCOMING) or rel.getAllNodes(Direction.OUTGOING) or Direction.BOTH even But this is basically equivalent with retrieving all relationships that are of the specified relationship-type. So this would be more accurate: rel.getAllRelationships(); where rel is the Relationship of the type that we want and the getAllRelationships() would return something that would be a list of all relationship of that type (in the entire database I guess) but possibly _*without*_ having to iterate (or traverse?) all nodes(i guess starting from the reference node?), in order to find if each has the relationship type I'm looking for. (I haven't yet fully looked at traverse but I know it needs a starting node, even though this could probably be the reference node[?]; this makes me wonder if there's a traverser for relationships instead of just nodes - I am unsure where to look [maybe just pointing me there would be enough of a reply to this; thanks]) The way I see it, the fact that relationships have a type is an extra layer on top of the relationships (just as indexing is extra(independent) layer on top of nodes or relationships). So I see the relationships each being unique (especially since I can add the same-type relationship to the same two nodes, more than 1 time) and they are somehow coalesced together via the relationship-type. It's like the relationship-type is a set which contains a bunch of relationships (which are obviously unique ie. unique ID) and this set constitutes a relationship-type. So since it's a set (probably stored as key-value pairs on the low level) one could potentially just get the elements via an iterator or something (but I also want to know how many aka size or count, relationships are there, of this type). (what I find a bit odd though, is that you can have more than one relationship for the same two nodes (1: A-B ; 2: A-B ), although dwins(on irc) implied that this is allowed because each relationship can have key-value pairs(properties) associated with it, and thus one could use same key for each relationship but with different values, but the practicality for this escapes me) ___ Neo4j mailing list User@lists.neo4j.org https://lists.neo4j.org/mailman/listinfo/user
Re: [Neo4j] how many relationships?
I guess I was hoping it(size/count) was cached in the database or the underlaying database would provide this somehow, ie. in berkeleydb (java edition) there's a cursor.count() I could use (though I don't know how they did it implementation-wise) Thanks! I needed to know that. On Wed, Jul 20, 2011 at 8:37 PM, Jim Webber j...@neotechnology.com wrote: Hi, Responses from calling the Neo4j APIs are typically lazy, for performance reasons. So there's no way of eagerly counting the number of relationships unless you force eager evaluation as you've suggested below. Jim On 20 Jul 2011, at 11:13, cyuczi eekc wrote: Is there a way to get the number of relationships without having to iterate through (and count++) them? ie. rels=firstNode.getRelationships(); rels.size(); //doesn't actually exist ___ Neo4j mailing list User@lists.neo4j.org https://lists.neo4j.org/mailman/listinfo/user ___ Neo4j mailing list User@lists.neo4j.org https://lists.neo4j.org/mailman/listinfo/user ___ Neo4j mailing list User@lists.neo4j.org https://lists.neo4j.org/mailman/listinfo/user
[Neo4j] Transactions: what happens when tx.finish() is reached before tx.success() or tx.failure()
Does it auto fail? Considering how I see in the examples, it does auto-fail... if it doesn't then maybe the doc for tx.finish() should specify what happens, or even throw ? if there isn't a specified default. Ah, I just read the javadoc for Transaction (interface): If an exception is raised in the try-block, success()eclipse-javadoc:%E2%98%82=neo4j-community/kernel%5C/src%5C/main%5C/java%3Corg.neo4j.graphdb%7BTransaction.java%E2%98%83Transaction%E2%98%82%E2%98%82success%E2%98%82will never be invoked and the internal state of the transaction object will cause finish()eclipse-javadoc:%E2%98%82=neo4j-community/kernel%5C/src%5C/main%5C/java%3Corg.neo4j.graphdb%7BTransaction.java%E2%98%83Transaction%E2%98%82%E2%98%82finish%E2%98%82to roll back the transaction. This is very important: unless success()eclipse-javadoc:%E2%98%82=neo4j-community/kernel%5C/src%5C/main%5C/java%3Corg.neo4j.graphdb%7BTransaction.java%E2%98%83Transaction%E2%98%82%E2%98%82success%E2%98%82is invoked, the transaction will fail upon finish()eclipse-javadoc:%E2%98%82=neo4j-community/kernel%5C/src%5C/main%5C/java%3Corg.neo4j.graphdb%7BTransaction.java%E2%98%83Transaction%E2%98%82%E2%98%82finish%E2%98%82. A transaction can be explicitly marked for rollback by invoking the failure()eclipse-javadoc:%E2%98%82=neo4j-community/kernel%5C/src%5C/main%5C/java%3Corg.neo4j.graphdb%7BTransaction.java%E2%98%83Transaction%E2%98%82%E2%98%82failure%E2%98%82method. In this case, could some developer please update the tx.finish() javadoc to state that? it currently states this: Commits or marks this transaction for rollback, depending on whether success()eclipse-javadoc:%E2%98%82=neo4j-community/kernel%5C/src%5C/main%5C/java%3Corg.neo4j.graphdb%7BTransaction.java%E2%98%83Transaction%7Efinish%E2%98%82%E2%98%82success%E2%98%82or failure()eclipse-javadoc:%E2%98%82=neo4j-community/kernel%5C/src%5C/main%5C/java%3Corg.neo4j.graphdb%7BTransaction.java%E2%98%83Transaction%7Efinish%E2%98%82%E2%98%82failure%E2%98%82has been previously invoked. For some reason, this isn't clear to me that it defaults to failure() unless success() is invoked Thanks! ___ Neo4j mailing list User@lists.neo4j.org https://lists.neo4j.org/mailman/listinfo/user
Re: [Neo4j] how many relationships?
); tx.success(); } finally { long start = System.nanoTime(); tx.finish(); long end = System.nanoTime(); System.out.println( tx.finish() time= + number( end - start ) ); } // So let's find the shortest path between Neo and Agent Smith // Node neo = getOrCreateNode( Neo ); // Node agentSmith = getOrCreateNode( Agent Smith ); // // START SNIPPET: shortestPathUsage // PathFinderPath finder = GraphAlgoFactory.shortestPath( Traversal.expanderForTypes( KNOWS, Direction.BOTH ), 4 ); // Path foundPath = finder.findSinglePath( neo, agentSmith ); // System.out.println( Path from Neo to Agent Smith: + Traversal.simplePathToString( foundPath, NAME_KEY ) ); // END SNIPPET: shortestPathUsage // graphDb.shutdown(); } private static void createChain( String... names ) { for ( int i = 0; i names.length - 1; i++ ) { Node firstNode = getOrCreateNode( names[i] ); Node secondNode = getOrCreateNode( names[i + 1] ); firstNode.createRelationshipTo( secondNode, KNOWS ); } } private static Node getOrCreateNode( String name ) { Node node = indexService.get( NAME_KEY, name ).getSingle(); if ( node == null ) { node = graphDb.createNode(); node.setProperty( NAME_KEY, name ); indexService.add( node, NAME_KEY, name ); } return node; } private static void registerShutdownHook() { // Registers a shutdown hook for the Neo4j instance so that it // shuts down nicely when the VM exits (even if you Ctrl-C the // running example before it's completed) Runtime.getRuntime().addShutdownHook( new Thread() { @SuppressWarnings( synthetic-access ) @Override public void run() { System.out.println( Shutting down database ... ); graphDb.shutdown(); } } ); } private static void deleteFileOrDirectory( File file ) { if ( file.exists() ) { if ( file.isDirectory() ) { for ( File child : file.listFiles() ) { deleteFileOrDirectory( child ); } } file.delete(); } } } On Thu, Jul 21, 2011 at 3:39 AM, Michael Hunger michael.hun...@neotechnology.com wrote: Caching that result would require synchronizing it with every change using up memory and performance (at every change) for something that can be computed So far it has not been worth the effort. If you really need that value very often you could write a small TransactionEventHandler that keeps the count updated for the nodes you're interested in. You would then ask this handler for the Rel-Count of a node, which would either compute it (and add/register it to its cache) or just return it from the cache. Michael Am 20.07.2011 um 21:50 schrieb cyuczi eekc: I guess I was hoping it(size/count) was cached in the database or the underlaying database would provide this somehow, ie. in berkeleydb (java edition) there's a cursor.count() I could use (though I don't know how they did it implementation-wise) Thanks! I needed to know that. On Wed, Jul 20, 2011 at 8:37 PM, Jim Webber j...@neotechnology.com wrote: Hi, Responses from calling the Neo4j APIs are typically lazy, for performance reasons. So there's no way of eagerly counting the number of relationships unless you force eager evaluation as you've suggested below. Jim On 20 Jul 2011, at 11:13, cyuczi eekc wrote: Is there a way to get the number of relationships without having to iterate through (and count++) them? ie. rels=firstNode.getRelationships(); rels.size(); //doesn't actually exist ___ Neo4j mailing list User@lists.neo4j.org https://lists.neo4j.org/mailman/listinfo/user ___ Neo4j mailing list User@lists.neo4j.org https://lists.neo4j.org/mailman/listinfo/user ___ Neo4j mailing list User@lists.neo4j.org https://lists.neo4j.org/mailman/listinfo/user ___ Neo4j mailing list User@lists.neo4j.org https://lists.neo4j.org/mailman/listinfo/user ___ Neo4j mailing list User@lists.neo4j.org https://lists.neo4j.org/mailman/listinfo/user
Re: [Neo4j] how many relationships?
I should probably mention that I am using neo4j community (embedded) latest sources up to date from github On Thu, Jul 21, 2011 at 4:59 AM, cyuczi eekc cyuczie...@gmail.com wrote: Trying to count the relationships the normal way I find that oddly, I cannot see more than 100+x relationships, where x is the maximum number of relations ever added within a transaction. For example, if I add 91 relationships in a transation, and I count them, I have 91. I run the program again and I have 182, then I run the program again and I count 191, and any subsequent program runs will have the same 191 count. Is this a bug or am I missing something very important ?! Here's the sample code to try (run it 3 times and observe the ante-ante-last line on console: Node `one` has 191 out rels, time=24,098,904): (I don't know how I would place this code into a code block though) /** * Licensed to Neo Technology under one or more contributor * license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright * ownership. Neo Technology licenses this file to you under * the Apache License, Version 2.0 (the License); you may * not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * AS IS BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ package org.neo4j.examples; import java.io.*; import java.text.*; import org.neo4j.graphdb.*; import org.neo4j.graphdb.index.*; import org.neo4j.kernel.*; public class CalculateShortestPath { private static final int SHOWINFO_IF_COUNTING_REL_TOOK_MORE_THAN_ns= 2 * 300; private static final int SHOWINFO_IF_REL_TOOK_MORE_THAN_ns= 3; private static final intSHOWEVERY_xTH_REL = 1; private static final intHOWMANY_RELATIONSHIPS = 91; private static final StringDB_PATH = neo4j-shortest-path; private static final StringNAME_KEY = name; private static RelationshipTypeKNOWS = DynamicRelationshipType .withName( KNOWS ); private static GraphDatabaseServicegraphDb; private static IndexNodeindexService; private static DecimalFormatcommaDelimitedFormatter = new DecimalFormat( ###,### ); public static String number( double val ) { return commaDelimitedFormatter.format( val ); } public static String getTimeDelta( long start, long end ) { return commaDelimitedFormatter.format( end - start ); } public static void main( final String[] args ) { // deleteFileOrDirectory( new File( DB_PATH ) );// XXX: graphDb = new EmbeddedGraphDatabase( DB_PATH ); indexService = graphDb.index().forNodes( nodes ); registerShutdownHook(); Transaction tx = graphDb.beginTx(); try { Node one = getOrCreateNode( one ); DynamicRelationshipType moo = DynamicRelationshipType.withName( moo ); for ( int i = 1; i = HOWMANY_RELATIONSHIPS; i++ ) { long start = System.nanoTime(); Relationship rel = one.createRelationshipTo( graphDb.createNode(), moo ); rel.setProperty( relname, i ); long end = System.nanoTime(); if ( ( i % SHOWEVERY_xTH_REL == 0 ) || ( end - start SHOWINFO_IF_REL_TOOK_MORE_THAN_ns ) ) { System.out.println( number( i ) + timeDelta= + number( end - start ) ); } } System.out.println( counting... ); long start = System.nanoTime(); IterableRelationship rel = one.getRelationships( Direction.OUTGOING, moo ); long count = 0; long tstart = 0; for ( Relationship relationship : rel ) { long tend = System.nanoTime(); count++; if ( ( tend - tstart SHOWINFO_IF_COUNTING_REL_TOOK_MORE_THAN_ns ) ) { System.out.println( number( count ) + timeDelta= + number( tend - tstart ) ); } tstart = System.nanoTime(); } long end = System.nanoTime(); System.out.println( Node ` + one.getProperty( NAME_KEY ) + ` has + number( count ) + out rels, time= + number( end - start ) ); // /* // * (Neo) -- (Trinity) // * \ ^ // * v / // * (Morpheus) -- (Cypher
Re: [Neo4j] how many relationships?
{ long start = System.nanoTime(); tx.finish(); long end = System.nanoTime(); System.out.println( tx.finish() time= + number( end - start ) ); } System.out.println( counting outside of transaction... ); long start = System.nanoTime(); IterableRelationship rel = one.getRelationships( Direction.OUTGOING, moo ); long count = 0; for ( Relationship relationship : rel ) { count++; } long end = System.nanoTime(); System.out.println( Node ` + one.getProperty( NAME_KEY ) + ` has + number( count ) + out rels, time= + number( end - start ) ); // So let's find the shortest path between Neo and Agent Smith // Node neo = getOrCreateNode( Neo ); // Node agentSmith = getOrCreateNode( Agent Smith ); // // START SNIPPET: shortestPathUsage // PathFinderPath finder = GraphAlgoFactory.shortestPath( Traversal.expanderForTypes( KNOWS, Direction.BOTH ), 4 ); // Path foundPath = finder.findSinglePath( neo, agentSmith ); // System.out.println( Path from Neo to Agent Smith: + Traversal.simplePathToString( foundPath, NAME_KEY ) ); // END SNIPPET: shortestPathUsage // graphDb.shutdown(); } private static void createChain( String... names ) { for ( int i = 0; i names.length - 1; i++ ) { Node firstNode = getOrCreateNode( names[i] ); Node secondNode = getOrCreateNode( names[i + 1] ); firstNode.createRelationshipTo( secondNode, KNOWS ); } } private static Node getOrCreateNode( String name ) { Node node = indexService.get( NAME_KEY, name ).getSingle(); if ( node == null ) { System.out.println( creating new node with name= + name ); node = graphDb.createNode(); node.setProperty( NAME_KEY, name ); indexService.add( node, NAME_KEY, name ); } return node; } private static void registerShutdownHook() { // Registers a shutdown hook for the Neo4j instance so that it // shuts down nicely when the VM exits (even if you Ctrl-C the // running example before it's completed) Runtime.getRuntime().addShutdownHook( new Thread() { @SuppressWarnings( synthetic-access ) @Override public void run() { System.out.println( Shutting down database ... ); graphDb.shutdown(); } } ); } private static void deleteFileOrDirectory( File file ) { if ( file.exists() ) { if ( file.isDirectory() ) { for ( File child : file.listFiles() ) { deleteFileOrDirectory( child ); } } file.delete(); } } } On Thu, Jul 21, 2011 at 5:01 AM, cyuczi eekc cyuczie...@gmail.com wrote: I should probably mention that I am using neo4j community (embedded) latest sources up to date from github On Thu, Jul 21, 2011 at 4:59 AM, cyuczi eekc cyuczie...@gmail.com wrote: Trying to count the relationships the normal way I find that oddly, I cannot see more than 100+x relationships, where x is the maximum number of relations ever added within a transaction. For example, if I add 91 relationships in a transation, and I count them, I have 91. I run the program again and I have 182, then I run the program again and I count 191, and any subsequent program runs will have the same 191 count. Is this a bug or am I missing something very important ?! Here's the sample code to try (run it 3 times and observe the ante-ante-last line on console: Node `one` has 191 out rels, time=24,098,904): (I don't know how I would place this code into a code block though) /** * Licensed to Neo Technology under one or more contributor * license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright * ownership. Neo Technology licenses this file to you under * the Apache License, Version 2.0 (the License); you may * not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * AS IS BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ package org.neo4j.examples; import java.io.*; import java.text.*; import org.neo4j.graphdb.*; import org.neo4j.graphdb.index.*; import org.neo4j.kernel.*; public class CalculateShortestPath { private static final int SHOWINFO_IF_COUNTING_REL_TOOK_MORE_THAN_ns= 2 * 300; private static final int
[Neo4j] embedded database means it cannot be simultaneously used by multiple processes?
When trying to use the same database (or path) from two different java programs, the second one cannot open it. Is this normal ? Can't two or more java programs work on the same (embedded)database ? I used BerkeleyDB (java edition) before, and this was possible, hence why I was expecting this with neo4j too. (me sad :P) Then if so, what would be the workaround? not using embedded db ? using neo4j server instead? (didn't read about that yet) Exception in thread main org.neo4j.graphdb.TransactionFailureException: Could not create data source [nioneodb], see nested exception for cause of error at org.neo4j.kernel.impl.transaction.TxModule.registerDataSource(TxModule.java:153) at org.neo4j.kernel.GraphDbInstance.start(GraphDbInstance.java:111) at org.neo4j.kernel.EmbeddedGraphDbImpl.init(EmbeddedGraphDbImpl.java:189) at org.neo4j.kernel.EmbeddedGraphDatabase.init(EmbeddedGraphDatabase.java:86) at org.neo4j.kernel.EmbeddedGraphDatabase.init(EmbeddedGraphDatabase.java:63) at org.neo4j.examples.CalculateShortestPath.main(CalculateShortestPath.java:53) Caused by: java.lang.IllegalStateException: Unable to lock store [neo4j-shortest-path\neostore], this is usually a result of some other Neo4j kernel running usi ng the same store. at org.neo4j.kernel.impl.nioneo.store.CommonAbstractStore.checkStorage(CommonAbstractStore.java:266) at org.neo4j.kernel.impl.nioneo.store.CommonAbstractStore.init(CommonAbstractStore.java:169) at org.neo4j.kernel.impl.nioneo.store.AbstractStore.init(AbstractStore.java:120) at org.neo4j.kernel.impl.nioneo.store.NeoStore.init(NeoStore.java:65) at org.neo4j.kernel.impl.nioneo.xa.NeoStoreXaDataSource.init(NeoStoreXaDataSource.java:134) at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) at java.lang.reflect.Constructor.newInstance(Constructor.java:525) at org.neo4j.kernel.impl.transaction.XaDataSourceManager.create(XaDataSourceManager.java:76) at org.neo4j.kernel.impl.transaction.TxModule.registerDataSource(TxModule.java:147) ... 5 more ___ Neo4j mailing list User@lists.neo4j.org https://lists.neo4j.org/mailman/listinfo/user
Re: [Neo4j] embedded database means it cannot be simultaneously used by multiple processes?
I took a quick glance, though it seems they are duplicating(replicating?) the database, but I was hoping I could use only one database (instead of having multiple copies of it, though this would be good in the future of course). With this in mind, what should I look for? maybe neo4j server ? that is only one server using only one database, and have my clients be the different processes (java programs) that would talk to the server via (as I understand it) REST api ? I will look at this for now: http://wiki.neo4j.org/content/Getting_Started_With_Neo4j_Server Thank you, I will come back to HA later when I read/understand more about neo4j and stuff :) On Thu, Jul 21, 2011 at 5:31 AM, Jim Webber j...@neotechnology.com wrote: Hi Cyuczi, You can't open the same database twice in two programs. If you want data to be replicated between Neo4j instances, look into HA: http://docs.neo4j.org/chunked/stable/ha-how.html http://wiki.neo4j.org/content/High_Availability_Cluster Jim ___ Neo4j mailing list User@lists.neo4j.org https://lists.neo4j.org/mailman/listinfo/user ___ Neo4j mailing list User@lists.neo4j.org https://lists.neo4j.org/mailman/listinfo/user
Re: [Neo4j] embedded database means it cannot be simultaneously used by multiple processes?
Thanks Michael, that is good to know... I would've tried that right now, for tests, but unfortunately I get that silly error No index provider 'lucene' found, but only when using EmbeddedReadOnlyGraphDatabase, not EmbeddedGraphDatabase. Perhaps it would be worth mentioning that in order to not get the error for EmbeddedGraphDatabase, I had to add the folder .\lucene-index\src\main\resources\ to classpath, since I am not using any .jars, instead I'm using the source files directly from github (in eclipse) regarding my topic, I am reading this currently: http://wiki.neo4j.org/content/Using_the_Neo4j_Server_with_Java but it seems a bit messy, so I will probably limit myself to using embedded database for now :) On Thu, Jul 21, 2011 at 5:44 AM, Michael Hunger michael.hun...@neotechnology.com wrote: If you want to have a read-only-snapshot view of the database you can also use new EmbeddedReadOnlyGraphDatabase(path); Cheers Michael Am 21.07.2011 um 05:31 schrieb Jim Webber: Hi Cyuczi, You can't open the same database twice in two programs. If you want data to be replicated between Neo4j instances, look into HA: http://docs.neo4j.org/chunked/stable/ha-how.html http://wiki.neo4j.org/content/High_Availability_Cluster Jim ___ Neo4j mailing list User@lists.neo4j.org https://lists.neo4j.org/mailman/listinfo/user ___ Neo4j mailing list User@lists.neo4j.org https://lists.neo4j.org/mailman/listinfo/user ___ Neo4j mailing list User@lists.neo4j.org https://lists.neo4j.org/mailman/listinfo/user
Re: [Neo4j] embedded database means it cannot be simultaneously used by multiple processes?
It is not necessary however your reply made me retest, and it works as it were, but it only shows that error, if, I run the program with EmbeddedGraphDatabase and put it in an 100 second sleep(so that it keeps the database open), and then I change it to EmbeddedReadOnlyGraphDatabase and run it again as second program (while first is already running as EmbeddedGraphDatabase). In this case, this second program shows that error. If I run both programs with EmbeddedReadOnlyGraphDatabase, the exact thing happens :) I guess it's the way the second program complains that the index (and/or the database, since it's in the same path) is already in use by the first program. On Thu, Jul 21, 2011 at 6:03 AM, Michael Hunger michael.hun...@neotechnology.com wrote: Probably you have to add that for the other project too ? Am 21.07.2011 um 05:57 schrieb cyuczi eekc: Thanks Michael, that is good to know... I would've tried that right now, for tests, but unfortunately I get that silly error No index provider 'lucene' found, but only when using EmbeddedReadOnlyGraphDatabase, not EmbeddedGraphDatabase. Perhaps it would be worth mentioning that in order to not get the error for EmbeddedGraphDatabase, I had to add the folder .\lucene-index\src\main\resources\ to classpath, since I am not using any .jars, instead I'm using the source files directly from github (in eclipse) regarding my topic, I am reading this currently: http://wiki.neo4j.org/content/Using_the_Neo4j_Server_with_Java but it seems a bit messy, so I will probably limit myself to using embedded database for now :) On Thu, Jul 21, 2011 at 5:44 AM, Michael Hunger michael.hun...@neotechnology.com wrote: If you want to have a read-only-snapshot view of the database you can also use new EmbeddedReadOnlyGraphDatabase(path); Cheers Michael Am 21.07.2011 um 05:31 schrieb Jim Webber: Hi Cyuczi, You can't open the same database twice in two programs. If you want data to be replicated between Neo4j instances, look into HA: http://docs.neo4j.org/chunked/stable/ha-how.html http://wiki.neo4j.org/content/High_Availability_Cluster Jim ___ Neo4j mailing list User@lists.neo4j.org https://lists.neo4j.org/mailman/listinfo/user ___ Neo4j mailing list User@lists.neo4j.org https://lists.neo4j.org/mailman/listinfo/user ___ Neo4j mailing list User@lists.neo4j.org https://lists.neo4j.org/mailman/listinfo/user ___ Neo4j mailing list User@lists.neo4j.org https://lists.neo4j.org/mailman/listinfo/user ___ Neo4j mailing list User@lists.neo4j.org https://lists.neo4j.org/mailman/listinfo/user
Re: [Neo4j] No index provider 'lucene' found
Summary: it works if you set \lucene-index\src\main\resources as source folder (no need to set it as class folder) -- yes, if I add it as source folder instead of add it as class folder let's see, reproducing... wow, it is working now, how odd... (so adding it as source folder works) well as I remember it, as soon as I added it as a source folder, tried to run the org.neo4j.examples.CalculateShortestPath and I would get an eclipse message saying something about Java Exception (nothing specific) pressed ok, and in console I would get exceptions related to no class def found error (I don't remember the exact stuff, since I didn't bother), but after removing the folder from source folder and running the example again worked (with the lucene error though)... I would be really curious as to why that happened but looks like slim chances for me to be able to reproduce that In all regards, since then I have updated from github, and as I see it, removing the source folder still causes this to work, ie. not getting that error anymore, ok this is odder but maybe something got fixed on github :) hmm, looks like the folder contents (starting with META-INF) were already in bin, hence why it works I don't yet know how it got there... Ok, deleted it and cleaned project, got rebuilt, and it wasn't auto-created, so far so good, the error is there Trying to add the folder as source folder, that works, it auto-created its contents in bin now cleaning the project will auto create that folder's contents in bin, so no more lucene error So in other words, it works as Peter and you said, adding .\lucene-index\src\main\resources as source folder works, fixes that error. So there is no need to add it as class folder as I did, though I do wish I know why it didn't work then (with those eclipse errors) Either way, I am using: Eclipse SDK Version: 4.1.0 Build id: M20110713-2200 Thanks Michael and Peter! Hmm, considering the above, and looking in the big .bak_0.log on the workspace the reason why I got the eclipse exception and no class def found errors was most likely because I already had the bin\META-INF folder and its contents (manually added by me from before) before I set that folder as source folder, so since build wants to copy/create it there, it failed, hence it didn't compile anything or so... great now we know (or if it wasn't clear enough for you, then it's now *I* know ) :) !MESSAGE JavaBuilder handling ImageBuilderInternalException while building: neo4j-community !MESSAGE Resource already exists on disk: '/neo4j-community/bin/META-INF/services/org.neo4j.graphdb.index.IndexProvider' On Thu, Jul 21, 2011 at 6:04 AM, Michael Hunger michael.hun...@neotechnology.com wrote: Anyway as Peter said it should work to add the .\lucene-index\src\main\resources as source path to your eclipse project. You said you were getting exceptions with eclipse. What kind of exceptions are those? Michael Am 20.07.2011 um 20:25 schrieb Peter Neubauer: Hehe, On Wed, Jul 20, 2011 at 8:22 PM, cyuczi eekc cyuczie...@gmail.com wrote: PS: you mispelled programmatic =)) (I'm actually laughing with you, not at you xD) As I am a Gmail fanboy, I blame Google for not introducing a Do not send if misspelled button. The Undo send I use in around 60% of my mails. So deem for yourself would this mail _could_ have been like ;) /peter ___ Neo4j mailing list User@lists.neo4j.org https://lists.neo4j.org/mailman/listinfo/user ___ Neo4j mailing list User@lists.neo4j.org https://lists.neo4j.org/mailman/listinfo/user ___ Neo4j mailing list User@lists.neo4j.org https://lists.neo4j.org/mailman/listinfo/user
Re: [Neo4j] embedded database means it cannot be simultaneously used by multiple processes?
Yeah sorry about that :) Bottom line is, EmbeddedReadOnlyGraphDb works. It only displays the `lucene index not found error` when the database(path) is already in use by another program. Otherwise it just works. I should've said this, it's simpler to understand. To answer your question, I was trying to see if it worked to use the same database(path) when using EmbeddedReadOnlyGraphDb, while I understood it doesn't work when using EmbeddedGraphDatabase. Result: it doesn't work. But the noticed difference is, when using EmbeddedGraphDatabase the exception is this: Exception in thread main org.neo4j.graphdb.TransactionFailureException: Could not create data source [nioneodb], see nested exception for cause of error at org.neo4j.kernel.impl.transaction.TxModule.registerDataSource(TxModule.java:153) at org.neo4j.kernel.GraphDbInstance.start(GraphDbInstance.java:111) at org.neo4j.kernel.EmbeddedGraphDbImpl.init(EmbeddedGraphDbImpl.java:189) at org.neo4j.kernel.EmbeddedGraphDatabase.init(EmbeddedGraphDatabase.java:86) at org.neo4j.kernel.EmbeddedGraphDatabase.init(EmbeddedGraphDatabase.java:63) at org.neo4j.examples.CalculateShortestPath.main(CalculateShortestPath.java:53) Caused by: java.lang.IllegalStateException: Unable to lock store [neo4j-shortest-path\neostore], this is usually a result of some other Neo4j kernel running usi ng the same store. at org.neo4j.kernel.impl.nioneo.store.CommonAbstractStore.checkStorage(CommonAbstractStore.java:266) at org.neo4j.kernel.impl.nioneo.store.CommonAbstractStore.init(CommonAbstractStore.java:169) at org.neo4j.kernel.impl.nioneo.store.AbstractStore.init(AbstractStore.java:120) at org.neo4j.kernel.impl.nioneo.store.NeoStore.init(NeoStore.java:65) at org.neo4j.kernel.impl.nioneo.xa.NeoStoreXaDataSource.init(NeoStoreXaDataSource.java:134) at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) at java.lang.reflect.Constructor.newInstance(Constructor.java:525) at org.neo4j.kernel.impl.transaction.XaDataSourceManager.create(XaDataSourceManager.java:76) at org.neo4j.kernel.impl.transaction.TxModule.registerDataSource(TxModule.java:147) ... 5 more but when using EmbeddedReadOnlyGraphDatabase, the exception is this instead: Exception in thread main java.lang.IllegalArgumentException: No index provider 'lucene' found at org.neo4j.kernel.IndexManagerImpl.getIndexProvider(IndexManagerImpl.java:76) at org.neo4j.kernel.IndexManagerImpl.getOrCreateNodeIndex(IndexManagerImpl.java:269) at org.neo4j.kernel.IndexManagerImpl.forNodes(IndexManagerImpl.java:255) at org.neo4j.kernel.IndexManagerImpl.forNodes(IndexManagerImpl.java:249) at org.neo4j.examples.CalculateShortestPath.main(CalculateShortestPath.java:54) that is what I was attempting to say in the previous xD Regards ;) On Thu, Jul 21, 2011 at 6:16 AM, Michael Hunger michael.hun...@neotechnology.com wrote: If you run into errors, please make sure to include the exceptions in the e-mail. Verbal descriptions are sometimes hard to follow without having the code and the environment. You mean you take the same program and exchange the code line to use EmbeddedReadOnlyGraphDb ? Why do you do that? Why don't you create a second program that uses EmbeddedReadOnlyGraphDb, you can't do modifying operations anyway. Cheers Michael Am 21.07.2011 um 06:12 schrieb cyuczi eekc: It is not necessary however your reply made me retest, and it works as it were, but it only shows that error, if, I run the program with EmbeddedGraphDatabase and put it in an 100 second sleep(so that it keeps the database open), and then I change it to EmbeddedReadOnlyGraphDatabase and run it again as second program (while first is already running as EmbeddedGraphDatabase). In this case, this second program shows that error. If I run both programs with EmbeddedReadOnlyGraphDatabase, the exact thing happens :) I guess it's the way the second program complains that the index (and/or the database, since it's in the same path) is already in use by the first program. On Thu, Jul 21, 2011 at 6:03 AM, Michael Hunger michael.hun...@neotechnology.com wrote: Probably you have to add that for the other project too ? Am 21.07.2011 um 05:57 schrieb cyuczi eekc: Thanks Michael, that is good to know... I would've tried that right now, for tests, but unfortunately I get that silly error No index provider 'lucene' found, but only when using EmbeddedReadOnlyGraphDatabase, not EmbeddedGraphDatabase. Perhaps it would be worth mentioning that in order to not get the error for EmbeddedGraphDatabase, I had to add the folder .\lucene-index\src\main\resources\ to classpath, since I am not using any .jars
Re: [Neo4j] embedded database means it cannot be simultaneously used by multiple processes?
now looking back at HA, I see here: Porting your application to run on Neo4j-HA As mentioned earlier the only thing that needs to change is the creation of the graph database service. In single machine operations the EmbeddedGraphDatabase class should be used while in multi machine HA environment the HighlyAvailableGraphDatabase class should be used. Depending on application type this either means modifying the code or the configuration of the container running the application. so it looks like, HA is better than using neo4j server then , but I thought they were both using the same way to access data, via URI and weird messy stuff :) I'll then begin reading, many thanks Jim! On Thu, Jul 21, 2011 at 6:45 AM, cyuczi eekc cyuczie...@gmail.com wrote: Yeah sorry about that :) Bottom line is, EmbeddedReadOnlyGraphDb works. It only displays the `lucene index not found error` when the database(path) is already in use by another program. Otherwise it just works. I should've said this, it's simpler to understand. To answer your question, I was trying to see if it worked to use the same database(path) when using EmbeddedReadOnlyGraphDb, while I understood it doesn't work when using EmbeddedGraphDatabase. Result: it doesn't work. But the noticed difference is, when using EmbeddedGraphDatabase the exception is this: Exception in thread main org.neo4j.graphdb.TransactionFailureException: Could not create data source [nioneodb], see nested exception for cause of error at org.neo4j.kernel.impl.transaction.TxModule.registerDataSource(TxModule.java:153) at org.neo4j.kernel.GraphDbInstance.start(GraphDbInstance.java:111) at org.neo4j.kernel.EmbeddedGraphDbImpl.init(EmbeddedGraphDbImpl.java:189) at org.neo4j.kernel.EmbeddedGraphDatabase.init(EmbeddedGraphDatabase.java:86) at org.neo4j.kernel.EmbeddedGraphDatabase.init(EmbeddedGraphDatabase.java:63) at org.neo4j.examples.CalculateShortestPath.main(CalculateShortestPath.java:53) Caused by: java.lang.IllegalStateException: Unable to lock store [neo4j-shortest-path\neostore], this is usually a result of some other Neo4j kernel running usi ng the same store. at org.neo4j.kernel.impl.nioneo.store.CommonAbstractStore.checkStorage(CommonAbstractStore.java:266) at org.neo4j.kernel.impl.nioneo.store.CommonAbstractStore.init(CommonAbstractStore.java:169) at org.neo4j.kernel.impl.nioneo.store.AbstractStore.init(AbstractStore.java:120) at org.neo4j.kernel.impl.nioneo.store.NeoStore.init(NeoStore.java:65) at org.neo4j.kernel.impl.nioneo.xa.NeoStoreXaDataSource.init(NeoStoreXaDataSource.java:134) at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) at java.lang.reflect.Constructor.newInstance(Constructor.java:525) at org.neo4j.kernel.impl.transaction.XaDataSourceManager.create(XaDataSourceManager.java:76) at org.neo4j.kernel.impl.transaction.TxModule.registerDataSource(TxModule.java:147) ... 5 more but when using EmbeddedReadOnlyGraphDatabase, the exception is this instead: Exception in thread main java.lang.IllegalArgumentException: No index provider 'lucene' found at org.neo4j.kernel.IndexManagerImpl.getIndexProvider(IndexManagerImpl.java:76) at org.neo4j.kernel.IndexManagerImpl.getOrCreateNodeIndex(IndexManagerImpl.java:269) at org.neo4j.kernel.IndexManagerImpl.forNodes(IndexManagerImpl.java:255) at org.neo4j.kernel.IndexManagerImpl.forNodes(IndexManagerImpl.java:249) at org.neo4j.examples.CalculateShortestPath.main(CalculateShortestPath.java:54) that is what I was attempting to say in the previous xD Regards ;) On Thu, Jul 21, 2011 at 6:16 AM, Michael Hunger michael.hun...@neotechnology.com wrote: If you run into errors, please make sure to include the exceptions in the e-mail. Verbal descriptions are sometimes hard to follow without having the code and the environment. You mean you take the same program and exchange the code line to use EmbeddedReadOnlyGraphDb ? Why do you do that? Why don't you create a second program that uses EmbeddedReadOnlyGraphDb, you can't do modifying operations anyway. Cheers Michael Am 21.07.2011 um 06:12 schrieb cyuczi eekc: It is not necessary however your reply made me retest, and it works as it were, but it only shows that error, if, I run the program with EmbeddedGraphDatabase and put it in an 100 second sleep(so that it keeps the database open), and then I change it to EmbeddedReadOnlyGraphDatabase and run it again as second program (while first is already running as EmbeddedGraphDatabase). In this case, this second program shows that error. If I run both programs with EmbeddedReadOnlyGraphDatabase, the exact thing happens
Re: [Neo4j] how many relationships?
about this, should I create an issue? On Thu, Jul 21, 2011 at 5:15 AM, cyuczi eekc cyuczie...@gmail.com wrote: Ok there, I found out something new, if I do the count outside of the transaction (ie. after tx.finish() ) then it works right, ie. in a different example: Node `one` has 100,100 out rels, time=7,954,653,001 tx.finish() time=1,525,669,261 Node `one` has 1,200,546 out rels And as long as I create relationships inside the transaction, it will always show me(when I count) the number of added relationships + 100, even if on previous program run I had a transaction with more added relationships (ie. 200,000 as opposed to 100,000 now = shows 100,100) ok, here's the latest sample program: with this output ie. Node `one` has 99,100 out rels, time=9,265,459,688 tx.finish() time=1,221,787,378 counting outside of transaction... Node `one` has 1,399,546 out rels, time=353,716,303 /** * Licensed to Neo Technology under one or more contributor * license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright * ownership. Neo Technology licenses this file to you under * the Apache License, Version 2.0 (the License); you may * not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * AS IS BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ package org.neo4j.examples; import java.io.*; import java.text.*; import org.neo4j.graphdb.*; import org.neo4j.graphdb.index.*; import org.neo4j.kernel.*; public class CalculateShortestPath { private static final int SHOWINFO_IF_COUNTING_REL_TOOK_MORE_THAN_ns= 2 * 300; private static final int SHOWINFO_IF_REL_TOOK_MORE_THAN_ns= 3; private static final intSHOWEVERY_xTH_REL = 1; private static final intHOWMANY_RELATIONSHIPS = 99000; private static final StringDB_PATH = neo4j-shortest-path; private static final StringNAME_KEY = name; private static RelationshipTypeKNOWS = DynamicRelationshipType .withName( KNOWS ); private static GraphDatabaseServicegraphDb; private static IndexNodeindexService; private static DecimalFormatcommaDelimitedFormatter = new DecimalFormat( ###,### ); public static String number( double val ) { return commaDelimitedFormatter.format( val ); } public static void main( final String[] args ) { // deleteFileOrDirectory( new File( DB_PATH ) );// XXX: graphDb = new EmbeddedGraphDatabase( DB_PATH ); indexService = graphDb.index().forNodes( nodes ); registerShutdownHook(); Transaction tx = graphDb.beginTx(); Node one = getOrCreateNode( one ); DynamicRelationshipType moo = DynamicRelationshipType.withName( moo ); try { for ( int i = 1; i = HOWMANY_RELATIONSHIPS; i++ ) { long start = System.nanoTime(); Relationship rel = one.createRelationshipTo( graphDb.createNode(), moo ); // rel.setProperty( relname, i ); long end = System.nanoTime(); if ( ( i % SHOWEVERY_xTH_REL == 0 ) || ( end - start SHOWINFO_IF_REL_TOOK_MORE_THAN_ns ) ) { System.out.println( number( i ) + timeDelta= + number( end - start ) ); } } System.out.println( counting... ); long start = System.nanoTime(); IterableRelationship rel = one.getRelationships( Direction.OUTGOING, moo ); long count = 0; long tstart = 0; for ( Relationship relationship : rel ) { long tend = System.nanoTime(); count++; if ( ( tend - tstart SHOWINFO_IF_COUNTING_REL_TOOK_MORE_THAN_ns ) ) { System.out.println( number( count ) + timeDelta= + number( tend - tstart ) ); } tstart = System.nanoTime(); } long end = System.nanoTime(); System.out.println( Node ` + one.getProperty( NAME_KEY ) + ` has + number( count ) + out rels, time= + number( end - start ) ); // /* // * (Neo) -- (Trinity) // * \ ^ // * v / // * (Morpheus) -- (Cypher) // * \ | // * v v // * (Agent Smith) // */ // createChain( Neo
Re: [Neo4j] Neo4j 1.4 / Lucene 3.1 / OSGi - No index provider 'lucene' found
I got the same error when trying to use only the source code from github in eclipse and running some neo4j example, i eventually ended up using the precompiled jars which fixed the problem(and I had them point to the source code to see the javadoc), but I would really love to use the latest sources from github, and this same error is preventing me to do so: No index provider 'lucene' found On Wed, Jul 20, 2011 at 2:50 AM, Jörg Richter j...@deepamehta.de wrote: Neo4j 1.4 / Lucene 3.1 / OSGi = java.lang.IllegalArgumentException: No index provider 'lucene' found I'm running in Felix. All Dependencies are resolved (so version 0.0.0 should not be the problem here). 1|Active |5|wrap_mvn_org.apache.lucene_lucene-core_3.1.0 (0.0.0) 13|Active |5|Neo4j - Graph Database Kernel (1.4.0) 14|Active |5|Neo4j - Lucene Index (1.4.0) I understood Neo4j expects Lucene 3.1. So I wrapped Lucene via pax runner. The latest servicemix Lucene bundle available is 3.0.3 and brings up the same Exception. With the old Index API in Neo4j 1.1 and 1.2 (IndexService) the problem never occured when running in OSGi. But always with the new service-provider based Index API of Neo4j 1.3 and 1.4 when running in OSGi. Two month ago Marco Gerber started the Thread No index provider 'lucene' found - osgi (this time still for Neo4j 1.3) and found out: On May 24, 2011, at 8:53, Marco Gerber wrote: I solved the problem after having a look on the neo4j source code. The code uses java services to load any extensions on runtime. One of them is defined in META-INF/services/org.neo4j.graphdb.index.IndexProvider which is 'org.neo4j.index.impl.lucene.LuceneIndexProvider' (in my opinion the default index provider). However, the package containing this class isn't getting exported with the bundle. So, the class isn't visibible at runtime and no lucene index provider is getting loaded. His solution (tweaking the MANIFEST of the neo4j-lucene-index jar) is no durable solution and Peter Neubauer's approach (moving the LuceneIndexProvider into the public space, where it is now in Neo4j 1.4) looks like a good one but apparently did not solve the problem. I would really love to use Neo4j 1.4 with Lucene indexing while running in OSGi. Cheers, Jörg ___ Neo4j mailing list User@lists.neo4j.org https://lists.neo4j.org/mailman/listinfo/user ___ Neo4j mailing list User@lists.neo4j.org https://lists.neo4j.org/mailman/listinfo/user