couchbaselabs / cbforest

C++ wrapper library around ForestDB, for use in Couchbase Lite.
17 stars 12 forks source link

Fixed Java Core Issue 1448 - CBForest: Assertion failed: !_inTransact… #111

Closed hideki closed 8 years ago

hideki commented 8 years ago

…ion in Database::beginTransaction()

With view/query with multi-threads, currently CBL Android faces assertion failure with !_inTransaction in Database::beginTransaction().

Transaction should be only one per Database. But, as Line 285 and 286 waits till _file->_transaction becomes NULL. So CBFAssert(!_inTransaction); at beginning of beginTransaction() is inappropriate.

    void Database::beginTransaction(Transaction* t, bool active) {
        CBFAssert(!_inTransaction);
        if (!isOpen())
            error::_throw(FDB_RESULT_INVALID_HANDLE);
        std::unique_lock<std::mutex> lock(_file->_transactionMutex);
        while (_file->_transaction != NULL)
            _file->_transactionCond.wait(lock);

        _file->_transaction = t;
        _inTransaction = true;

        if (active) {
            Log("Database: beginTransaction");
            check(fdb_begin_transaction(_fileHandle, FDB_ISOLATION_READ_COMMITTED));
        }
    }
snej commented 8 years ago

I remember this bug! Somehow I thought it had already been fixed weeks ago...