You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jackrabbit.apache.org by mr...@apache.org on 2009/04/03 14:00:36 UTC
svn commit: r761634 - in /jackrabbit/trunk/jackrabbit-core/src:
main/java/org/apache/jackrabbit/core/
test/java/org/apache/jackrabbit/core/integration/
test/java/org/apache/jackrabbit/core/query/lucene/ test/repository/
test/repository/workspaces/works...
Author: mreutegg
Date: Fri Apr 3 12:00:35 2009
New Revision: 761634
URL: http://svn.apache.org/viewvc?rev=761634&view=rev
Log:
JCR-2048: Workspace is shut down while creating initial index
Added:
jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/integration/WorkspaceInitTest.java (with props)
jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/lucene/SlowQueryHandler.java (with props)
jackrabbit/trunk/jackrabbit-core/src/test/repository/workspaces/workspace-init-test/
jackrabbit/trunk/jackrabbit-core/src/test/repository/workspaces/workspace-init-test/workspace.xml (with props)
Modified:
jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/RepositoryImpl.java
jackrabbit/trunk/jackrabbit-core/src/test/repository/repository.xml
Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/RepositoryImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/RepositoryImpl.java?rev=761634&r1=761633&r2=761634&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/RepositoryImpl.java (original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/RepositoryImpl.java Fri Apr 3 12:00:35 2009
@@ -481,7 +481,7 @@
secWspName = smc.getWorkspaceName();
}
try {
- initWorkspace((WorkspaceInfo) wspInfos.get(wspName));
+ ((WorkspaceInfo) wspInfos.get(wspName)).initialize();
if (secWspName != null && !wspInfos.containsKey(secWspName)) {
createWorkspace(secWspName);
log.info("created system workspace: {}", secWspName);
@@ -636,48 +636,6 @@
}
}
- private void initWorkspace(WorkspaceInfo wspInfo) throws RepositoryException {
- // first initialize workspace info
- if (!wspInfo.initialize()) {
- // workspace has already been initialized, we're done
- return;
- }
-
- // get system session and Workspace instance
- SessionImpl sysSession = wspInfo.getSystemSession();
- WorkspaceImpl wsp = (WorkspaceImpl) sysSession.getWorkspace();
-
- /**
- * todo implement 'System' workspace
- * FIXME
- * - there should be one 'System' workspace per repository
- * - the 'System' workspace should have the /jcr:system node
- * - versions, version history and node types should be reflected in
- * this system workspace as content under /jcr:system
- * - all other workspaces should be dynamic workspaces based on
- * this 'read-only' system workspace
- *
- * for now, the jcr:system node is created in
- * {@link org.apache.jackrabbit.core.state.SharedItemStateManager#createRootNodeState}
- */
-
- // register the repository as event listener for keeping repository statistics
- wsp.getObservationManager().addEventListener(this,
- Event.NODE_ADDED | Event.NODE_REMOVED
- | Event.PROPERTY_ADDED | Event.PROPERTY_REMOVED,
- "/", true, null, null, false);
-
- // register SearchManager as event listener
- SearchManager searchMgr = wspInfo.getSearchManager();
- if (searchMgr != null) {
- wsp.getObservationManager().addEventListener(searchMgr,
- Event.NODE_ADDED | Event.NODE_REMOVED
- | Event.PROPERTY_ADDED | Event.PROPERTY_REMOVED
- | Event.PROPERTY_CHANGED,
- "/", true, null, null, false);
- }
- }
-
/**
* Returns the system search manager or <code>null</code> if none is
* configured.
@@ -769,7 +727,7 @@
}
try {
- initWorkspace(wspInfo);
+ wspInfo.initialize();
} catch (RepositoryException e) {
log.error("Unable to initialize workspace '" + workspaceName + "'", e);
throw new NoSuchWorkspaceException(workspaceName);
@@ -1929,6 +1887,7 @@
log.info("initializing workspace '" + getName() + "'...");
doInitialize();
initialized = true;
+ doPostInitialize();
log.info("workspace '" + getName() + "' initialized");
return true;
} finally {
@@ -1983,6 +1942,49 @@
}
/**
+ * Initializes the search manager of this workspace info. This method
+ * is called while still holding the write lock on this workspace
+ * info, but {@link #initialized} is already set to <code>true</code>.
+ *
+ * @throws RepositoryException if the search manager could not be created
+ */
+ protected void doPostInitialize()
+ throws RepositoryException {
+ // get system Workspace instance
+ WorkspaceImpl wsp = (WorkspaceImpl) getSystemSession().getWorkspace();
+
+ /**
+ * todo implement 'System' workspace
+ * FIXME
+ * - there should be one 'System' workspace per repository
+ * - the 'System' workspace should have the /jcr:system node
+ * - versions, version history and node types should be reflected in
+ * this system workspace as content under /jcr:system
+ * - all other workspaces should be dynamic workspaces based on
+ * this 'read-only' system workspace
+ *
+ * for now, the jcr:system node is created in
+ * {@link org.apache.jackrabbit.core.state.SharedItemStateManager#createRootNodeState}
+ */
+
+ // register the repository as event listener for keeping repository statistics
+ wsp.getObservationManager().addEventListener(RepositoryImpl.this,
+ Event.NODE_ADDED | Event.NODE_REMOVED
+ | Event.PROPERTY_ADDED | Event.PROPERTY_REMOVED,
+ "/", true, null, null, false);
+
+ // register SearchManager as event listener
+ SearchManager searchMgr = getSearchManager();
+ if (searchMgr != null) {
+ wsp.getObservationManager().addEventListener(searchMgr,
+ Event.NODE_ADDED | Event.NODE_REMOVED
+ | Event.PROPERTY_ADDED | Event.PROPERTY_REMOVED
+ | Event.PROPERTY_CHANGED,
+ "/", true, null, null, false);
+ }
+ }
+
+ /**
* Disposes this <code>WorkspaceInfo</code> if it has been idle for more
* than <code>maxIdleTime</code> milliseconds.
*
Added: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/integration/WorkspaceInitTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/integration/WorkspaceInitTest.java?rev=761634&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/integration/WorkspaceInitTest.java (added)
+++ jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/integration/WorkspaceInitTest.java Fri Apr 3 12:00:35 2009
@@ -0,0 +1,53 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF 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.apache.jackrabbit.core.integration;
+
+import java.util.List;
+import java.util.ArrayList;
+import java.util.Iterator;
+
+import javax.jcr.RepositoryException;
+
+import org.apache.jackrabbit.test.AbstractJCRTest;
+
+/**
+ * <code>WorkspaceInitTest</code>...
+ */
+public class WorkspaceInitTest extends AbstractJCRTest {
+
+ public void testIdleTime() throws Exception {
+ // simply access the workspace, which will cause
+ // initialization of SlowQueryHandler.
+ List threads = new ArrayList();
+ for (int i = 0; i < 10; i++) {
+ Thread t = new Thread(new Runnable() {
+ public void run() {
+ try {
+ helper.getSuperuserSession("workspace-init-test").logout();
+ } catch (RepositoryException e) {
+ throw new RuntimeException(e);
+ }
+ }
+ });
+ t.start();
+ threads.add(t);
+ }
+ for (Iterator it = threads.iterator(); it.hasNext(); ) {
+ ((Thread) it.next()).join();
+ }
+ }
+}
Propchange: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/integration/WorkspaceInitTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/lucene/SlowQueryHandler.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/lucene/SlowQueryHandler.java?rev=761634&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/lucene/SlowQueryHandler.java (added)
+++ jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/lucene/SlowQueryHandler.java Fri Apr 3 12:00:35 2009
@@ -0,0 +1,73 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF 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.apache.jackrabbit.core.query.lucene;
+
+import java.io.IOException;
+
+import javax.jcr.RepositoryException;
+import javax.jcr.query.InvalidQueryException;
+
+import org.apache.jackrabbit.core.query.AbstractQueryHandler;
+import org.apache.jackrabbit.core.query.ExecutableQuery;
+import org.apache.jackrabbit.core.state.NodeState;
+import org.apache.jackrabbit.core.NodeId;
+import org.apache.jackrabbit.core.SessionImpl;
+import org.apache.jackrabbit.core.ItemManager;
+import org.apache.jackrabbit.spi.commons.query.qom.QueryObjectModelTree;
+import org.apache.jackrabbit.uuid.UUID;
+
+/**
+ * <code>SlowQueryHandler</code> implements a dummy query handler for testing
+ * purpose.
+ */
+public class SlowQueryHandler extends AbstractQueryHandler {
+
+ protected void doInit() throws IOException {
+ // sleep for 10 seconds then try to read from the item state manager
+ // the repository.xml is configured with a 5 second maxIdleTime
+ try {
+ Thread.sleep(10 * 1000);
+ } catch (InterruptedException e) {
+ // ignore
+ }
+ NodeId id = new NodeId(UUID.randomUUID());
+ getContext().getItemStateManager().hasItemState(id);
+ }
+
+ public void addNode(NodeState node) throws RepositoryException, IOException {
+ }
+
+ public void deleteNode(NodeId id) throws IOException {
+ }
+
+ public void close() throws IOException {
+ }
+
+ public ExecutableQuery createExecutableQuery(SessionImpl session,
+ ItemManager itemMgr, String statement,
+ String language)
+ throws InvalidQueryException {
+ return null;
+ }
+
+ public ExecutableQuery createExecutableQuery(SessionImpl session,
+ ItemManager itemMgr,
+ QueryObjectModelTree qomTree)
+ throws InvalidQueryException {
+ return null;
+ }
+}
Propchange: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/lucene/SlowQueryHandler.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: jackrabbit/trunk/jackrabbit-core/src/test/repository/repository.xml
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/test/repository/repository.xml?rev=761634&r1=761633&r2=761634&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/test/repository/repository.xml (original)
+++ jackrabbit/trunk/jackrabbit-core/src/test/repository/repository.xml Fri Apr 3 12:00:35 2009
@@ -72,7 +72,7 @@
<!--
location of workspaces root directory and name of default workspace
-->
- <Workspaces rootPath="${rep.home}/workspaces" defaultWorkspace="default"/>
+ <Workspaces rootPath="${rep.home}/workspaces" defaultWorkspace="default" maxIdleTime="2"/>
<!--
workspace configuration template:
used to create the initial workspace if there's no workspace yet
Added: jackrabbit/trunk/jackrabbit-core/src/test/repository/workspaces/workspace-init-test/workspace.xml
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/test/repository/workspaces/workspace-init-test/workspace.xml?rev=761634&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/test/repository/workspaces/workspace-init-test/workspace.xml (added)
+++ jackrabbit/trunk/jackrabbit-core/src/test/repository/workspaces/workspace-init-test/workspace.xml Fri Apr 3 12:00:35 2009
@@ -0,0 +1,38 @@
+<?xml version="1.0"?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF 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.
+ -->
+<Workspace name="workspace-init-test">
+ <!--
+ virtual file system of the workspace:
+ class: FQN of class implementing FileSystem interface
+ -->
+ <FileSystem class="org.apache.jackrabbit.core.fs.local.LocalFileSystem">
+ <param name="path" value="${wsp.home}" />
+ </FileSystem>
+
+ <!--
+ persistence of the workspace:
+ class: FQN of class implementing PersistenceManager interface
+ -->
+ <PersistenceManager class="org.apache.jackrabbit.core.persistence.mem.InMemPersistenceManager"/>
+
+ <!--
+ Search index and the file system it uses.
+ -->
+ <SearchIndex class="org.apache.jackrabbit.core.query.lucene.SlowQueryHandler"/>
+</Workspace>
+
Propchange: jackrabbit/trunk/jackrabbit-core/src/test/repository/workspaces/workspace-init-test/workspace.xml
------------------------------------------------------------------------------
svn:eol-style = native