예제 #1
0
파일: lmdb_engine.cpp 프로젝트: Abioy/ardb
 int LMDBEngine::Put(const Slice& key, const Slice& value, const Options& options)
 {
     LMDBContext& holder = m_ctx_local.GetValue();
     MDB_txn *txn = holder.readonly_txn;
     if (NULL == txn || holder.batch_write == 0)
     {
         MDB_val k, v;
         k.mv_data = const_cast<char*>(key.data());
         k.mv_size = key.size();
         v.mv_data = const_cast<char*>(value.data());
         v.mv_size = value.size();
         CHECK_OP(mdb_txn_begin(m_env, NULL, 0, &txn));
         CHECK_OP(mdb_put(txn, m_dbi, &k, &v, 0));
         CHECK_OP(mdb_txn_commit(txn));
         return 0;
     }
     PutOperation* op = new PutOperation;
     op->key.assign((const char*) key.data(), key.size());
     op->value.assign((const char*) value.data(), value.size());
     m_write_queue.Push(op);
     if (holder.batch_write == 0)
     {
         CheckPointOperation* ck = new CheckPointOperation(holder.cond);
         m_write_queue.Push(ck);
         NotifyBackgroundThread();
         ck->Wait();
         DELETE(ck);
         return 0;
     }
     return 0;
 }
예제 #2
0
파일: iterate.c 프로젝트: nks5295/lightwave
VOID
VmDirMDBIndexIteratorFree(
    PVDIR_BACKEND_INDEX_ITERATOR    pIterator
    )
{
    PVDIR_MDB_INDEX_ITERATOR    pMdbIterator = NULL;

    if (pIterator)
    {
        pMdbIterator = (PVDIR_MDB_INDEX_ITERATOR)pIterator->pIterator;
        if (pMdbIterator)
        {
            if (pMdbIterator->pCursor)
            {
                mdb_cursor_close(pMdbIterator->pCursor);
            }
            if (pMdbIterator->pTxn)
            {
                if (pMdbIterator->bAbort)
                {
                    mdb_txn_abort(pMdbIterator->pTxn);
                }
                else
                {
                    mdb_txn_commit(pMdbIterator->pTxn);
                }
            }
            VMDIR_SAFE_FREE_MEMORY(pMdbIterator->pszVal);
            VMDIR_SAFE_FREE_MEMORY(pMdbIterator);
        }
        VMDIR_SAFE_FREE_MEMORY(pIterator);
    }
}
    void write(const std::string& keystr, const std::string& value) {
        if (use_leveldb) {  // leveldb
            batch->Put(keystr, value);
        } else {  // lmdb
            mdb_data.mv_size = value.size();
            mdb_data.mv_data = const_cast<char*>(&value[0]);
            mdb_key.mv_size = keystr.size();
            mdb_key.mv_data = const_cast<char*>(&keystr[0]);
            CHECK_EQ(mdb_put(mdb_txn, mdb_dbi, &mdb_key, &mdb_data, 0), MDB_SUCCESS)
            << "mdb_put failed";
        }

        if (++count % 1000 == 0) {
            // Commit txn
            if (use_leveldb) {  // leveldb
                db->Write(leveldb::WriteOptions(), batch);
                delete batch;
                batch = new leveldb::WriteBatch();
            } else {  // lmdb
                CHECK_EQ(mdb_txn_commit(mdb_txn), MDB_SUCCESS)
                << "mdb_txn_commit failed";
                CHECK_EQ(mdb_txn_begin(mdb_env, NULL, 0, &mdb_txn), MDB_SUCCESS)
                << "mdb_txn_begin failed";
            }
            LOG(ERROR) << "Processed " << count << " files.";
        }
    }
예제 #4
0
파일: yota_test2.c 프로젝트: ReOpen/libmdbx
static void db_connect() {
	MDB_dbi dbi_session;
	MDB_dbi dbi_session_id;
	MDB_dbi dbi_event;
	MDB_dbi dbi_ip;

	LMDB_CHECK(mdb_env_create(&env));
	LMDB_CHECK(mdb_env_set_mapsize(env, 300000L * 4096L));
	LMDB_CHECK(mdb_env_set_maxdbs(env, 30));
#if defined(MDBX_LIFORECLAIM)
	LMDB_CHECK(mdb_env_open(env, opt_db_path, MDB_CREATE | MDB_NOSYNC | MDB_WRITEMAP | MDBX_LIFORECLAIM, 0664));
#else
	LMDB_CHECK(mdb_env_open(env, opt_db_path, MDB_CREATE | MDB_NOSYNC | MDB_WRITEMAP, 0664));
#endif
	MDB_txn *txn;

	// transaction init
	LMDB_CHECK(mdb_txn_begin(env, NULL, 0, &txn));
	// open database in read-write mode
	LMDB_CHECK(mdb_dbi_open(txn, "session", MDB_CREATE, &dbi_session));
	LMDB_CHECK(mdb_dbi_open(txn, "session_id", MDB_CREATE, &dbi_session_id));
	LMDB_CHECK(mdb_dbi_open(txn, "event", MDB_CREATE, &dbi_event));
	LMDB_CHECK(mdb_dbi_open(txn, "ip", MDB_CREATE, &dbi_ip));
	// transaction commit
	LMDB_CHECK(mdb_txn_commit(txn));
	printf("Connection open\n");
}
예제 #5
0
bool LmdbDataset<K, V, KCoder, VCoder>::commit() {
  DLOG(INFO) << "LMDB: Commit";

  CHECK_NOTNULL(write_txn_);

  int retval;
  retval = mdb_txn_commit(write_txn_);
  if (MDB_SUCCESS != retval) {
    LOG(ERROR) << "mdb_txn_commit failed " << mdb_strerror(retval);
    return false;
  }

  mdb_txn_abort(read_txn_);

  retval = mdb_txn_begin(env_, NULL, 0, &write_txn_);
  if (MDB_SUCCESS != retval) {
    LOG(ERROR) << "mdb_txn_begin failed " << mdb_strerror(retval);
    return false;
  }

  retval = mdb_txn_begin(env_, NULL, MDB_RDONLY, &read_txn_);
  if (MDB_SUCCESS != retval) {
    LOG(ERROR) << "mdb_txn_begin failed " << mdb_strerror(retval);
    return false;
  }

  return true;
}
예제 #6
0
int mail_cache_db_get_size(struct mail_cache_db * cache_db,
    const void * key, size_t key_len, size_t * pvalue_len)
{
  int r;
  MDB_env *env;
  MDB_txn *txn;
  MDB_dbi dbi;
  MDB_val mdb_key;
  MDB_val mdb_val;

  env = cache_db->internal_database;

  mdb_key.mv_size = key_len;
  mdb_key.mv_data = (void *) key;

  r = mdb_txn_begin(env, NULL, 0, &txn);
  if (r != 0)
    return -1;
  r = mdb_dbi_open(txn, NULL, 0, &dbi);
  if (r != 0)
    goto error;

  r = mdb_get(txn, dbi, &mdb_key, &mdb_val);
  if (r != 0)
    goto error;

  * pvalue_len = mdb_val.mv_size;
  mdb_txn_commit(txn);
  return 0;

  error:
    mdb_txn_abort(txn);
    return -1;
}
예제 #7
0
common::Error LmdbRaw::put(const std::string& key, const std::string& value) {
  MDB_val mkey;
  mkey.mv_size = key.size();
  mkey.mv_data = (void*)key.c_str();
  MDB_val mval;
  mval.mv_size = value.size();
  mval.mv_data = (void*)value.c_str();

  MDB_txn *txn = NULL;
  int rc = mdb_txn_begin(lmdb_->env, NULL, 0, &txn);
  if (rc == LMDB_OK) {
    rc = mdb_put(txn, lmdb_->dbir, &mkey, &mval, 0);
    if (rc == LMDB_OK) {
        rc = mdb_txn_commit(txn);
    } else {
        mdb_txn_abort(txn);
    }
  }

  if (rc != LMDB_OK) {
    char buff[1024] = {0};
    common::SNPrintf(buff, sizeof(buff), "put function error: %s", mdb_strerror(rc));
    return common::make_error_value(buff, common::ErrorValue::E_ERROR);
  }

  return common::Error();
}
예제 #8
0
파일: lmdb_engine.cpp 프로젝트: mrkeng/ardb
 int LMDBEngine::Get(const Slice& key, std::string* value, bool fill_cache)
 {
     MDB_val k, v;
     k.mv_data = const_cast<char*>(key.data());
     k.mv_size = key.size();
     int rc;
     LMDBContext& holder = m_ctx_local.GetValue();
     MDB_txn *txn = holder.readonly_txn;
     if (NULL == holder.readonly_txn)
     {
         rc = mdb_txn_begin(m_env, NULL, MDB_RDONLY, &txn);
         if (rc != 0)
         {
             ERROR_LOG("Failed to create txn for get for reason:%s", mdb_strerror(rc));
             return -1;
         }
     }
     rc = mdb_get(txn, m_dbi, &k, &v);
     if (NULL == holder.readonly_txn)
     {
         mdb_txn_commit(txn);
     }
     if (0 == rc && NULL != value && NULL != v.mv_data)
     {
         value->assign((const char*) v.mv_data, v.mv_size);
     }
     return rc;
 }
예제 #9
0
counter_t *counter_init(const char *path, uint64_t readers) {
    counter_t *lc = NULL;
    if((lc = calloc(1, sizeof(counter_t))) == NULL) {
        perror("calloc");
        return NULL;
    }

    // Setup and open the lmdb enviornment
    MDB_CHECK(mdb_env_create(&lc->env), MDB_SUCCESS, NULL);
    MDB_CHECK(mdb_env_set_maxreaders(lc->env, readers), MDB_SUCCESS, NULL);
    MDB_CHECK(mdb_env_set_mapsize(lc->env, MDB_MAPSIZE), MDB_SUCCESS, NULL);
    MDB_CHECK(mdb_env_open(lc->env, path, MDB_WRITEMAP | MDB_MAPASYNC | MDB_NOSUBDIR, 0664), MDB_SUCCESS, NULL);

    MDB_txn *txn = NULL;
    MDB_CHECK(mdb_txn_begin(lc->env, NULL, 0, &txn), MDB_SUCCESS, NULL);

    if((lc->dbi = calloc(1, sizeof(MDB_dbi))) == NULL) {
        perror("calloc");
        return NULL;
    }

    MDB_CHECK(mdb_dbi_open(txn, NULL, 0, lc->dbi), MDB_SUCCESS, NULL);
    mdb_txn_commit(txn);
    return lc;
}
예제 #10
0
/**
 * This function works in stages. First we clean up the given key to prevent
 * any trickery by users. Then we retrieve the existing value, increment it,
 * and store it back in the db.
 */
uint64_t counter_inc(counter_t *lc, const char *key) {
    char clean_key[KEYSZ] = { 0 };
    key_clean(clean_key, key);
    clean_key[15] = '\0';

    MDB_val mkey, data, update;
    MDB_txn *txn = NULL;

    mkey.mv_size = (KEYSZ) * sizeof(char);
    mkey.mv_data = (void *)clean_key;

    mdb_txn_begin(lc->env, NULL, 0, &txn);
    uint64_t stored_counter = 0;
    // We only care about success here, since if mdb_get fails it is because
    // the key doesn't exist and we need to make it.
    if(mdb_get(txn, *lc->dbi, &mkey, &data) == MDB_SUCCESS) {
        stored_counter = *(uint64_t *)data.mv_data;
    }
    stored_counter++;
    update.mv_size = sizeof(uint64_t);
    update.mv_data = (void *)&stored_counter;
    if(mdb_put(txn, *lc->dbi, &mkey, &update, 0) != MDB_SUCCESS) {
        perror("mdb_put");
        mdb_txn_abort(txn);
        return 0;
    }

    MDB_CHECK(mdb_txn_commit(txn), MDB_SUCCESS, 0);
    return stored_counter;
}
예제 #11
0
파일: gcache.c 프로젝트: Miradorn/recorder
long gcache_get(struct gcache *gc, char *k, char *buf, long buflen)
{
	MDB_val key, data;
	MDB_txn *txn;
	int rc;
	long len = -1;

	if (gc == NULL)
		return (-1);

	rc = mdb_txn_begin(gc->env, NULL, MDB_RDONLY, &txn);
	if (rc) {
		olog(LOG_ERR, "gcache_get: mdb_txn_begin: (%d) %s", rc, mdb_strerror(rc));
		return (-1);
	}

	key.mv_data = k;
	key.mv_size = strlen(k);

	rc = mdb_get(txn, gc->dbi, &key, &data);
	if (rc != 0) {
		if (rc != MDB_NOTFOUND) {
			printf("get: %s\n", mdb_strerror(rc));
		} else {
			// printf(" [%s] not found\n", k);
		}
	} else {
		len =  (data.mv_size < buflen) ? data.mv_size : buflen;
		memcpy(buf, data.mv_data, len);
		// printf("%s\n", (char *)data.mv_data);
	}
	mdb_txn_commit(txn);
	return (len);
}
예제 #12
0
파일: gcache.c 프로젝트: Miradorn/recorder
int gcache_del(struct gcache *gc, char *keystr)
{
	int rc;
	MDB_val key;
	MDB_txn *txn;

	rc = mdb_txn_begin(gc->env, NULL, 0, &txn);
	if (rc != 0) {
		olog(LOG_ERR, "gcache_del: mdb_txn_begin: %s", mdb_strerror(rc));
		return (rc);
	}

	key.mv_data	= keystr;
	key.mv_size	= strlen(keystr);

	rc = mdb_del(txn, gc->dbi, &key, NULL);
	if (rc != 0 && rc != MDB_NOTFOUND) {
		olog(LOG_ERR, "gcache_del: mdb_del: %s", mdb_strerror(rc));
		/* fall through to commit */
	}

	rc = mdb_txn_commit(txn);
	if (rc) {
		olog(LOG_ERR, "gcache_del: mdb_txn_commit: (%d) %s", rc, mdb_strerror(rc));
		mdb_txn_abort(txn);
	}
	return (rc);
}
예제 #13
0
int     slmdb_close(SLMDB *slmdb)
{
    int     status = 0;

    /*
     * Finish an open bulk transaction. If slmdb_recover() returns after a
     * bulk-transaction error, then it was unable to recover.
     */
    if (slmdb->txn != 0
	&& (status = mdb_txn_commit(slmdb->txn)) != 0)
	status = slmdb_recover(slmdb, status);

    /*
     * Clean up after an unfinished sequence() operation.
     */
    if (slmdb->cursor != 0)
	slmdb_cursor_close(slmdb);

    mdb_env_close(slmdb->env);

    /*
     * Clean up the saved key information.
     */
    if (HAVE_SLMDB_SAVED_KEY(slmdb))
	slmdb_saved_key_free(slmdb);

    SLMDB_API_RETURN(slmdb, status);
}
예제 #14
0
int     slmdb_del(SLMDB *slmdb, MDB_val *mdb_key)
{
    MDB_txn *txn;
    int     status;

    /*
     * Start a write transaction if there's no bulk-mode txn.
     */
    if (slmdb->txn)
	txn = slmdb->txn;
    else if ((status = slmdb_txn_begin(slmdb, 0, &txn)) != 0)
	SLMDB_API_RETURN(slmdb, status);

    /*
     * Do the update.
     */
    if ((status = mdb_del(txn, slmdb->dbi, mdb_key, (MDB_val *) 0)) != 0) {
	mdb_txn_abort(txn);
	if (status != MDB_NOTFOUND) {
	    if ((status = slmdb_recover(slmdb, status)) == 0)
		status = slmdb_del(slmdb, mdb_key);
	    SLMDB_API_RETURN(slmdb, status);
	}
    }

    /*
     * Commit the transaction if it's not the bulk-mode txn.
     */
    if (status == 0 && slmdb->txn == 0 && (status = mdb_txn_commit(txn)) != 0
	&& (status = slmdb_recover(slmdb, status)) == 0)
	status = slmdb_del(slmdb, mdb_key);

    SLMDB_API_RETURN(slmdb, status);
}
예제 #15
0
파일: init.c 프로젝트: vmware/lightwave
DWORD
MDBDropDB(
    PVDIR_MDB_DB pDB,
    VDIR_DB      mdbDBi
    )
{
    DWORD               dwError = 0;
    MDB_txn*            pTxn = NULL;

    assert(pDB);

    dwError = mdb_txn_begin(pDB->mdbEnv, NULL, BE_DB_FLAGS_ZERO, &pTxn);
    BAIL_ON_VMDIR_ERROR(dwError);

    dwError = mdb_drop(pTxn, mdbDBi, 1);
    BAIL_ON_VMDIR_ERROR(dwError);

    dwError = mdb_txn_commit(pTxn);
    pTxn = NULL;
    BAIL_ON_VMDIR_ERROR(dwError);

cleanup:
    return dwError;

error:
    if (pTxn)
    {
        mdb_txn_abort(pTxn);
        pTxn = NULL;
    }
    goto cleanup;
}
예제 #16
0
파일: lmdb_engine.cpp 프로젝트: mrkeng/ardb
    const std::string LMDBEngine::Stats()
    {
        MDB_stat stat;
        MDB_txn* txn;
        int rc = mdb_txn_begin(m_env, NULL, 0, &txn);
        if (0 == rc)
        {
            mdb_stat(txn, m_dbi, &stat);
            mdb_txn_commit(txn);
            std::string stat_info;
            stat_info.append("lmdb version:").append(mdb_version(NULL, NULL, NULL)).append("\r\n");
            stat_info.append("db page size:").append(stringfromll(stat.ms_psize)).append("\r\n");
            stat_info.append("b-tree depath:").append(stringfromll(stat.ms_depth)).append("\r\n");
            stat_info.append("branch pages:").append(stringfromll(stat.ms_branch_pages)).append("\r\n");
            stat_info.append("leaf pages:").append(stringfromll(stat.ms_leaf_pages)).append("\r\n");
            stat_info.append("overflow oages:").append(stringfromll(stat.ms_overflow_pages)).append("\r\n");
            stat_info.append("data items:").append(stringfromll(stat.ms_entries));
            return stat_info;
        }
        else
        {
            return "Failed to get lmdb's stats";
        }

    }
예제 #17
0
파일: init.c 프로젝트: vmware/lightwave
/*
 * Initialize ENTRYID and USN sequence.
 */
static
DWORD
MDBInitSequence(
    PVDIR_MDB_DB pDB,
    VDIR_DB      mdbDbi
    )
{
    DWORD           dwError = 0;
    PVDIR_DB_TXN    pTxn = NULL;
    VDIR_DB_DBT     key = {0};
    VDIR_DB_DBT     value = {0};
    unsigned char   EidBytes[sizeof( ENTRYID )] = {0};
    ENTRYID         initEIDValue = ENTRY_ID_SEQ_INITIAL_VALUE;
    ENTRYID         initUNSValue = USN_SEQ_INITIAL_VALUE;

    assert(pDB);

    dwError = mdb_txn_begin( pDB->mdbEnv, NULL, BE_DB_FLAGS_ZERO, &pTxn );
    BAIL_ON_VMDIR_ERROR(dwError);

    key.mv_data = &EidBytes[0];
    MDBEntryIdToDBT(BE_MDB_ENTRYID_SEQ_KEY, &key);

    dwError =  mdb_get(pTxn, mdbDbi, &key, &value);
    if (dwError == MDB_NOTFOUND)
    {
        // first time, initialize two sequence records
        value.mv_data = &initEIDValue;
        value.mv_size = sizeof(initEIDValue);

        // set entryid sequence record
        dwError = mdb_put(pTxn, mdbDbi, &key, &value,  MDB_NOOVERWRITE);
        BAIL_ON_VMDIR_ERROR(dwError);

        MDBEntryIdToDBT(BE_MDB_USN_SEQ_KEY, &key);
        value.mv_data = &initUNSValue;
        value.mv_size = sizeof(initUNSValue);

        // set usn sequence record
        dwError = mdb_put(pTxn, mdbDbi, &key, &value, MDB_NOOVERWRITE);
        BAIL_ON_VMDIR_ERROR(dwError);
    }

    dwError = mdb_txn_commit(pTxn);
    pTxn = NULL;
    BAIL_ON_VMDIR_ERROR(dwError);

cleanup:

    return dwError;

error:

    if (pTxn)
    {
        mdb_txn_abort(pTxn);
    }

    goto cleanup;
}
예제 #18
0
파일: lmdb_engine.cpp 프로젝트: mrkeng/ardb
 int LMDBEngine::Del(const Slice& key)
 {
     LMDBContext& holder = m_ctx_local.GetValue();
     MDB_txn *txn = holder.readonly_txn;
     if (NULL == txn || holder.batch_write == 0)
     {
         MDB_val k;
         k.mv_data = const_cast<char*>(key.data());
         k.mv_size = key.size();
         mdb_txn_begin(m_env, NULL, 0, &txn);
         mdb_del(txn, m_dbi, &k, NULL);
         mdb_txn_commit(txn);
         return 0;
     }
     DelOperation* op = new DelOperation;
     op->key.assign((const char*) key.data(), key.size());
     m_write_queue.Push(op);
     if (holder.batch_write == 0)
     {
         CheckPointOperation* ck = new CheckPointOperation(holder.cond);
         m_write_queue.Push(ck);
         NotifyBackgroundThread();
         ck->Wait();
         DELETE(ck);
         return 0;
     }
     return 0;
 }
예제 #19
0
파일: mydb.cpp 프로젝트: hanllc/appsrv
bool Context::EndTxn(bool commit){
  Error(0);
  if (envHandle==nullptr){
    return false;
  }
  else if (txnHandle==nullptr){
    return false;
  }
  else if (commit==false){
    mdb_txn_abort(txnHandle);
    txnHandle=nullptr;
    return true;
  }
  else{
    int commit = mdb_txn_commit(txnHandle);
    if (commit!=0){
      Error(commit);
      txnHandle=nullptr;
      return false;
    }
    else {
      txnHandle=nullptr;
      return true;
    }
  }
}
예제 #20
0
static void unlock_write_txn(int nEnv, char syncForce, char *commit)
{
	int i;

	if (!g_tsd_wmdb)
		return;

	++g_tsd_wmdb->usageCount;
	if (*commit || syncForce)
	{
		if (mdb_txn_commit(g_tsd_wmdb->txn) != MDB_SUCCESS)
			mdb_txn_abort(g_tsd_wmdb->txn);
		g_tsd_wmdb->txn = NULL;
		g_tsd_wmdb->usageCount = 0;
		
		if (syncForce)
			mdb_env_sync(g_tsd_wmdb->env,1);

		if (syncForce)
			++g_pd->syncNumbers[nEnv];
		*commit = 1;
	}
	// else
	// 	DBG("UNLOCK %u",g_tsd_wmdb->usageCount);
	g_tsd_cursync = g_pd->syncNumbers[nEnv];
	g_tsd_wmdb = NULL;
}
예제 #21
0
파일: lmdb_stubs.c 프로젝트: 8l/pijul
CAMLprim value caml_mdb_txn_commit(value txn){
  CAMLparam1(txn);
  if(mdb_txn_commit((MDB_txn*) txn)){
    caml_failwith("error in mdb_txn_commit");
  }
  CAMLreturn0;
}
예제 #22
0
static int slmdb_prepare(SLMDB *slmdb)
{
    int     status = 0;

    /*
     * This is called before accessing the database, or after recovery from
     * an LMDB error. Note: this code cannot recover from errors itself.
     * slmdb->txn is either the database open() transaction or a
     * freshly-created bulk-mode transaction.
     * 
     * - With O_TRUNC we make a "drop" request before updating the database.
     * 
     * - With a bulk-mode transaction we commit when the database is closed.
     */
    if (slmdb->open_flags & O_TRUNC) {
	if ((status = mdb_drop(slmdb->txn, slmdb->dbi, 0)) != 0)
	    return (status);
	if ((slmdb->slmdb_flags & SLMDB_FLAG_BULK) == 0) {
	    if ((status = mdb_txn_commit(slmdb->txn)) != 0)
		return (status);
	    slmdb->txn = 0;
	}
    } else if ((slmdb->lmdb_flags & MDB_RDONLY) != 0
	       || (slmdb->slmdb_flags & SLMDB_FLAG_BULK) == 0) {
	mdb_txn_abort(slmdb->txn);
	slmdb->txn = 0;
    }
    slmdb->api_retry_count = 0;
    return (status);
}
예제 #23
0
	int LMDBEngine::FlushWriteBatch(BatchHolder& holder)
	{
		if (NULL != holder.txn)
		{
			StringSet::iterator it = holder.dels.begin();
			while (it != holder.dels.end())
			{
				MDB_val k;
				k.mv_data = (void*) (it->c_str());
				k.mv_size = it->size();
				mdb_del(holder.txn, m_dbi, &k, NULL);
				it++;
			}
			std::map<std::string, std::string>::iterator sit =
			        holder.inserts.begin();
			while (sit != holder.inserts.end())
			{
				MDB_val k, v;
				k.mv_data = (void*) (sit->first.c_str());
				k.mv_size = sit->first.size();
				v.mv_data = (void*) (sit->second.c_str());
				v.mv_size = sit->second.size();
				mdb_put(holder.txn, m_dbi, &k, &v, 0);
				sit++;
			}
			mdb_txn_commit(holder.txn);
			holder.txn = NULL;
			holder.Clear();
		}
		return 0;
	}
예제 #24
0
파일: accurate_lmdb.c 프로젝트: AlD/bareos
bool B_ACCURATE_LMDB::end_load(JCR *jcr)
{
   int result;

   /*
    * Commit any pending write transactions.
    */
   if (m_db_rw_txn) {
      result = mdb_txn_commit(m_db_rw_txn);
      if (result != 0) {
         Jmsg1(jcr, M_FATAL, 0, _("Unable close write transaction: %s\n"), mdb_strerror(result));
         return false;
      }
      result = mdb_txn_begin(m_db_env, NULL, 0, &m_db_rw_txn);
      if (result != 0) {
         Jmsg1(jcr, M_FATAL, 0, _("Unable to create write transaction: %s\n"), mdb_strerror(result));
         return false;
      }
   }

   /*
    * From now on we also will be doing read transactions so create a read transaction context.
    */
   if (!m_db_ro_txn) {
      result = mdb_txn_begin(m_db_env, NULL, MDB_RDONLY, &m_db_ro_txn);
      if (result != 0) {
         Jmsg1(jcr, M_FATAL, 0, _("Unable to create read transaction: %s\n"), mdb_strerror(result));
         return false;
      }
   }

   return true;
}
예제 #25
0
파일: jmdb.c 프로젝트: cirnoworks/jmdb
/*
 * Class:     jmdb_DatabaseWrapper
 * Method:    txnCommit
 * Signature: (J)V
 */
JNIEXPORT void JNICALL Java_jmdb_DatabaseWrapper_txnCommit(JNIEnv *vm,
		jclass clazz, jlong txnL) {
	int code = mdb_txn_commit((MDB_txn*) txnL);
	if (code) {
		throwDatabaseException(vm, code);
	}
}
예제 #26
0
파일: kvdb_lmdb.c 프로젝트: uukuguy/legolas
int kvdb_lmdb_get(kvdb_t *kvdb, const char *key, uint32_t klen, void **ppVal, uint32_t *pnVal)
{
    kvdb_lmdb_t *lmdb = (kvdb_lmdb_t*)kvdb;
    kvenv_lmdb_t *kvenv_lmdb = (kvenv_lmdb_t*)kvdb->kvenv;

    MDB_val m_key;
    MDB_txn *txn;

    m_key.mv_size = klen;
    m_key.mv_data = (void*)key;

    int rc = mdb_txn_begin(kvenv_lmdb->env, NULL, MDB_RDONLY, &txn);
    if( rc==0 ){
        MDB_val m_val = {0, 0};
        rc = mdb_get(txn, lmdb->dbi, &m_key, &m_val);
        if ( rc == 0 ) {
            uint32_t nVal = m_val.mv_size;
            char *pVal = m_val.mv_data;
            char *result = (char*)zmalloc(nVal);
            memcpy(result, pVal, nVal);
            *ppVal = result;
            *pnVal = nVal;
        } else if( rc==MDB_NOTFOUND ){
            rc = 0;
            *ppVal = 0;
            *pnVal = -1;
        }else{
            error_log("kvdb_lmdb_get() failure. error: %s", mdb_strerror(rc));
        }
        mdb_txn_commit(txn);
    }

    return rc;
}
예제 #27
0
파일: kvdb_lmdb.c 프로젝트: uukuguy/legolas
int kvdb_lmdb_put(kvdb_t *kvdb, const char *key, uint32_t klen, void *value, uint32_t vlen)
{
    kvdb_lmdb_t *lmdb = (kvdb_lmdb_t*)kvdb;
    kvenv_lmdb_t *kvenv_lmdb = (kvenv_lmdb_t*)kvdb->kvenv;

    MDB_val m_val;
    MDB_val m_key;
    MDB_txn *txn;

    m_val.mv_size = vlen; 
    m_val.mv_data = value;
    m_key.mv_size = klen; 
    m_key.mv_data = (void*)key;

    int rc = mdb_txn_begin(kvenv_lmdb->env, NULL, 0, &txn);
    if( rc==0 ){
        rc = mdb_put(txn, lmdb->dbi, &m_key, &m_val, 0);
        if( rc==0 ){
            rc = mdb_txn_commit(txn);
        }else{
            error_log("kvdb_lmdb_put() failure. error: %s", mdb_strerror(rc));
            mdb_txn_abort(txn);
        }
    }

    return rc;
}
예제 #28
0
int main(int argc,char * argv[])
{
	int rc;
	GLMDB_env *genv;
	printf("opening graph!\n");
	rc = openGraph(&genv, "/home/pieter/Downloads/glmdb-blueprints/src/main/native/testdb");
	if (rc != 0) {
		printf("opening graph failure  = %i!\n", rc);
		goto fail;
	}

	rc = addVertexAnd2Properties(genv);
	if (rc != 0) {
		goto fail;
	}

	printf("before traverseEdgeDb\n");
	MDB_txn *txn;
	rc = mdb_txn_begin(genv->env, NULL, 1, &txn);
	if (rc != 0) {
		printf("begin transaction failure  = %i!\n", rc);
		goto fail;
	}

	traverseEdgeDb(genv, txn);

	mdb_txn_commit(txn);

	fail:
	printf("closing graph!\n");
	closeGraph(genv);
	return 0;
}
예제 #29
0
파일: accurate_lmdb.c 프로젝트: AlD/bareos
bool B_ACCURATE_LMDB::send_base_file_list(JCR *jcr)
{
   int result;
   int32_t LinkFIc;
   FF_PKT *ff_pkt;
   MDB_cursor *cursor;
   MDB_val key, data;
   bool retval = false;
   accurate_payload *payload;
   int stream = STREAM_UNIX_ATTRIBUTES;

   if (!jcr->accurate || jcr->getJobLevel() != L_FULL) {
      return true;
   }

   /*
    * Commit any pending write transactions.
    */
   if (m_db_rw_txn) {
      result = mdb_txn_commit(m_db_rw_txn);
      if (result != 0) {
         Jmsg1(jcr, M_FATAL, 0, _("Unable close write transaction: %s\n"), mdb_strerror(result));
         goto bail_out;
      }
      m_db_rw_txn = NULL;
   }

   ff_pkt = init_find_files();
   ff_pkt->type = FT_BASE;

   result = mdb_cursor_open(m_db_ro_txn, m_db_dbi, &cursor);
   if (result == 0) {
      while ((result = mdb_cursor_get(cursor, &key, &data, MDB_NEXT)) == 0) {
         payload = (accurate_payload *)data.mv_data;
         if (bit_is_set(payload->filenr, m_seen_bitmap)) {
            Dmsg1(dbglvl, "base file fname=%s\n", key.mv_data);
            decode_stat(payload->lstat, &ff_pkt->statp, sizeof(struct stat), &LinkFIc); /* decode catalog stat */
            ff_pkt->fname = (char *)key.mv_data;
            encode_and_send_attributes(jcr, ff_pkt, stream);
         }
      }
      mdb_cursor_close(cursor);
   } else {
      Jmsg1(jcr, M_FATAL, 0, _("Unable create cursor: %s\n"), mdb_strerror(result));
   }

   mdb_txn_reset(m_db_ro_txn);
   result = mdb_txn_renew(m_db_ro_txn);
   if (result != 0) {
      Jmsg1(jcr, M_FATAL, 0, _("Unable to renew read transaction: %s\n"), mdb_strerror(result));
      goto bail_out;
   }

   retval = true;

bail_out:
   term_find_files(ff_pkt);
   return retval;
}
예제 #30
0
파일: its7733.c 프로젝트: AN2016/py-lmdb
void new_txn(void)
{
    if(txn) {
        fprintf(stderr, "commit\n");
        check(mdb_txn_commit(txn));
    }
    check(mdb_txn_begin(env, NULL, 0, &txn));
}