{"action":"created","issue":{"url":"https://api.github.com/repos/cruppstahl/hamsterdb/issues/52","labels_url":"https://api.github.com/repos/cruppstahl/hamsterdb/issues/52/labels{/name}","comments_url":"https://api.github.com/repos/cruppstahl/hamsterdb/issues/52/comments","events_url":"https://api.github.com/repos/cruppstahl/hamsterdb/issues/52/events","html_url":"https://github.com/cruppstahl/hamsterdb/issues/52","id":66538463,"number":52,"title":"Cursor iteration not returning results in sorted order","user":{"login":"mjmckp","id":7776787,"avatar_url":"https://avatars.githubusercontent.com/u/7776787?v=3","gravatar_id":"","url":"https://api.github.com/users/mjmckp","html_url":"https://github.com/mjmckp","followers_url":"https://api.github.com/users/mjmckp/followers","following_url":"https://api.github.com/users/mjmckp/following{/other_user}","gists_url":"https://api.github.com/users/mjmckp/gists{/gist_id}","starred_url":"https://api.github.com/users/mjmckp/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mjmckp/subscriptions","organizations_url":"https://api.github.com/users/mjmckp/orgs","repos_url":"https://api.github.com/users/mjmckp/repos","events_url":"https://api.github.com/users/mjmckp/events{/privacy}","received_events_url":"https://api.github.com/users/mjmckp/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-04-06T06:18:04Z","updated_at":"2015-04-06T09:54:07Z","closed_at":null,"body":"The code below can be pasted into dotnet\\unittests\\CursorTest.cs and run with either ReproduceBug(true) or ReproduceBug(false).  The point in the test at which each fails has been annotated within the code.  I've tried to provide a minimal example of the error, however the following things seems to be required to obtain the errors: 1) Use trasactions, 2) Inserting unequal length arrays for the record values, and 3) Using Cursor.Find followed by Cursor.Move to iterate over the contents of the DB.\r\n\r\nBy the way, the .NET project is missing the file Properties\\AssemblyInfo.cs in the GitHub repo.\r\n\r\n```\r\n        private void WithTransaction(Action<Transaction> f)\r\n        {\r\n            var txn = env.Begin();\r\n            try\r\n            {\r\n                f(txn);\r\n                txn.Commit();\r\n            }\r\n            catch\r\n            {\r\n                txn.Abort();\r\n                throw;\r\n            }\r\n        }\r\n\r\n        private void ReproduceBug(bool bugVariation)\r\n        {\r\n            env = new Hamster.Environment();\r\n            env.Create(\"ntest.db\", HamConst.HAM_ENABLE_TRANSACTIONS);   // Note: not using transactions works fine\r\n\r\n            var prm = new Parameter();\r\n            prm.name = HamConst.HAM_PARAM_KEY_TYPE;\r\n            prm.value = HamConst.HAM_TYPE_UINT64;\r\n            var prms = new Parameter[] { prm };\r\n\r\n            db = new Database();\r\n            db = env.CreateDatabase(1, HamConst.HAM_ENABLE_DUPLICATE_KEYS, prms);\r\n\r\n            var k1 = new byte[] { 128, 93, 150, 237, 49, 178, 92, 8 };\r\n            var k2 = new byte[] { 0, 250, 234, 1, 199, 250, 128, 8 };\r\n            var k3 = new byte[] { 128, 17, 181, 113, 1, 220, 132, 8 };\r\n\r\n            // print keys (note they are in ascending order as UInt64)\r\n            Console.WriteLine(\"{0}\", BitConverter.ToUInt64(k1, 0));\r\n            Console.WriteLine(\"{0}\", BitConverter.ToUInt64(k2, 0));\r\n            Console.WriteLine(\"{0}\", BitConverter.ToUInt64(k3, 0));\r\n            Console.WriteLine();\r\n\r\n            var v1  = new byte[46228];   // Note: using equal size value byte arrays works fine!\r\n            var v11 = new byte[446380];\r\n            var v12 = new byte[525933];\r\n            var v21 = new byte[334157];\r\n            var v22 = new byte[120392];\r\n            WithTransaction(txn => db.Insert(txn, k1, v1, Hamster.HamConst.HAM_DUPLICATE));\r\n            WithTransaction(txn => db.Insert(txn, k2, v11, Hamster.HamConst.HAM_DUPLICATE));\r\n            WithTransaction(txn => db.Insert(txn, k2, v12, Hamster.HamConst.HAM_DUPLICATE));\r\n            WithTransaction(txn => db.Insert(txn, k3, v21, Hamster.HamConst.HAM_DUPLICATE));\r\n            WithTransaction(txn => db.Insert(txn, k3, v22, Hamster.HamConst.HAM_DUPLICATE));\r\n\r\n            WithTransaction(txn =>\r\n            {\r\n                using (var c = new Cursor(db, txn))\r\n                {\r\n                    // Note: calling c.Move(HamConst.HAM_CURSOR_NEXT) instead works fine!\r\n                    if (bugVariation)                   \r\n                        c.Find(k1, HamConst.HAM_FIND_GEQ_MATCH);    \r\n                    else\r\n                        c.Find(k1);\r\n\r\n                    var s1 = c.GetKey();\r\n                    Console.WriteLine(\"{0}\", BitConverter.ToUInt64(s1, 0));\r\n\r\n                    c.Move(HamConst.HAM_CURSOR_NEXT);\r\n                    var s2 = c.GetKey();\r\n                    Console.WriteLine(\"{0}\", BitConverter.ToUInt64(s2, 0));\r\n\r\n                    c.Move(HamConst.HAM_CURSOR_NEXT);\r\n                    var s3 = c.GetKey();\r\n                    Console.WriteLine(\"{0}\", BitConverter.ToUInt64(s3, 0));\r\n\r\n                    c.Move(HamConst.HAM_CURSOR_NEXT);\r\n                    var s4 = c.GetKey();\r\n                    Console.WriteLine(\"{0}\", BitConverter.ToUInt64(s4, 0));\r\n\r\n                    c.Move(HamConst.HAM_CURSOR_NEXT);   // fails here when bugVariation == false\r\n                    var s5 = c.GetKey();\r\n                    Console.WriteLine(\"{0}\", BitConverter.ToUInt64(s5, 0));\r\n\r\n                    checkEqual(k1, s1);\r\n                    checkEqual(k2, s2); // fails here when bugVariation == true\r\n                    checkEqual(k2, s3);\r\n                    checkEqual(k3, s4);\r\n                    checkEqual(k3, s5);\r\n                }\r\n            });\r\n\r\n            env.Close();\r\n\r\n            return;\r\n        }\r\n```"},"comment":{"url":"https://api.github.com/repos/cruppstahl/hamsterdb/issues/comments/89997471","html_url":"https://github.com/cruppstahl/hamsterdb/issues/52#issuecomment-89997471","issue_url":"https://api.github.com/repos/cruppstahl/hamsterdb/issues/52","id":89997471,"user":{"login":"cruppstahl","id":209283,"avatar_url":"https://avatars.githubusercontent.com/u/209283?v=3","gravatar_id":"","url":"https://api.github.com/users/cruppstahl","html_url":"https://github.com/cruppstahl","followers_url":"https://api.github.com/users/cruppstahl/followers","following_url":"https://api.github.com/users/cruppstahl/following{/other_user}","gists_url":"https://api.github.com/users/cruppstahl/gists{/gist_id}","starred_url":"https://api.github.com/users/cruppstahl/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cruppstahl/subscriptions","organizations_url":"https://api.github.com/users/cruppstahl/orgs","repos_url":"https://api.github.com/users/cruppstahl/repos","events_url":"https://api.github.com/users/cruppstahl/events{/privacy}","received_events_url":"https://api.github.com/users/cruppstahl/received_events","type":"User","site_admin":false},"created_at":"2015-04-06T09:54:07Z","updated_at":"2015-04-06T09:54:07Z","body":"I can reproduce it. Please give me a couple of days for a fix. Thanks a lot for the test!"}}