oak-osgi : org.apache.jackrabbit.oak.api.CommitFailedException: OakMerge0001

2024-02-06 Thread Sandeep Ambule
return oak.createContentRepository();
}
private static QueryIndex.NodeAggregator getNodeAggregator() {
return (QueryIndex.NodeAggregator)(new SimpleNodeAggregator())
.newRuleWithName("nt:file", Lists.newArrayList((Object[])new String[] {
"jcr:content", "jcr:content/*" }));
}

/** helper class to initialize the Property index definition */
static class *IndexInitializer* implements RepositoryInitializer {
private String indexType;
private String name;
private Set properties;

public IndexInitializer(
final String indexType, final String name, final Set properties) {
this.indexType = indexType;
this.name = checkNotNull(name);
this.properties = checkNotNull(properties);
}

private boolean isAlreadyThere(final NodeBuilder root) {
return checkNotNull(root).hasChildNode(INDEX_DEFINITIONS_NAME)
&& root.getChildNode(INDEX_DEFINITIONS_NAME).hasChildNode(name);
}

@Override
public void initialize(final NodeBuilder builder) {
if (!isAlreadyThere(builder)) {
if (indexType.equals("luceneIndex")) {
addLuceneIndex(builder, name, properties);
}

if (indexType.equals("propertyIndex")) {
addPropertyIndex(builder, name, properties);
}
}
}
} // end of helper class


// Code Retrieve DocumentNodeStore Service
private DocumentNodeStore getDocumentNodeStore() {
ServiceTracker
nodeStoreServiceTracker = null;
try {
BundleContext context =
FrameworkUtil.getBundle(DocumentNodeStore.class).getBundleContext();
nodeStoreServiceTracker =
new ServiceTracker<>(context, DocumentNodeStore.class, null) {
@Override
public DocumentNodeStore addingService(ServiceReference
reference) {
logger.info("DocumentNodeStore service reference received");
documentNodeStore = context.getService(reference);
return super.addingService(reference);
}
};
nodeStoreServiceTracker.open();
documentNodeStore =
nodeStoreServiceTracker.waitForService(SERVICE_WAIT_TIME);
if (documentNodeStore != null) {
logger.info(
"ContentManagementServiceImpl.getDocumentNodeStore-DocumentNodeStore
service"
+ " reference found");

EditorHook hook =
new EditorHook(
new CompositeEditorProvider(
new NamespaceEditorProvider(), new TypeEditorProvider()));

OakInitializer.initialize(documentNodeStore, new InitialContent(), hook);
}

} catch (InterruptedException e) {
logger.error(
"ContentManagementServiceImpl.getDocumentNodeStore- Failed to get
documentNodeStore",
e);
} finally {
nodeStoreServiceTracker.close();
}

return documentNodeStore;
}

// Repository creation code
private ContentRepository createRepository( String workspace)
throws CommitFailedException {
HashMap extraMap = new HashMap<>();
NodeStore documentNodeStoreService=getDocumentNodeStore();
IndexInitializer propertyIndexInitializer =
new *IndexInitializer*(
"propertyIndex",
"schemaPropertyIndex",
new HashSet
<>(Arrays.asList(ExperienceManagerConstant.PROPERTY_INDEX_PROPERTIES)));

String asyncIndexTime = "5";
String freeTextAsyncIndexTime = "5";

extraMap.put(OAK_ASYNC_INDEX_LANE_INTERVAL, asyncIndexTime);
extraMap.put(OAK_FULLTEXT_ASYNC_INDEX_LANE_INTERVAL,
freeTextAsyncIndexTime);

return *LuceneRepository*.createRepositoryWithLuceneIndex(
documentNodeStoreService, propertyIndexInitializer, workspace, extraMap);
}


// Code causing oakmerge issue
try {
contentSession = repositoryService.getContentSession(workSpaceName);
if (contentSession != null) {
Root rootNode = contentSession.getLatestRoot();
rootNode.rebase();
Tree contentNode =
FormDataUtil.addFileContentNode(rootNode, formDataFile, parentTreePath,
extra);
// commit node
if (contentNode != null) {
rootNode.commit();
contentId = "" + contentNode.getPath();
formDataFile.setFilepath(contentId);
}
}

} catch (CommitFailedException e) {
logger.error("Content Manager: {} Unable to create node ", methodName);
}


//Configuration PID:
org.apache.jackrabbit.oak.plugins.document.DocumentNodeStoreService file

#A path on the file system where repository data like cache will be stored
repository.home=
# Document Store type
documentStoreType=RDB
maxReplicationLagInSecs=21600
leaseCheckMode=DISABLED
#Property indicating that this component will not register as a NodeStore
but as a "NodeStoreProvider" with given role
role=
cache=512
nodeCachePercentage=35
prevDocCachePercentage=4
childrenCachePercentage=15
diffCachePercentage=30
cacheSegmentCount=16
cacheStackMoveDistance=16
blobCacheSize=16
updateLimit=10
persistentCache=cache,size\=512,+compact
persistentCacheIncludes=/
journalCache=diff-cache

journalGCInterval=30
journalGCMaxAge=8640
versionGcMaxAgeInSecs=86400
versionGCExpression= 0 0 2 * * ?
versionGCTimeLimitInSecs=10800
blobGcMaxAgeInSecs=86400
blobTrackSnapshotIntervalInSecs=43200




Thanks & Regards,
Sandeep Ambule


Re: oak-osgi : lucene searching not working

2020-03-12 Thread Sandeep Ambule
Any updates on this?

On Mon, Mar 9, 2020, 12:24 PM Sandeep Ambule  wrote:

> >So, this is not about RDB, but about using the DocumentNodeStoreService
> or not, right?
>
> Yes, This is not about RDB ,Its about using osgi service, here i am using 
> DocumentNodeStoreService.
>
> In scenario 2: i have injected datascource,and Using DocumentNodeStoreService 
> created repository .
> i can store data and create index but not able to do full text search.
>
> In scenario 1: i have created DocumentNodeStre created dataSource using 
> RDBDataSourceFactory and created DocumentNodeStore using 
> RDBDocumentNodeStoreBuilder insted of injecting osgi service.
> Using this scenario fulltext search working correctly
>
> may be i am missing something while creating repository while using osgi 
> service?
>
> but if you see my code i have used same code to create repository only 
> difference is
>
> DocumentNodeStoreService.
>
> In scenario 1 , i have provided DocumenNodeStore and In scenario 2: i have 
> provided
>
>
> On Sat, Mar 7, 2020 at 12:45 AM Julian Reschke 
> wrote:
>
>> On 06.03.2020 05:47, Sandeep Ambule wrote:
>> > *In scenario 1 *, I have created a repository using a node store created
>> > using  RDBDocumentNodeStoreBuilder
>> >
>> > public DocumentNodeStore createRDBStore(){String
>> > jdbcurl="jdbc:postgresql://127.0.0.1:5432/SP05";String
>> > user="postgres";String pw="manager";DataSource dataSource =
>> > RDBDataSourceFactory.forJdbcUrl(jdbcurl, user, pw);
>> >
>> > DocumentNodeStore store = new
>> > RDBDocumentNodeStoreBuilder().newRDBDocumentNodeStoreBuilder()
>> > .setRDBConnection(dataSource).build();
>> > return store;
>> >
>> > }
>> >
>> >
>> > *In scenario 2: i have created a repository by autowiring *NodeStore
>> > *osgi service.*
>> >
>> >
>> > *i have given both scenario 1 and scenario 2 code in previous mail.*
>>
>> Yes. But we are all volunteers here, so it's good to provide all the
>> information you have in a form that makes the question easier to
>> understand.
>>
>> > *major difference in scenario 1 and scenario 2 is , In scenario 2 i am
>> > using nodestore osgi service.*
>>
>> So, this is not about RDB, but about using the DocumentNodeStoreService
>> or not, right? If it works with the latter, it's likely it's setting up
>> in addition to what you do in scenario 1, no?
>>
>> Best regards, Julian
>>
>


Re: oak-osgi : lucene searching not working

2020-03-09 Thread Sandeep Ambule
>So, this is not about RDB, but about using the DocumentNodeStoreService
or not, right?

Yes, This is not about RDB ,Its about using osgi service, here i am
using DocumentNodeStoreService.

In scenario 2: i have injected datascource,and Using
DocumentNodeStoreService created repository .
i can store data and create index but not able to do full text search.

In scenario 1: i have created DocumentNodeStre created dataSource
using RDBDataSourceFactory and created DocumentNodeStore using
RDBDocumentNodeStoreBuilder insted of injecting osgi service.
Using this scenario fulltext search working correctly

may be i am missing something while creating repository while using
osgi service?

but if you see my code i have used same code to create repository only
difference is

DocumentNodeStoreService.

In scenario 1 , i have provided DocumenNodeStore and In scenario 2: i
have provided




On Sat, Mar 7, 2020 at 12:45 AM Julian Reschke 
wrote:

> On 06.03.2020 05:47, Sandeep Ambule wrote:
> > *In scenario 1 *, I have created a repository using a node store created
> > using  RDBDocumentNodeStoreBuilder
> >
> > public DocumentNodeStore createRDBStore(){String
> > jdbcurl="jdbc:postgresql://127.0.0.1:5432/SP05";String
> > user="postgres";String pw="manager";DataSource dataSource =
> > RDBDataSourceFactory.forJdbcUrl(jdbcurl, user, pw);
> >
> > DocumentNodeStore store = new
> > RDBDocumentNodeStoreBuilder().newRDBDocumentNodeStoreBuilder()
> > .setRDBConnection(dataSource).build();
> > return store;
> >
> > }
> >
> >
> > *In scenario 2: i have created a repository by autowiring *NodeStore
> > *osgi service.*
> >
> >
> > *i have given both scenario 1 and scenario 2 code in previous mail.*
>
> Yes. But we are all volunteers here, so it's good to provide all the
> information you have in a form that makes the question easier to
> understand.
>
> > *major difference in scenario 1 and scenario 2 is , In scenario 2 i am
> > using nodestore osgi service.*
>
> So, this is not about RDB, but about using the DocumentNodeStoreService
> or not, right? If it works with the latter, it's likely it's setting up
> in addition to what you do in scenario 1, no?
>
> Best regards, Julian
>


Re: oak-osgi : lucene searching not working

2020-03-06 Thread Sandeep Ambule
*In scenario 1 *, I have created a repository using a node store created
using  RDBDocumentNodeStoreBuilder

public DocumentNodeStore createRDBStore(){String
jdbcurl="jdbc:postgresql://127.0.0.1:5432/SP05";String
user="postgres";String pw="manager";DataSource dataSource =
RDBDataSourceFactory.forJdbcUrl(jdbcurl, user, pw);

DocumentNodeStore store = new
RDBDocumentNodeStoreBuilder().newRDBDocumentNodeStoreBuilder()
   .setRDBConnection(dataSource).build();
return store;

}


*In scenario 2: i have created a repository by autowiring *NodeStore
*osgi service.*


*i have given both scenario 1 and scenario 2 code in previous mail.*


*major difference in scenario 1 and scenario 2 is , In scenario 2 i am
using nodestore osgi service.*


On Thu, Mar 5, 2020 at 5:20 PM Julian Reschke  wrote:

> On 05.03.2020 11:22, Sandeep Ambule wrote:
> > I am trying to implement Lucene index full-text search with OSGi RDB
> > document service, but it's not working,
> >
> > Lucene search working fine if I created repository like below,
> >
> > Scenario 1: searching working correctly
> > ...
>
> So you've got one scenario where it works, and one where it does not.
>
> Could you please summarize how these scenarios differ?
>
> Best regards, Julian
>


oak-osgi : lucene searching not working

2020-03-05 Thread Sandeep Ambule
I am trying to implement Lucene index full-text search with OSGi RDB
document service, but it's not working,

Lucene search working fine if I created repository like below,

Scenario 1: searching working correctly

@Overrideprotected ContentRepository createRepository() {
return getOakRepo().createContentRepository();}
Oak getOakRepo() {
  //  LowCostLuceneIndexProvider provider = new
LowCostLuceneIndexProvider();LuceneIndexProvider provider = new
LuceneIndexProvider();
return new Oak(createInitialContent())
.with(new OpenSecurityProvider())
.with((QueryIndexProvider) provider)
.with((Observer) provider)
.with(new LuceneIndexEditorProvider());}


private  DocumentNodeStore createInitialContent(){DocumentNodeStore
ds=createRDBStore();
EditorHook hook = new EditorHook(
new CompositeEditorProvider(new NamespaceEditorProvider(),
new TypeEditorProvider()));

OakInitializer.initialize(ds, new InitialContent(), hook);
return ds;}

public DocumentNodeStore createRDBStore(){String
jdbcurl="jdbc:postgresql://127.0.0.1:5432/SP05";String
user="postgres";String pw="manager";DataSource dataSource =
RDBDataSourceFactory.forJdbcUrl(jdbcurl, user, pw);DocumentNodeStore
store = new RDBDocumentNodeStoreBuilder().newRDBDocumentNodeStoreBuilder()
   .setRDBConnection(dataSource).build();

return store; }

Scenario 2: searching not working

@Autowiredprivate NodeStore documentNodeStoreService;

   @Overrideprotected ContentRepository createRepository() {
return getOakRepo().createContentRepository();
}

Oak getOakRepo() {
  //  LowCostLuceneIndexProvider provider = new
LowCostLuceneIndexProvider();
LuceneIndexProvider provider = new LuceneIndexProvider();
return new Oak(intializeNodeStoreService())
.with(new OpenSecurityProvider())
.with((QueryIndexProvider) provider)
.with((Observer) provider)
.with(new LuceneIndexEditorProvider());
}


private static CommitInfo createCommitInfo() {
Map infoMap = ImmutableMap.of(CommitContext.NAME, new SimpleCommitContext());
return new CommitInfo(SESSION_ID, null, infoMap);
}

private NodeStore intializeNodeStoreService() {
EditorHook hook = new EditorHook(
new CompositeEditorProvider(new
NamespaceEditorProvider(), new TypeEditorProvider()));
try {
NodeBuilder builder = documentNodeStoreService.getRoot().builder();
new InitialContent().initialize(builder);
documentNodeStoreService.merge(builder, hook, createCommitInfo());

} catch (CommitFailedException e) {
throw new RuntimeException(e);
}

return documentNodeStoreService;

}

In this case repository get created but searching not working, giving error
like Traversal query (query without index)

Can you tell me ,what wrong i am doing here?

Code to create Lucene index in both scenario ,

  Tree index = root.getTree("/");
  Tree indexDefn = createTestIndexNode(index,
LuceneIndexConstants.TYPE_LUCENE);
  TestUtil.useV2(indexDefn);

  indexDefn.setProperty(LuceneIndexConstants.TEST_MODE, true);
  indexDefn.setProperty(FulltextIndexConstants.EVALUATE_PATH_RESTRICTION,
true);

  Tree props = TestUtil.newRulePropTree(indexDefn, "nt:base");
  props.getParent().setProperty(FulltextIndexConstants.INDEX_NODE_NAME,
true);
  TestUtil.enablePropertyIndex(props, "c1/p", false);
  TestUtil.enableForFullText(props,
FulltextIndexConstants.REGEX_ALL_PROPS, true);
  TestUtil.enablePropertyIndex(props, "a/name", false);
  TestUtil.enablePropertyIndex(props, "b/name", false);
  TestUtil.enableFunctionIndex(props, "length([name])");
  TestUtil.enableFunctionIndex(props, "lower([name])");
  TestUtil.enableFunctionIndex(props, "upper([name])");

  root.commit();
  }


Lucene search not working with osgi RDB DocumentService

2020-02-24 Thread Sandeep Ambule
Hi ,

i am trying to implement lucene index  fulltest search with osgi RDB
documentService,but its not working,

Lucene search working fine if i created repository like below,

Scenario 1: searching working correctly

@Override
protected ContentRepository createRepository() {
return getOakRepo().createContentRepository();
}

Oak getOakRepo() {
  //  LowCostLuceneIndexProvider provider = new
LowCostLuceneIndexProvider();
LuceneIndexProvider provider = new LuceneIndexProvider();
return new Oak(createInitialContent())
.with(new OpenSecurityProvider())
.with((QueryIndexProvider) provider)
.with((Observer) provider)
.with(new LuceneIndexEditorProvider());
}



private  DocumentNodeStore createInitialContent()
{
DocumentNodeStore ds=createRDBStore();
EditorHook hook = new EditorHook(
new CompositeEditorProvider(new NamespaceEditorProvider(),
new TypeEditorProvider()));

OakInitializer.initialize(ds, new InitialContent(), hook);
return ds;
}


public DocumentNodeStore createRDBStore()
{
String jdbcurl="jdbc:postgresql://127.0.0.1:5432/SP05";
String user="postgres";
String pw="manager";
DataSource dataSource = RDBDataSourceFactory.forJdbcUrl(jdbcurl, user,
pw);
DocumentNodeStore store = new
RDBDocumentNodeStoreBuilder().newRDBDocumentNodeStoreBuilder()
   .setRDBConnection(dataSource).build();
return store;
}



Scenario 2: searching not working

@Autowired
private NodeStore documentNodeStoreService;

   @Override
protected ContentRepository createRepository() {
return getOakRepo().createContentRepository();
}

Oak getOakRepo() {
  //  LowCostLuceneIndexProvider provider = new
LowCostLuceneIndexProvider();
LuceneIndexProvider provider = new LuceneIndexProvider();
return new Oak(documentNodeStoreService)
.with(new OpenSecurityProvider())
.with((QueryIndexProvider) provider)
.with((Observer) provider)
.with(new LuceneIndexEditorProvider());
}


In this case repository get created but searching not working,
giving error like  Traversal query (query without index)

Can you tell me ,what wrong i am doing here?



 Code to create Lucene index in both scenario ,

   protected void createTestIndexNode() throws Exception {
Tree index = root.getTree("/");
Tree indexDefn = createTestIndexNode(index,
LuceneIndexConstants.TYPE_LUCENE);
TestUtil.useV2(indexDefn);

indexDefn.setProperty(LuceneIndexConstants.TEST_MODE, true);

indexDefn.setProperty(FulltextIndexConstants.EVALUATE_PATH_RESTRICTION,
true);

Tree props = TestUtil.newRulePropTree(indexDefn, "nt:base");

props.getParent().setProperty(FulltextIndexConstants.INDEX_NODE_NAME, true);
TestUtil.enablePropertyIndex(props, "c1/p", false);
TestUtil.enableForFullText(props,
FulltextIndexConstants.REGEX_ALL_PROPS, true);
TestUtil.enablePropertyIndex(props, "a/name", false);
TestUtil.enablePropertyIndex(props, "b/name", false);
TestUtil.enableFunctionIndex(props, "length([name])");
TestUtil.enableFunctionIndex(props, "lower([name])");
TestUtil.enableFunctionIndex(props, "upper([name])");

root.commit();
}


Fwd: Lucene index: getting empty result while query

2019-10-07 Thread Sandeep Ambule
Hi ,
I am trying to query with Lucene index but getting the empty result and
below errors in the log,
Traversal query (query without index): select [jcr:path] from [nt:base]
where isdescendantnode('/test') and name='World'; consider creating an index
[async] The index update failed
org.apache.jackrabbit.oak.api.CommitFailedException: OakAsync0002: Missing
index provider detected for type [counter] on index [/oak:index/counter]

can you help me to find what wrong I am doing here,

public class SimpleTest {
@Test
public void simpleTest() throws Exception {
NodeStore store = new MemoryNodeStore();

//create reposiotory
LuceneIndexProvider provider = new LuceneIndexProvider();
ContentRepository repository = new Oak(store)
.with(new OpenSecurityProvider())
.with(new InitialContent())
.with(new NodeCounterEditorProvider())
.with((QueryIndexProvider) provider)
.with((Observer) provider)
.with(new LuceneIndexEditorProvider())
.withAsyncIndexing("async",
5).createContentRepository();

//login reposiotory and retrive session
ContentSession contentSession = repository.login(null, null);
Root root = contentSession.getLatestRoot();

//create lucene index
IndexDefinitionBuilder idxBuilder = new
IndexDefinitionBuilder().async("async");
idxBuilder.indexRule("nt:base").property("name").propertyIndex();

idxBuilder.build(root.getTree("/").addChild("oak:index").addChild("lucene"));
root.commit();

//Create TestNode
String h = "Hello";
String w = "World";

Tree test = root.getTree("/").addChild("test");
test.addChild("a").setProperty("name", Arrays.asList(new String[] {
h, w }), Type.STRINGS);
test.addChild("b").setProperty("name", h);
root.commit();

// wait for async indexing cycle (avoiding more elegant ways)
Thread.sleep(TimeUnit.SECONDS.toMillis(10));

//Search
String query = "select [jcr:path] from [nt:base] where
isdescendantnode('/test') and name='World' option(traversal fail)";

List paths = executeQuery(root, query);
for (String path : paths) {
System.out.println("Path=" + path);
}
}

private List executeQuery(Root root, String query) throws
ParseException {
Result result = root.getQueryEngine()
.executeQuery(query, "JCR-SQL2", QueryEngine.NO_BINDINGS,
QueryEngine.NO_MAPPINGS);

    return StreamSupport.stream(result.getRows().spliterator(), false)
.map(row -> row.getPath())
.collect(Collectors.toList());
}
}

Regards,
Sandeep Ambule


Lucene index: getting empty result while query

2019-09-30 Thread Sandeep Ambule
Hi ,
I am trying to query with Lucene index but getting the empty result and
below errors in the log,
Traversal query (query without index): select [jcr:path] from [nt:base]
where isdescendantnode('/test') and name='World'; consider creating an index
[async] The index update failed
org.apache.jackrabbit.oak.api.CommitFailedException: OakAsync0002: Missing
index provider detected for type [counter] on index [/oak:index/counter]

can you help me to find what wrong I am doing here,

PFA of my code.

Regards,
Sandeep Ambule
public class SimpleTest {
@Test
public void simpleTest() throws Exception {
NodeStore store = new MemoryNodeStore();

//create reposiotory
LuceneIndexProvider provider = new LuceneIndexProvider();
ContentRepository repository = new Oak(store)
.with(new OpenSecurityProvider())
.with(new InitialContent())
.with(new NodeCounterEditorProvider())
.with((QueryIndexProvider) provider)
.with((Observer) provider)
.with(new LuceneIndexEditorProvider())
.withAsyncIndexing("async",
5).createContentRepository();

//login reposiotory and retrive session
ContentSession contentSession = repository.login(null, null);
Root root = contentSession.getLatestRoot();

//create lucene index
IndexDefinitionBuilder idxBuilder = new 
IndexDefinitionBuilder().async("async");
idxBuilder.indexRule("nt:base").property("name").propertyIndex();

idxBuilder.build(root.getTree("/").addChild("oak:index").addChild("lucene"));
root.commit();

//Create TestNode
String h = "Hello";
String w = "World";

Tree test = root.getTree("/").addChild("test");
test.addChild("a").setProperty("name", Arrays.asList(new String[] { h, 
w }), Type.STRINGS);
test.addChild("b").setProperty("name", h);
root.commit();

// wait for async indexing cycle (avoiding more elegant ways)
Thread.sleep(TimeUnit.SECONDS.toMillis(10));

//Search
String query = "select [jcr:path] from [nt:base] where 
isdescendantnode('/test') and name='World' option(traversal fail)";

List paths = executeQuery(root, query);
for (String path : paths) {
System.out.println("Path=" + path);
}
}

private List executeQuery(Root root, String query) throws 
ParseException {
Result result = root.getQueryEngine()
.executeQuery(query, "JCR-SQL2", QueryEngine.NO_BINDINGS, 
QueryEngine.NO_MAPPINGS);

return StreamSupport.stream(result.getRows().spliterator(), false)
.map(row -> row.getPath())
.collect(Collectors.toList());
}
}