Back to index

nordugrid-arc-nox  1.1.0~rc6
Public Member Functions | Private Attributes
Arc::JobQueue Class Reference

#include <job_queue.h>

Collaboration diagram for Arc::JobQueue:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 JobQueue ()
 ~JobQueue ()
void init (const std::string &dbroot, const std::string &store_name)
void refresh (Job &j)
Joboperator[] (const std::string &id)
void remove (Job &job)
void remove (const std::string &id)
JobQueueIterator getAll (void)
JobQueueIterator getAll (JobSelector *selector_)
void sync (void)
void checkpoint (void)

Private Attributes

DbEnv * env_
Db * db_
Arc::Logger logger_

Detailed Description

Definition at line 53 of file job_queue.h.


Constructor & Destructor Documentation

Definition at line 60 of file job_queue.h.

:logger_(Arc::Logger::rootLogger, "JobQ") { env_ = NULL; db_ = NULL; };

Definition at line 169 of file job_queue.cpp.

{
    if (db_ != NULL) {
        db_->close(0);
        delete db_;
    }
    if (env_ != NULL) {
        env_->close(0);
        delete env_;
    }
}

Member Function Documentation

void Arc::JobQueue::checkpoint ( void  )

Definition at line 327 of file job_queue.cpp.

{
    try {
        env_->txn_checkpoint(0, 0, 0);
    } catch(DbException &e) {
        logger_.msg(Arc::ERROR, "checkpoint: %s", e.what());
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 286 of file job_queue.cpp.

{
    Dbc *cursor;
    DbTxn *tid = NULL;
    try {
        env_->txn_begin(NULL, &tid, 0);
    } catch (std::exception &e) {
        return JobQueueIterator();
    }
    try {
        db_->cursor(tid, &cursor, 0);
        return JobQueueIterator(tid, cursor);
    } catch (DbException &e) {
        tid->abort();
        return JobQueueIterator();
    }
}

Here is the caller graph for this function:

Definition at line 304 of file job_queue.cpp.

{
    Dbc *cursor;
    DbTxn *tid = NULL;
    try {
        env_->txn_begin(NULL, &tid, 0);
    } catch (std::exception &e) {
        return JobQueueIterator();
    }
    try {
        db_->cursor(tid, &cursor, 0);
        return JobQueueIterator(tid, cursor, selector_);
    } catch (DbException &e) {
        tid->abort();
        return JobQueueIterator();
    }
}
void Arc::JobQueue::init ( const std::string &  dbroot,
const std::string &  store_name 
)

Definition at line 143 of file job_queue.cpp.

{
    env_ = NULL;
    db_ = NULL;
    env_ = new DbEnv(0); // Exception will occure
    // env_->open(dbroot.c_str(), DB_CREATE | DB_INIT_CDB | DB_INIT_MPOOL | DB_THREAD, 0644);
    env_->open(dbroot.c_str(), DB_CREATE | DB_INIT_MPOOL | DB_INIT_LOCK | DB_INIT_TXN | DB_RECOVER | DB_THREAD, 0644);
    // setup internal deadlock detection mechanizm
    env_->set_lk_detect(DB_LOCK_DEFAULT);
    db_ = new Db(env_, 0);
    try {
#if (DB_VERSION_MAJOR < 4) || (DB_VERSION_MAJOR == 4 && DB_VERSION_MINOR == 0)
        db_->open(store_name.c_str(), DB_BTREE, DB_CREATE | DB_THREAD, 0644);
#else
        DbTxn *tid = NULL;
        env_->txn_begin(NULL, &tid, 0);
        db_->open(tid, store_name.c_str(), NULL, DB_BTREE, DB_CREATE | DB_THREAD, 0644);
        tid->commit(0);
#endif
    } catch (DbException &e) {
        logger_.msg(Arc::ERROR, "Cannot open database");
        db_ = NULL;
        return;
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

Job * Arc::JobQueue::operator[] ( const std::string &  id)

Definition at line 213 of file job_queue.cpp.

{
    void *buf = (void *)id.c_str();
    int size = id.size() + 1;
    Dbt key(buf, size);
    Dbt data;
    data.set_flags(DB_DBT_MALLOC);
    DbTxn *tid = NULL;
    while (true) {
        try {
            env_->txn_begin(NULL, &tid, 0);
            if (db_->get(tid, &key, &data, 0) != DB_NOTFOUND) {
                ByteArray a(data.get_data(), data.get_size());
                free(data.get_data());
                Job *j = new Job(a);
                tid->commit(0);
                return j;
            } else {
                tid->commit(0);
                throw JobNotFoundException();
            }
        } catch (DbDeadlockException &e) {
            try {
                tid->abort();
            } catch (DbException &e) {
                logger_.msg(Arc::ERROR, "operator[]: Cannot abort transaction: %s", e.what()); 
            }
            return NULL;
        } catch (DbException &e) {
            try {
                tid->abort();
            } catch (DbException &e) {
                logger_.msg(Arc::ERROR, "operator[]: Cannot abort transaction: %s", e.what()); 
            }
            return NULL;
        }
    }
}

Here is the call graph for this function:

void Arc::JobQueue::refresh ( Job j)

Definition at line 181 of file job_queue.cpp.

{
    // generate key
    void *buf = (void *)j.getID().c_str();
    int size = j.getID().size() + 1;
    Dbt key(buf, size);
    // generate data
    ByteArray &a = j.serialize();
    Dbt data(a.data(), a.size());
    
    DbTxn *tid = NULL;
    while (true) {
        try {
            env_->txn_begin(NULL, &tid, 0);
            db_->put(tid, &key, &data, 0);
            tid->commit(0);
            return;
        } catch (DbDeadlockException &de) {
            try {
                tid->abort();
            } catch (DbException &e) {
                logger_.msg(Arc::ERROR, "refresh: Cannot abort transaction: %s", e.what());
                return;
            }
        } catch (DbException &e) {
            logger_.msg(Arc::ERROR, "refresh: Error during transaction: %s", e.what());
            tid->abort();
            return;
        }
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void Arc::JobQueue::remove ( Job job)

Definition at line 252 of file job_queue.cpp.

{
    remove(j.getID());
}

Here is the call graph for this function:

Here is the caller graph for this function:

void Arc::JobQueue::remove ( const std::string &  id)

Definition at line 257 of file job_queue.cpp.

{
    DbTxn *tid = NULL;
    void *buf = (void *)id.c_str();
    int size = id.size() + 1;
    Dbt key(buf, size);
    while (true) { 
        try {
            env_->txn_begin(NULL, &tid, 0);
            db_->del(tid, &key, 0);
            tid->commit(0);
        } catch (DbDeadlockException &e) {
            try {
                tid->abort();
            } catch (DbException &e) {
                logger_.msg(Arc::ERROR, "remove: Cannot abort transaction: %s", e.what()); 
            }
            return;
        } catch (DbException &e) {
            try {
                tid->abort();
            } catch (DbException &e) {
                logger_.msg(Arc::ERROR, "remove: Cannot abort transaction: %s", e.what()); 
            }
            return;
        }
    }
}

Here is the call graph for this function:

void Arc::JobQueue::sync ( void  )

Definition at line 322 of file job_queue.cpp.

{
    // db_->sync(0);
}

Member Data Documentation

Db* Arc::JobQueue::db_ [private]

Definition at line 57 of file job_queue.h.

DbEnv* Arc::JobQueue::env_ [private]

Definition at line 56 of file job_queue.h.

Definition at line 58 of file job_queue.h.


The documentation for this class was generated from the following files: