You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@jackrabbit.apache.org by sowmi <so...@telenav.com> on 2006/07/27 00:04:36 UTC

java.lang.IllegalStateException: workspace 'default' not initialized

I am getting this error when I perform a multi-threaded search. I am creating
a session object for each thread that I run. Any help appreciated.

java.lang.IllegalStateException: workspace 'default' not initialized
 at
org.apache.jackrabbit.core.RepositoryImpl$WorkspaceInfo.getSearchManager(RepositoryImpl.java:1477
 at
org.apache.jackrabbit.core.RepositoryImpl.getSearchManager(RepositoryImpl.java:740)
-- 
View this message in context: http://www.nabble.com/java.lang.IllegalStateException%3A-workspace-%27default%27-not-initialized-tf2006499.html#a5511967
Sent from the Jackrabbit - Users forum at Nabble.com.


Re: java.lang.IllegalStateException: workspace 'default' not initialized

Posted by Tobias Bocanegra <to...@day.com>.
it looks like it should work. although there is some thread-local magic.
can you try to create the 5 sessions beforehand, and pass them to the
tests, instaed of creating them on the fly?

regards, toby

On 7/27/06, sowmi <so...@telenav.com> wrote:
>
> fuzzySearch() looks like this:
>
> Session session = SessionManager.getInstance().getSession();
> List list = RepositorySearch.search(session, query, maxItems);
>
> I have a singleton of SessionManager that instantiates the
> TransientRepository
>
> public static synchronized SessionManager getInstance() {
>                 if (sessMgr == null) {
>                         sessMgr = new SessionManager();
>                 }
>                 return sessMgr;
>         }
> private SessionManager() {
>                 try {
>                         repository = new TransientRepository();
>                 } catch (IOException ex) {
>                         log.error("Unable to open the repository.", ex);
>                 }
>         }
>
> Will this still cause a problem?
> --
> View this message in context: http://www.nabble.com/java.lang.IllegalStateException%3A-workspace-%27default%27-not-initialized-tf2006499.html#a5526727
> Sent from the Jackrabbit - Users forum at Nabble.com.
>
>


-- 
-----------------------------------------< tobias.bocanegra@day.com >---
Tobias Bocanegra, Day Management AG, Barfuesserplatz 6, CH - 4001 Basel
T +41 61 226 98 98, F +41 61 226 98 97
-----------------------------------------------< http://www.day.com >---

Re: java.lang.IllegalStateException: workspace 'default' not initialized

Posted by sowmi <so...@telenav.com>.
fuzzySearch() looks like this:

Session session = SessionManager.getInstance().getSession();
List list = RepositorySearch.search(session, query, maxItems);

I have a singleton of SessionManager that instantiates the
TransientRepository

public static synchronized SessionManager getInstance() {
		if (sessMgr == null) {
			sessMgr = new SessionManager();
		}
		return sessMgr;
	}
private SessionManager() {
		try {
			repository = new TransientRepository();
		} catch (IOException ex) {
			log.error("Unable to open the repository.", ex);
		}
	}

Will this still cause a problem?
-- 
View this message in context: http://www.nabble.com/java.lang.IllegalStateException%3A-workspace-%27default%27-not-initialized-tf2006499.html#a5526727
Sent from the Jackrabbit - Users forum at Nabble.com.


Re: java.lang.IllegalStateException: workspace 'default' not initialized

Posted by Tobias Bocanegra <to...@day.com>.
> Here's the log and the code below that.
and what does

ContentSearch search = new ContentSearch(null);
List list = search.fuzzySearch("test search");

exactly do?

> Looks like "Thread-0" dies after the
> exception is thrown while all other threads continue. Even though I see the
> "Repository was not shut down properly" warning, this does not seem to be
> the reason, as sometimes the execution is fine even after the warning.

how do you start and connect to the repository? i suspect, that you
create a repository for every thread, which results in concurrent open
repositories that would explain this behaviour. you only need to
create the repository once, and give each thread it's one repository
session.

regards, toby


-- 
-----------------------------------------< tobias.bocanegra@day.com >---
Tobias Bocanegra, Day Management AG, Barfuesserplatz 6, CH - 4001 Basel
T +41 61 226 98 98, F +41 61 226 98 97
-----------------------------------------------< http://www.day.com >---

Re: java.lang.IllegalStateException: workspace 'default' not initialized

Posted by sowmi <so...@telenav.com>.
Here's the log and the code below that. Looks like "Thread-0" dies after the
exception is thrown while all other threads continue. Even though I see the
"Repository was not shut down properly" warning, this does not seem to be
the reason, as sometimes the execution is fine even after the warning. The
thread in question, seems to be able to retrieve the session ok, but its the
getSearchManager() call that fails.




[2006-07-27 10:04:07,846](Thread-4-iter0-ContentSearch.java) Location not
provided for search!!
[2006-07-27 10:04:07,847](Thread-1-iter0-ContentSearch.java) Location not
provided for search!!
[2006-07-27 10:04:07,847](Thread-2-iter0-ContentSearch.java) Location not
provided for search!!
[2006-07-27 10:04:07,847](Thread-0-iter0-ContentSearch.java) Location not
provided for search!!
[2006-07-27 10:04:07,846](Thread-3-iter0-ContentSearch.java) Location not
provided for search!!
[2006-07-27 10:04:07,860](Thread-0-iter0-QueryFormatter.java) No location
constraints specified.
[2006-07-27 10:04:07,860](Thread-1-iter0-QueryFormatter.java) No location
constraints specified.
[2006-07-27 10:04:07,860](Thread-4-iter0-QueryFormatter.java) No location
constraints specified.
[2006-07-27 10:04:07,860](Thread-2-iter0-QueryFormatter.java) No location
constraints specified.
[2006-07-27 10:04:07,860](Thread-3-iter0-QueryFormatter.java) No location
constraints specified.
[2006-07-27 10:04:08,282](Thread-0-iter0-RepositoryImpl.java) Existing lock
file at /home/contentuser/mgmt/repository/.lock deteteced. Repository was
not shut down properly.
[2006-07-27 10:04:09,529](Thread-0-iter0-SessionManager.java)
Thread-0-iter0:Created new session:true
[2006-07-27 10:04:09,530](Thread-0-iter0-SessionManager.java) Getting
session took: 1603 ms.
[2006-07-27 10:04:09,530](Thread-2-iter0-SessionManager.java)
Thread-2-iter0:Created new session:true
java.lang.IllegalStateException: workspace 'default' not initialized
        at
org.apache.jackrabbit.core.RepositoryImpl$WorkspaceInfo.getSearchManager(RepositoryImpl.java:1477)
        at
org.apache.jackrabbit.core.RepositoryImpl.getSearchManager(RepositoryImpl.java:740)
        at
org.apache.jackrabbit.core.WorkspaceImpl.getQueryManager(WorkspaceImpl.java:566)
        at
com.telenav.contentEngine.jackrabbit.prototype.search.RepositorySearch.performSearch(RepositorySearch.java:105)
        at
com.telenav.contentEngine.jackrabbit.prototype.search.RepositorySearch.search(RepositorySearch.java:76)
[2006-07-27 10:04:09,531](Thread-2-iter0-SessionManager.java) Getting
session took: 1604 ms.
        at
com.telenav.contentEngine.jackrabbit.prototype.search.RepositorySearch.search(RepositorySearch.java:63)
[2006-07-27 10:04:09,531](Thread-4-iter0-SessionManager.java)
Thread-4-iter0:Created new session:true
        at
com.telenav.contentEngine.client.ContentSearch.fuzzySearch(ContentSearch.java:117)
        at
MultiThreadedTest$RunnerThread.testAirportSearch(MultiThreadedTest.java:64)
        at MultiThreadedTest$RunnerThread.run(MultiThreadedTest.java:55)
[2006-07-27 10:04:09,532](Thread-4-iter0-SessionManager.java) Getting
session took: 1605 ms.
[2006-07-27 10:04:09,532](Thread-3-iter0-SessionManager.java)
Thread-3-iter0:Created new session:true
[2006-07-27 10:04:09,531](Thread-1-iter0-SessionManager.java)
Thread-1-iter0:Created new session:true
[2006-07-27 10:04:09,537](Thread-1-iter0-SessionManager.java) Getting
session took: 1610 ms.
[2006-07-27 10:04:09,537](Thread-3-iter0-SessionManager.java) Getting
session took: 1610 ms.
[2006-07-27 10:04:10,906](Thread-3-iter0-TNSearchIndex.java) Lucene Search
took: 1008 ms.
[2006-07-27 10:04:10,906](Thread-1-iter0-TNSearchIndex.java) Lucene Search
took: 1008 ms.
[2006-07-27 10:04:10,907](Thread-4-iter0-TNSearchIndex.java) Lucene Search
took: 1009 ms.
[2006-07-27 10:04:10,906](Thread-2-iter0-TNSearchIndex.java) Lucene Search
took: 1008 ms.




public class MultiThreadedTest {

        private int numThreads;
        private int numIterations;

        private List results;

        public MultiThreadedTest(int numThreads, int numIterations) {
                this.numThreads = numThreads;
                this.numIterations = numIterations;
                this.results = new ArrayList(numThreads);
        }

        public void run() {
                for (int i = 0; i < numThreads; i++) {
                        RunnerThread newThread = new
RunnerThread(numIterations);
                        newThread.start();
                }
        }

        static class RunnerThread extends Thread {
                private long time;
                private int numIterations;

                public RunnerThread(int num) {
                        this.numIterations = num;
                }

                public void run() {
                        String name = getName();
                        for (int i = 0; i < numIterations; i++) {
                                Thread.currentThread().setName(name +
"-iter" + i);
                                performSearch();
                        }
                }

                public void performSearch() {
                	// Each thread has a separate session object.
                	// Internally ContentSearch retrieves a session object in
the 
                	// ThreadLocal for this thread, and does the search getting
                	// the QueryManager from the workspace of the session.
                        ContentSearch search = new ContentSearch(null);
                        time = System.currentTimeMillis();
                        List list = search.fuzzySearch("test search");
                        Utils.print(list);
                        time = System.currentTimeMillis() - time;
                        System.out.println("[" +
Thread.currentThread().getName() + "]Time taken:  " + time);
                }
        }

        public static void main(String[] args) throws Exception {
        	// Opening 5 threads, 2 iterations each.
                MultiThreadedTest test = new MultiThreadedTest(5, 2);
                test.run();
        }
}
-- 
View this message in context: http://www.nabble.com/java.lang.IllegalStateException%3A-workspace-%27default%27-not-initialized-tf2006499.html#a5525269
Sent from the Jackrabbit - Users forum at Nabble.com.


Re: java.lang.IllegalStateException: workspace 'default' not initialized

Posted by Tobias Bocanegra <to...@day.com>.
can you provide a testcase or code snippet that shows this behaviour?
regards, toby

On 7/27/06, sowmi <so...@telenav.com> wrote:
>
> Yes, the workspace exists. In fact, if I run 5 threads, sometimes 3 of them
> work fine, but 2 of them throw the Exception. Looks like the error is
> generated by JR code that checks for workspace initialization, but I am not
> able to put a finger on how exactly this happens.
> --
> View this message in context: http://www.nabble.com/java.lang.IllegalStateException%3A-workspace-%27default%27-not-initialized-tf2006499.html#a5513356
> Sent from the Jackrabbit - Users forum at Nabble.com.
>
>


-- 
-----------------------------------------< tobias.bocanegra@day.com >---
Tobias Bocanegra, Day Management AG, Barfuesserplatz 6, CH - 4001 Basel
T +41 61 226 98 98, F +41 61 226 98 97
-----------------------------------------------< http://www.day.com >---

Re: java.lang.IllegalStateException: workspace 'default' not initialized

Posted by sowmi <so...@telenav.com>.
Yes, the workspace exists. In fact, if I run 5 threads, sometimes 3 of them
work fine, but 2 of them throw the Exception. Looks like the error is
generated by JR code that checks for workspace initialization, but I am not
able to put a finger on how exactly this happens. 
-- 
View this message in context: http://www.nabble.com/java.lang.IllegalStateException%3A-workspace-%27default%27-not-initialized-tf2006499.html#a5513356
Sent from the Jackrabbit - Users forum at Nabble.com.


Re: java.lang.IllegalStateException: workspace 'default' not initialized

Posted by Nicolas <nt...@gmail.com>.
Hi,

Do you see in the filesystem the default workspace?

Nico

On 7/27/06, sowmi <so...@telenav.com> wrote:
>
>
> I am getting this error when I perform a multi-threaded search. I am
> creating
> a session object for each thread that I run. Any help appreciated.
>
> java.lang.IllegalStateException: workspace 'default' not initialized
> at
> org.apache.jackrabbit.core.RepositoryImpl$WorkspaceInfo.getSearchManager(
> RepositoryImpl.java:1477
> at
> org.apache.jackrabbit.core.RepositoryImpl.getSearchManager(
> RepositoryImpl.java:740)
> --
> View this message in context:
> http://www.nabble.com/java.lang.IllegalStateException%3A-workspace-%27default%27-not-initialized-tf2006499.html#a5511967
> Sent from the Jackrabbit - Users forum at Nabble.com.
>
>


-- 
a+
Nico
my blog! http://www.deviant-abstraction.net !!