[SERVER-9236] Wrong binary serialization when DuplicateKey occurs Created: 04/Apr/13  Updated: 02/Feb/16  Resolved: 02/Feb/16

Status: Closed
Project: Core Server
Component/s: Index Maintenance
Affects Version/s: 2.2.3
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: Anton V. Volokhov Assignee: Unassigned
Resolution: Duplicate Votes: 0
Labels: logging
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

java driver 2.11.0


Issue Links:
Duplicate
duplicates SERVER-9526 Log messages regarding chunks not ver... Closed
Operating System: ALL
Steps To Reproduce:

1: run code
import com.mongodb.BasicDBObject;
import com.mongodb.Mongo;
import com.mongodb.MongoException.DuplicateKey;
import com.mongodb.WriteConcern;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.net.UnknownHostException;

/**

  • @author Anton Volokhov
    */
    public class BDBOSerializeUtilsTest {
    private static final Logger log = LoggerFactory.getLogger(
    BDBOSerializeUtilsTest.class);

@Test
public void testSerialize() throws UnknownHostException {
final BasicDBObject object = new BasicDBObject("_id",
new byte[]

{1, 2, 3}

);
Mongo mongo = new Mongo();
mongo.setWriteConcern(WriteConcern.ACKNOWLEDGED);
mongo.getDB("testSerialize").getCollection("test").insert(object);
mongo.getDB("testSerialize").getCollection("test").insert(object);
}
}
2. Look at the exception message

Participants:

 Description   

This code throws MongoException.DuplicateKey, as expected. But error message doesn't contain actual key:
com.mongodb.MongoException$DuplicateKey: E11000 duplicate key error index: testSerialize.test.$id dup key: { : BinData }

Looks like this "{ : BinData}" comes from the server side. Is it any way to see actual key, that is duplicated? Just BinData is not user-friendly message at all.



 Comments   
Comment by Max Hirschhorn [ 02/Feb/16 ]

Closing as a duplicate of SERVER-9526. If the BinData holds fewer than 80 bytes, then it is included in the error message in its entirety. If the BinData holds more than 80 bytes, then the first 70 bytes of the BinData are included in the error message.

> db.mycoll.insert({_id: HexData(0, new Array(100).join('00'))})
WriteResult({ "nInserted" : 1 })
> db.mycoll.insert({_id: HexData(0, new Array(100).join('00'))})
WriteResult({
	"nInserted" : 0,
	"writeError" : {
		"code" : 11000,
		"errmsg" : "insertDocument :: caused by :: 11000 E11000 duplicate key error index: test.mycoll.$_id_  dup key: { : BinData(0, 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...) }"
	}
})

Generated at Thu Feb 08 03:19:47 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.