From: <tho...@us...> - 2013-09-17 14:16:33
|
Revision: 7414 http://bigdata.svn.sourceforge.net/bigdata/?rev=7414&view=rev Author: thompsonbry Date: 2013-09-17 14:16:25 +0000 (Tue, 17 Sep 2013) Log Message: ----------- Bug fix for #743 (AbstractTripleStore.destroy() does not filter for correct prefix). Modified Paths: -------------- branches/BIGDATA_RELEASE_1_3_0/bigdata/src/java/com/bigdata/journal/IIndexStore.java branches/BIGDATA_RELEASE_1_3_0/bigdata/src/java/com/bigdata/journal/Name2Addr.java branches/BIGDATA_RELEASE_1_3_0/bigdata/src/java/com/bigdata/relation/AbstractResource.java branches/BIGDATA_RELEASE_1_3_0/bigdata/src/java/com/bigdata/service/ListIndicesTask.java branches/BIGDATA_RELEASE_1_3_0/bigdata-rdf/src/test/com/bigdata/rdf/store/TestLocalTripleStoreDestroy.java Modified: branches/BIGDATA_RELEASE_1_3_0/bigdata/src/java/com/bigdata/journal/IIndexStore.java =================================================================== --- branches/BIGDATA_RELEASE_1_3_0/bigdata/src/java/com/bigdata/journal/IIndexStore.java 2013-09-13 19:35:09 UTC (rev 7413) +++ branches/BIGDATA_RELEASE_1_3_0/bigdata/src/java/com/bigdata/journal/IIndexStore.java 2013-09-17 14:16:25 UTC (rev 7414) @@ -62,7 +62,13 @@ * Iterator visits the names of all indices spanned by the given prefix. * * @param prefix - * The prefix (optional). + * The prefix (optional). When given, this MUST include a + * <code>.</code> if you want to restrict the scan to only those + * indices in a given namespace. Otherwise you can find indices + * in <code>kb2</code> if you provide the prefix <code>kb</code> + * where both kb and kb2 are namespaces since the indices spanned + * by <code>kb</code> would include both <code>kb.xyz</code> and + * <code>kb2.xyx</code>. * @param timestamp * A timestamp which represents either a possible commit time on * the store or a read-only transaction identifier. Modified: branches/BIGDATA_RELEASE_1_3_0/bigdata/src/java/com/bigdata/journal/Name2Addr.java =================================================================== --- branches/BIGDATA_RELEASE_1_3_0/bigdata/src/java/com/bigdata/journal/Name2Addr.java 2013-09-13 19:35:09 UTC (rev 7413) +++ branches/BIGDATA_RELEASE_1_3_0/bigdata/src/java/com/bigdata/journal/Name2Addr.java 2013-09-17 14:16:25 UTC (rev 7414) @@ -1600,6 +1600,14 @@ * {@link Name2Addr#getKey(String)} and * {@link Name2AddrTupleSerializer#serializeKey(Object)} * implementation (depending on how the keys are being encoded). + * <p> + * Update: See <a + * href="https://sourceforge.net/apps/trac/bigdata/ticket/743"> + * AbstractTripleStore.destroy() does not filter for correct prefix + * </a> as well. Maybe the problem is just that we need to have the + * "." appended to the namespace. This could be something that is + * done automatically if the caller does not take care of it + * themselves. */ public static final Iterator<String> indexNameScan(final String prefix, final IIndex n2a) { Modified: branches/BIGDATA_RELEASE_1_3_0/bigdata/src/java/com/bigdata/relation/AbstractResource.java =================================================================== --- branches/BIGDATA_RELEASE_1_3_0/bigdata/src/java/com/bigdata/relation/AbstractResource.java 2013-09-13 19:35:09 UTC (rev 7413) +++ branches/BIGDATA_RELEASE_1_3_0/bigdata/src/java/com/bigdata/relation/AbstractResource.java 2013-09-17 14:16:25 UTC (rev 7414) @@ -694,8 +694,8 @@ */ { - final Iterator<String> itr = indexManager.indexNameScan(namespace, - timestamp); + final Iterator<String> itr = indexManager.indexNameScan(namespace + + ".", timestamp); while (itr.hasNext()) { Modified: branches/BIGDATA_RELEASE_1_3_0/bigdata/src/java/com/bigdata/service/ListIndicesTask.java =================================================================== --- branches/BIGDATA_RELEASE_1_3_0/bigdata/src/java/com/bigdata/service/ListIndicesTask.java 2013-09-13 19:35:09 UTC (rev 7413) +++ branches/BIGDATA_RELEASE_1_3_0/bigdata/src/java/com/bigdata/service/ListIndicesTask.java 2013-09-17 14:16:25 UTC (rev 7414) @@ -54,6 +54,13 @@ * @param namespace * The namespace prefix for the indices to be returned (may be an * empty string to return the names of all registered indices). + * <p> + * Note: This SHOULD include a "." if you want to restrict the + * scan to only those indices in a given namespace. Otherwise you + * can find indices in <code>kb2</code> if you provide the prefix + * <code>kb</code> and both kb and kb2 are namespaces since the + * indices spanned by <code>kb</code> would include both + * <code>kb.xyz</code> and <code>kb2.xyx</code>. */ public ListIndicesTask(final long ts, final String namespace) { Modified: branches/BIGDATA_RELEASE_1_3_0/bigdata-rdf/src/test/com/bigdata/rdf/store/TestLocalTripleStoreDestroy.java =================================================================== --- branches/BIGDATA_RELEASE_1_3_0/bigdata-rdf/src/test/com/bigdata/rdf/store/TestLocalTripleStoreDestroy.java 2013-09-13 19:35:09 UTC (rev 7413) +++ branches/BIGDATA_RELEASE_1_3_0/bigdata-rdf/src/test/com/bigdata/rdf/store/TestLocalTripleStoreDestroy.java 2013-09-17 14:16:25 UTC (rev 7414) @@ -37,6 +37,7 @@ import com.bigdata.journal.ITx; import com.bigdata.rdf.lexicon.LexiconKeyOrder; import com.bigdata.rdf.spo.SPOKeyOrder; +import com.bigdata.relation.AbstractResource; import com.bigdata.relation.RelationSchema; import com.bigdata.relation.locator.DefaultResourceLocator; import com.bigdata.sparse.ITPS; @@ -282,4 +283,227 @@ } + /** + * Verify the namespace prefix for the triple store is imposed correctly in + * {@link AbstractResource#destroy()}. Create two KBs such that the + * namespace for one instance is a prefix of the namespace for the other + * instance, e.g., + * + * <pre> + * kb + * kb1 + * </pre> + * + * Verify that destroying <code>kb</code> does not cause the indices for + * <code>kb1</code> to be destroyed. + * + * @see <a href="https://sourceforge.net/apps/trac/bigdata/ticket/743"> + * AbstractTripleStore.destroy() does not filter for correct prefix + * </a> + */ + public void test_destroyTwo() { + + final String namespace = "kb"; + final String namespaceLexiconRelation = namespace + ".lex"; + final String namespaceSPORelation = namespace + ".spo"; + final String lexiconRelationIndexName = namespaceLexiconRelation + "." + + LexiconKeyOrder.TERM2ID.getIndexName(); + final String primaryStatementIndexName = namespaceSPORelation + "." + + SPOKeyOrder.SPO.getIndexName(); + + final String namespace1 = "kb1"; + final String namespaceLexiconRelation1 = namespace1 + ".lex"; + final String namespaceSPORelation1 = namespace1 + ".spo"; + final String lexiconRelationIndexName1 = namespaceLexiconRelation1 + + "." + LexiconKeyOrder.TERM2ID.getIndexName(); + final String primaryStatementIndexName1 = namespaceSPORelation1 + "." + + SPOKeyOrder.SPO.getIndexName(); + + final Properties properties = new Properties(); + properties.setProperty(com.bigdata.journal.Options.CREATE_TEMP_FILE, "true"); + properties.setProperty(AbstractTripleStore.Options.BUFFER_MODE,BufferMode.DiskWORM.toString()); + properties.setProperty(AbstractTripleStore.Options.TRIPLES_MODE,"true"); + + final AbstractTripleStore kb = getStore(properties); + + final IIndexManager indexManager = kb.getIndexManager(); + + try { + + assertEquals(namespace, kb.getNamespace()); + + final AbstractTripleStore kb1 = new LocalTripleStore(indexManager, + namespace1, ITx.UNISOLATED, properties); + kb1.create(); + + // make the tripleStore dirty so commit() will do something. + kb.addTerm(kb.getValueFactory().createLiteral("bigdata")); + kb1.addTerm(kb.getValueFactory().createLiteral("bigdata")); + + // Verify post-conditions of the created KBs. + { + + /* + * Verify that both triple store declarations exist in the GRS. + * + * Note: Will be in lexical order for Unicode. + */ + final String[] namespaces = getNamespaces(indexManager) + .toArray(new String[] {}); + assertEquals(new String[] { namespace, namespace1 }, namespaces); + + /* + * Verify that the unislolated versions of each triple stores is + * the same reference that we obtained above when that triple + * store was created. + */ + assertTrue(kb == indexManager.getResourceLocator().locate( + kb.getNamespace(), ITx.UNISOLATED)); + assertTrue(kb1 == indexManager.getResourceLocator().locate( + kb1.getNamespace(), ITx.UNISOLATED)); + + /* Verify lexicon relations exist. */ + assertTrue(kb.getLexiconRelation() == indexManager + .getResourceLocator().locate(namespaceLexiconRelation, + ITx.UNISOLATED)); + assertTrue(kb1.getLexiconRelation() == indexManager + .getResourceLocator().locate(namespaceLexiconRelation1, + ITx.UNISOLATED)); + + /* Verify SPO relations exist. */ + assertTrue(kb.getSPORelation() == indexManager + .getResourceLocator().locate(namespaceSPORelation, + ITx.UNISOLATED)); + assertTrue(kb1.getSPORelation() == indexManager + .getResourceLocator().locate(namespaceSPORelation1, + ITx.UNISOLATED)); + + /* Verify lexicon index exists. */ + assertNotNull(indexManager.getIndex(lexiconRelationIndexName, + ITx.UNISOLATED)); + assertNotNull(indexManager.getIndex(lexiconRelationIndexName1, + ITx.UNISOLATED)); + + /* Verify primary SPO index exists. */ + assertNotNull(indexManager.getIndex(primaryStatementIndexName, + ITx.UNISOLATED)); + assertNotNull(indexManager.getIndex(primaryStatementIndexName1, + ITx.UNISOLATED)); + + } + + /* Commit. */ + final long commitTime = kb.commit(); + assertTrue(commitTime > 0); + + /* + * Destroy the triple store whose namespace is a prefix of the 2nd + * triple store namespace. + */ + { + kb.destroy(); + + // global row store entry is gone. + final String[] namespaces = getNamespaces(indexManager).toArray( + new String[] {}); + assertEquals(new String[] { namespace1 }, namespaces); + + // resources can not be located. + assertTrue(null == indexManager.getResourceLocator().locate( + namespace, ITx.UNISOLATED)); + assertTrue(null == indexManager.getResourceLocator().locate( + namespaceLexiconRelation, ITx.UNISOLATED)); + assertTrue(null == indexManager.getResourceLocator().locate( + namespaceSPORelation, ITx.UNISOLATED)); + + // indicies are gone. + assertNull(indexManager.getIndex(lexiconRelationIndexName, + ITx.UNISOLATED)); + assertNull(indexManager.getIndex(primaryStatementIndexName, + ITx.UNISOLATED)); + + // The committed version of the triple store remains visible. + assertNotNull(indexManager.getResourceLocator().locate( + namespace, commitTime - 1)); + } + + /* + * Verify that the other kb still exists, including its GRS + * declaration and its indices. + */ + { + + /* + * Verify that the triple store declaration exists in the GRS. + * + * Note: Will be in lexical order for Unicode. + */ + final String[] namespaces = getNamespaces(indexManager).toArray( + new String[] {}); + assertEquals(new String[] { namespace1 }, namespaces); + + /* + * Verify that the unislolated versions of each triple stores is the + * same reference that we obtained above when that triple store was + * created. + */ + assertTrue(kb1 == indexManager.getResourceLocator().locate( + kb1.getNamespace(), ITx.UNISOLATED)); + + /* Verify lexicon relations exist. */ + assertTrue(kb1.getLexiconRelation() == indexManager + .getResourceLocator().locate(namespaceLexiconRelation1, + ITx.UNISOLATED)); + + /* Verify SPO relations exist. */ + assertTrue(kb1.getSPORelation() == indexManager + .getResourceLocator().locate(namespaceSPORelation1, + ITx.UNISOLATED)); + + /* Verify lexicon index exists. */ + assertNotNull(indexManager.getIndex(lexiconRelationIndexName1, + ITx.UNISOLATED)); + + /* Verify primary SPO index exists. */ + assertNotNull(indexManager.getIndex(primaryStatementIndexName1, + ITx.UNISOLATED)); + + } + + /* + * Destroy the other triple store. + */ + { + kb1.destroy(); + + // global row store entry is gone. + assertTrue(getNamespaces(indexManager).isEmpty()); + + // resources can not be located. + assertTrue(null == indexManager.getResourceLocator().locate( + namespace1, ITx.UNISOLATED)); + assertTrue(null == indexManager.getResourceLocator().locate( + namespaceLexiconRelation1, ITx.UNISOLATED)); + assertTrue(null == indexManager.getResourceLocator().locate( + namespaceSPORelation1, ITx.UNISOLATED)); + + // indicies are gone. + assertNull(indexManager.getIndex(lexiconRelationIndexName1, + ITx.UNISOLATED)); + assertNull(indexManager.getIndex(primaryStatementIndexName1, + ITx.UNISOLATED)); + + // The committed version of the triple store remains visible. + assertNotNull(indexManager.getResourceLocator().locate( + namespace1, commitTime - 1)); + } + + } finally { + + indexManager.destroy(); + + } + + } + } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |