Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ForestDB: Emitting dictionary key causes error #479

Closed
24601 opened this issue Oct 3, 2014 · 5 comments
Closed

ForestDB: Emitting dictionary key causes error #479

24601 opened this issue Oct 3, 2014 · 5 comments

Comments

@24601
Copy link

24601 commented Oct 3, 2014

When running a query against a FORESTDB couchbase lite db (new or upgraded, happens on both), getting a "FORESTDB ERROR -1" when calling run on the CBLQuery object to get the CBLQueryEnumerator.

Specifically:

CBLQuery* statuteComponents = [statuteComponentsByCitation createQuery];

CBLQueryEnumerator* results = [statuteComponents run:&error];

creates:

FORESTDB ERROR -1
(lldb) bt
* thread #1: tid = 0x1e8c03, 0x000000010669e519 libc++abi.dylib`__cxa_throw, queue = 'com.apple.root.default-qos', stop reason = breakpoint 1.2
    frame #0: 0x000000010669e519 libc++abi.dylib`__cxa_throw
    frame #1: 0x0000000101de82c5 Voltaire`forestdb::Transaction::set(forestdb::slice, forestdb::slice, forestdb::slice) + 309
    frame #2: 0x0000000101df5088 Voltaire`forestdb::IndexTransaction::update(forestdb::slice, unsigned long long, std::__1::vector<forestdb::Collatable, std::__1::allocator<forestdb::Collatable> >, std::__1::vector<forestdb::Collatable, std::__1::allocator<forestdb::Collatable> >, unsigned long long&) + 568
    frame #3: 0x0000000101deb941 Voltaire`forestdb::MapReduceIndex::updateDocInIndex(forestdb::IndexTransaction&, forestdb::Mappable const&) + 225
    frame #4: 0x00000001067d5825 libdispatch.dylib`_dispatch_client_callout2 + 8
    frame #5: 0x00000001067c2c54 libdispatch.dylib`_dispatch_apply_serial + 56
    frame #6: 0x00000001067d57f4 libdispatch.dylib`_dispatch_client_callout + 8
    frame #7: 0x00000001067bcb64 libdispatch.dylib`_dispatch_sync_f_invoke + 303
    frame #8: 0x00000001067c28df libdispatch.dylib`dispatch_apply_f + 306
    frame #9: 0x0000000101dec76e Voltaire`forestdb::MapReduceDispatchIndexer::addMappable(forestdb::Mappable const&) + 94
    frame #10: 0x0000000101de5933 Voltaire`___lldb_unnamed_function2794$$Voltaire + 255
    frame #11: 0x0000000101debdd5 Voltaire`forestdb::MapReduceIndexer::run() + 405
    frame #12: 0x0000000101daaeb2 Voltaire`___lldb_unnamed_function1488$$Voltaire + 571
    frame #13: 0x0000000101daa71e Voltaire`___lldb_unnamed_function1476$$Voltaire + 88
    frame #14: 0x0000000101da3423 Voltaire`___lldb_unnamed_function1339$$Voltaire + 395
    frame #15: 0x0000000101da0165 Voltaire`___lldb_unnamed_function1227$$Voltaire + 153
  * frame #16: 0x0000000101c95574 Voltaire`+[VTAccountViewController doDataLoadStatic](self=0x000000010258ccc8, _cmd=0x0000000102279bde) + 3028 at VTAccountViewController.m:130
    frame #17: 0x0000000101c8f89b Voltaire`__40-[VTLoginFormViewController viewDidLoad]_block_invoke255(.block_descriptor=<unavailable>) + 667 at VTLoginFormViewController.m:178
    frame #18: 0x0000000101e8c9b9 Voltaire`-[BPFormButtonCell buttonPressed:](self=0x00007ff01b1c1b60, _cmd=0x0000000104dd0354, sender=0x00007ff01b1469a0) + 137 at BPFormButtonCell.m:81
    frame #19: 0x0000000104577e6e UIKit`-[UIApplication sendAction:to:from:forEvent:] + 75
    frame #20: 0x000000010467e9c0 UIKit`-[UIControl _sendActionsForEvents:withEvent:] + 467
    frame #21: 0x000000010467dd8f UIKit`-[UIControl touchesEnded:withEvent:] + 522
    frame #22: 0x00000001049247d0 UIKit`_UIGestureRecognizerUpdate + 9487
    frame #23: 0x00000001045bd5a6 UIKit`-[UIWindow _sendGesturesForEvent:] + 1041
    frame #24: 0x00000001045be1d3 UIKit`-[UIWindow sendEvent:] + 667
    frame #25: 0x000000010458af61 UIKit`-[UIApplication sendEvent:] + 246
    frame #26: 0x000000010459802d UIKit`_UIApplicationHandleEventFromQueueEvent + 17370
    frame #27: 0x00000001045736b3 UIKit`_UIApplicationHandleEventQueue + 1961
    frame #28: 0x00000001061d7551 CoreFoundation`__CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
    frame #29: 0x00000001061cd41d CoreFoundation`__CFRunLoopDoSources0 + 269
    frame #30: 0x00000001061cca54 CoreFoundation`__CFRunLoopRun + 868
    frame #31: 0x00000001061cc486 CoreFoundation`CFRunLoopRunSpecific + 470
    frame #32: 0x00000001079949f0 GraphicsServices`GSEventRunModal + 161
    frame #33: 0x00000001045769d0 UIKit`UIApplicationMain + 1282
    frame #34: 0x0000000101c9f413 Voltaire`main(argc=1, argv=0x00007fff5e0104a8) + 115 at main.m:19
    frame #35: 0x000000010680a145 libdyld.dylib`start + 1

The view creation code looks like this:

CBLView* statuteComponentsByCitation = [self.cblDatabase viewNamed:@"statuteComponents"];

[statuteComponentsByCitation setMapBlock: MAPBLOCK({
    // NSLog(@"map function for casesByName got doc: %@",[doc description]);
    if([[doc valueForKey:@"type"] isEqualToString:@"VTStatuteComponent"])
    {

            emit(doc,[doc valueForKey:@"citation"]);
    }
}) version:@"3"];

(obviously, this should be open against the forestdb branch)

@snej
Copy link
Contributor

snej commented Oct 3, 2014

I think you put the parameters to emit backwards — it's (key, value) not (value, key).

What you've done shouldn't crash (though it's unlikely to do anything useful), but since doc is an NSDictionary it means the index key is a JSON dictionary/map/object instead of a scalar or array. This hasn't been tested in CBL since it's almost never done, as dictionaries don't make useful index keys.

I should figure out why this is crashing and make it not crash, but if you fix your emit call this won't happen anymore.

@snej snej changed the title Crash with "FORESTDB ERROR -1" when running query ForestDB: Emitting dictionary key causes error Oct 3, 2014
@snej snej added this to the Future milestone Oct 3, 2014
@24601
Copy link
Author

24601 commented Oct 6, 2014

Yup, that was a bonehead move on my part :), thanks for catching the error on my part!

@jessliu jessliu modified the milestones: 1.2.0, Future Oct 10, 2014
@jessliu jessliu added the icebox label Oct 10, 2014
@snej
Copy link
Contributor

snej commented Oct 13, 2014

That's error FDB_RESULT_INVALID_ARGS from fdb_set(). Not sure why that would happen; empty key?

@snej
Copy link
Contributor

snej commented Oct 13, 2014

Actually it was probably a too-long key; currently ForestDB's maximum key length is 3840 bytes (FDB_MAX_KEYLEN). We should handle or at least report this better, since I think other developers may run into it.

@snej
Copy link
Contributor

snej commented Oct 14, 2014

The latest commit (4884ae7) logs a specific warning in this case, and just skips emitting that one key/value pair instead of aborting the whole index update.

@snej snej closed this as completed Oct 14, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants