Custom Reduce behaving inconsistently


#1

Hi,


I am using couchbase version 2.0.1 - enterprise edition (build-170) and java-client version 1.2.2

I have a custom reduce function to get last activity of a user

The response from java client is inconsistent At time I get correct response and most of the time I get null value against valid keys. Even Stale.FALSE doesn’t help !!

Number of records in view is around 1 millon and result set for query is arounk 1K key value pairs.
I am not sure what could be the issue here… It will be great if someone can help.

Reduce Function is as below:


function (key, values, rereduce) {
var currDate = 0;
var activity = “”;
for(var idx in values){
if(currDate < values[idx][0]){
currDate = values[idx][0];
activity = values[idx][1];
}
}
return [currDate, activity];
}

View Query:


CouchbaseClient cbc = Couchbase.getConnection();
Query query = new Query();
query.setIncludeDocs(false);
query.setSkip(0);
query.setLimit(10000);
query.setReduce(true);
query.setGroupLevel(4);
query.setRange(startKey,endKey);
View view = cbc.getView(document, view);
ViewResponse response = cbc.query(view, query);


#2

Could you also post your map function?
Also, any reason you’re not using the latest version of Couchbase server (2.1.1 Community / 2.2.0 Enterprise)?


#3

I have migration lined up soon. No reason for not migration. Pl. Warn me if there could be any :slight_smile:

Map code:

function (doc, meta) {
if(doc.identifier && doc.identifier == “RawActivityMetric” && doc.status == “ACTIVITY_STARTED”){
var posSplit = doc.positionId.split("|");
if(posSplit.length == 4){
var trainingId = posSplit[0];
var activityId = posSplit[3];
emit([doc.accessId, trainingId, doc.userId, doc.version], [doc.datetime, activityId]);
}
}
}

all docs have the fields identifier,accessId , status,positionId,userId,datetime and version(This version is different from meta.rev)

doc.datetime is number and all other fields are String.

My Progress today:

Querying from Web console I could fetch all 1K records multiple times without any inconsistency. I guessed some inconsistency between gson(used in my application) and couchbase-client. And update couchbase-client to 1.2.3 and replaces gson with jackson 2.2.2.

Query is working since lib updates… but I cannot confirm due to the randomness of issue.
Is there any know inconsistency with gson or with couchbase-server 2.0.1 ?

Thanks.


#4

I’m not aware with any issues with gson, but if a document isn’t well-formed json it will be treated as a BLOB and hence you won’t be able to access individual fields in it. (You can check for this by testing the meta.type field - this will be “json” for correctly-formatted JSON documents.


#5

tried to query non json meta.type and stale false … all documents look fine. thanks for the input.


#6

I bet it has something to do with the fact that you didn’t distinguish between the rereduce true and false situations.