Immediate GET doesn't give the data from view

Ok,

i changed the query.setStale(Stale.UPDATE_AFTER); to query.setStale(Stale.FALSE); and it worked.

Doing that will be affect performance ?

Harshit

Hi,
I am creating a new document and saving it and then i try to read a view for it . I dont get the result .
This is how i save

public void set(String key, String jsonDoc) {
OperationFuture op = getCbclient().set(key,CouchbaseClientFactory.NO_EXPIRY_TIME, jsonDoc);
}


public List getMemberIdForHashes(String hashes) {
final View view = getCbclient().getView(“contacthash”, “by_hash”);
List hashList = new ArrayList();
final Query query = new Query();
query.setStale(Stale.UPDATE_AFTER);
// query.setIncludeDocs(Boolean.TRUE);
query.setInclusiveEnd(Boolean.TRUE);
String[] keys = hashes.split(",");
if(keys.length > 1)
query.setKeys(ComplexKey.of(keys));
else
query.setKey(hashes);
final ViewResponse viewResponse = getCbclient().query(view, query);

        if (CollectionUtils.isNotEmpty(viewResponse.getErrors())) {
        	logger.error(viewResponse.getErrors());
        	return hashList;
        }
        Iterator<ViewRow> iter = viewResponse.iterator();
        while(iter.hasNext()){
        	ViewRow v = iter.next();
        	try {
				List a = mapper.getJsonmapper().readValue(v.getValue(), List.class);
				hashList.add(a.get(0).toString());	
			} catch (Exception e) {
				e.printStackTrace();
			}	        	


        }
        return hashList;
}     

My test code
String hashedContact = “h”+new Random().nextInt(1000);
String memberId = new Random().nextInt(1000)+"";
ContactHash hash = new ContactHash(hashedContact, memberId, “email”);
contactManager.addContactToPool(hashedContact, “email”, memberId);
List list = contactManager.getMemberIdForHashes(hashedContact);

	list = contactManager.getMemberIdForHashes(hashedContact);

	Assert.assertEquals(1, list.size());
}

Like , if i run the test case again with previous key , then i can retrieve it. I can also see that doc is present after test case is run.

My guess is that document is not synced or added to view for some amount of time after we do a set. Is this a setting and can it be changed ?

Also I put a Thread.sleep(20000) between set and get but it didnt work .

Thanks
Harshit

Hello,

So yes it could be a little be slower since with stale=false you are asking Couchbase Server to update the index before responding to your query.
You can find more information about the stale parameter in the documentation:http://www.couchbase.com/docs/couchbase-manual-2.0/couchbase-views-writing-stale.html

Regards