Пример #1
0
Status WiredTigerUtil::setTableLogging(OperationContext* opCtx, const std::string& uri, bool on) {
    // Try to close as much as possible to avoid EBUSY errors.
    WiredTigerRecoveryUnit::get(opCtx)->getSession()->closeAllCursors(uri);
    WiredTigerSessionCache* sessionCache = WiredTigerRecoveryUnit::get(opCtx)->getSessionCache();
    sessionCache->closeAllCursors(uri);

    // Use a dedicated session for alter operations to avoid transaction issues.
    WiredTigerSession session(sessionCache->conn());
    return setTableLogging(session.getSession(), uri, on);
}
Пример #2
0
Status WiredTigerRecordStore::compact(OperationContext* txn,
                                      RecordStoreCompactAdaptor* adaptor,
                                      const CompactOptions* options,
                                      CompactStats* stats) {
    WiredTigerSessionCache* cache = WiredTigerRecoveryUnit::get(txn)->getSessionCache();
    WiredTigerSession* session = cache->getSession();
    WT_SESSION* s = session->getSession();
    int ret = s->compact(s, getURI().c_str(), "timeout=0");
    invariantWTOK(ret);
    cache->releaseSession(session);
    return Status::OK();
}
Пример #3
0
    int WiredTigerUtil::verifyTable(OperationContext* txn, const std::string& uri,
                                    std::vector<std::string>* errors) {

        class MyEventHandlers : public WT_EVENT_HANDLER {
        public:
            MyEventHandlers(std::vector<std::string>* errors)
                : WT_EVENT_HANDLER(defaultEventHandlers())
                , _errors(errors)
                , _defaultErrorHandler(handle_error)
            {
                handle_error = onError;
            }

        private:
            static int onError(WT_EVENT_HANDLER* handler, WT_SESSION* session, int error,
                               const char* message) {
                try {
                    MyEventHandlers* self = static_cast<MyEventHandlers*>(handler);
                    self->_errors->push_back(message);
                    return self->_defaultErrorHandler(handler, session, error, message);
                }
                catch (...) {
                    std::terminate();
                }
            }

            typedef int(*ErrorHandler)(WT_EVENT_HANDLER*, WT_SESSION*, int, const char*);

            std::vector<std::string>* const _errors;
            const ErrorHandler _defaultErrorHandler;
        } eventHandler(errors);

        // Try to close as much as possible to avoid EBUSY errors.
        WiredTigerRecoveryUnit::get(txn)->getSession(txn)->closeAllCursors();
        WiredTigerSessionCache* sessionCache = WiredTigerRecoveryUnit::get(txn)->getSessionCache();
        sessionCache->closeAll();

        // Open a new session with custom error handlers.
        WT_CONNECTION* conn = WiredTigerRecoveryUnit::get(txn)->getSessionCache()->conn();
        WT_SESSION* session;
        invariantWTOK(conn->open_session(conn, errors ? &eventHandler : NULL, NULL, &session));
        ON_BLOCK_EXIT(session->close, session, "");

        // Do the verify. Weird parens prevent treating "verify" as a macro.
        return (session->verify)(session, uri.c_str(), NULL);
    }
Пример #4
0
int WiredTigerUtil::verifyTable(OperationContext* txn,
                                const std::string& uri,
                                std::vector<std::string>* errors) {
    ErrorAccumulator eventHandler(errors);

    // Try to close as much as possible to avoid EBUSY errors.
    WiredTigerRecoveryUnit::get(txn)->getSession(txn)->closeAllCursors();
    WiredTigerSessionCache* sessionCache = WiredTigerRecoveryUnit::get(txn)->getSessionCache();
    sessionCache->closeAll();

    // Open a new session with custom error handlers.
    WT_CONNECTION* conn = WiredTigerRecoveryUnit::get(txn)->getSessionCache()->conn();
    WT_SESSION* session;
    invariantWTOK(conn->open_session(conn, &eventHandler, NULL, &session));
    ON_BLOCK_EXIT(session->close, session, "");

    // Do the verify. Weird parens prevent treating "verify" as a macro.
    return (session->verify)(session, uri.c_str(), NULL);
}
TEST(WiredTigerSessionCacheTest, CheckSessionCacheCleanup) {
    WiredTigerSessionCacheHarnessHelper harnessHelper("");
    WiredTigerSessionCache* sessionCache = harnessHelper.getSessionCache();
    ASSERT_EQUALS(sessionCache->getIdleSessionsCount(), 0U);
    {
        UniqueWiredTigerSession _session = sessionCache->getSession();
        ASSERT_EQUALS(sessionCache->getIdleSessionsCount(), 0U);
    }
    // Destroying of a session puts it in the session cache
    ASSERT_EQUALS(sessionCache->getIdleSessionsCount(), 1U);

    // An idle timeout of 0 means never expire idle sessions
    sessionCache->closeExpiredIdleSessions(0);
    ASSERT_EQUALS(sessionCache->getIdleSessionsCount(), 1U);
    sleepmillis(10);

    // Expire sessions that have been idle for 10 secs
    sessionCache->closeExpiredIdleSessions(10000);
    ASSERT_EQUALS(sessionCache->getIdleSessionsCount(), 1U);
    // Expire sessions that have been idle for 2 millisecs
    sessionCache->closeExpiredIdleSessions(2);
    ASSERT_EQUALS(sessionCache->getIdleSessionsCount(), 0U);
}