bool ehgraph_transfer_info(ehgraph_t* dest, ehgraph_t* src, size_t lim) {
  bool bRet = false;

  do {

    CheckNotNULL(src);
    CheckNotNULL(dest);
    if (dest->ptrdim != src->ptrdim || dest->nLinks != src->nLinks) {
      DB_ERROR("graphs are not compatible");
      break;
    }

    if (lim > (src->size + src->ptrdim) || lim > (dest->size + dest->ptrdim)) {
      DB_ERROR("invalid arg");
      break;
    }

    size_t nL = src->nLinks;

    bRet = true;
    for (size_t i = 0; i < lim && bRet; ++i) 
      bRet = ehgraph_transfer_node_info(dest, i, src, i);
    
  } while(0);
  
  return bRet;
}
Beispiel #2
0
int DbChannel::send_request(Dbt *request, u_int32_t nrequest,
    Dbt *response, db_timeout_t timeout, u_int32_t flags)
{
	DB_CHANNEL *dbchannel = unwrap(this);
	DB_ENV *dbenv = unwrap(dbenv_);
	DBT *dbtlist;
	int i, ret;

	ret = __os_malloc(dbenv->env, sizeof(DBT) * nrequest, &dbtlist);
	if (ret != 0) {
		DB_ERROR(dbenv_, "DbChannel::send_request", ret,
		    ON_ERROR_UNKNOWN);
		return (ret);
	}

	for (i = 0; i < (int)nrequest; i++)
		memcpy(&dbtlist[i], request[i].get_DBT(), sizeof(DBT));

	if ((ret = dbchannel->send_request(dbchannel, dbtlist, nrequest,
	    response->get_DBT(), timeout, flags)) != 0)
		DB_ERROR(dbenv_, "DbChannel::send_request", ret,
		    ON_ERROR_UNKNOWN);

	__os_free(dbenv->env, dbtlist);

	return (ret);
}
Beispiel #3
0
//static
int Db::_append_recno_intercept(DB *db, DBT *data, db_recno_t recno)
{
	int err;

	if (db == 0) {
		DB_ERROR("Db::append_recno_callback", EINVAL, ON_ERROR_UNKNOWN);
		return (EINVAL);
	}
	Db *cxxdb = (Db *)db->cj_internal;
	if (cxxdb == 0) {
		DB_ERROR("Db::append_recno_callback", EINVAL, ON_ERROR_UNKNOWN);
		return (EINVAL);
	}
	if (cxxdb->append_recno_callback_ == 0) {
		DB_ERROR("Db::append_recno_callback", EINVAL, cxxdb->error_policy());
		return (EINVAL);
	}

	// making these copies is slow but portable.
	// Another alternative is to cast the DBT* manufactured
	// by the C layer to a Dbt*.  It 'should be' safe since
	// Dbt is a thin shell over DBT, adding no extra data,
	// but is nonportable, and could lead to errors if anything
	// were added to the Dbt class.
	//
	Dbt cxxdbt;
	memcpy((DBT *)&cxxdbt, data, sizeof(DBT));
	err = (*cxxdb->append_recno_callback_)(cxxdb, &cxxdbt, recno);
	memcpy(data, (DBT *)&cxxdbt, sizeof(DBT));
	return (err);
}
Beispiel #4
0
relation_t *
relation_load(char *name)
{
  relation_t *rel;

  rel = relation_find(name);
  if(rel != NULL) {
    rel->references++;
    goto end;
  }

  rel = relation_allocate();
  if(rel == NULL) {
    return NULL;
  }

  if(DB_ERROR(storage_get_relation(rel, name))) {
    memb_free(&relations_memb, rel);
    return NULL;
  }

  memcpy(rel->name, name, sizeof(rel->name));
  rel->name[sizeof(rel->name) - 1] = '\0';
  rel->references = 1;
  list_add(relations, rel);

end:
  if(rel->dir == DB_STORAGE && DB_ERROR(storage_load(rel))) {
    relation_release(rel);
    return NULL;
  }

  return rel;
}
Beispiel #5
0
db_result_t
relation_rename(char *old_name, char *new_name)
{
  if(DB_ERROR(relation_remove(new_name, 0)) ||
     DB_ERROR(storage_rename_relation(old_name, new_name))) {
    return DB_STORAGE_ERROR;
  }

  return DB_OK;
}
Beispiel #6
0
// If an error occurred during the constructor, report it now.
// Otherwise, call the underlying DB->open method.
//
int DbEnv::open(const char *db_home, u_int32_t flags, int mode)
{
	DB_ENV *env = unwrap(this);
	int err;

	if ((err = construct_error_) != 0)
		DB_ERROR("Db::open", err, error_policy());
	else if ((err = env->open(env, db_home, flags, mode)) != 0)
		DB_ERROR("DbEnv::open", err, error_policy());

	return (err);
}
Beispiel #7
0
// If an error occurred during the constructor, report it now.
// Otherwise, call the underlying DB->open method.
//
int Db::open(const char *file, const char *database,
	     DBTYPE type, u_int32_t flags, int mode)
{
	int err;
	DB *db = unwrap(this);

	if ((err = construct_error_) != 0)
		DB_ERROR("Db::open", construct_error_, error_policy());
	else if ((err = db->open(db, file, database, type, flags, mode)) != 0)
		DB_ERROR("Db::open", err, error_policy());

	return (err);
}
Beispiel #8
0
void DbEnv::_paniccall_intercept(DB_ENV *env, int errval)
{
	if (env == 0) {
		DB_ERROR("DbEnv::paniccall_callback", EINVAL, ON_ERROR_UNKNOWN);
	}
	DbEnv *cxxenv = (DbEnv *)env->cj_internal;
	if (cxxenv == 0) {
		DB_ERROR("DbEnv::paniccall_callback", EINVAL, ON_ERROR_UNKNOWN);
	}
	if (cxxenv->paniccall_callback_ == 0) {
		DB_ERROR("DbEnv::paniccall_callback", EINVAL, cxxenv->error_policy());
	}
	(*cxxenv->paniccall_callback_)(cxxenv, errval);
}
Beispiel #9
0
int Db::sync(u_int32_t flags)
{
    DB *db = unwrap(this);
    if (!db) {
        DB_ERROR("Db::sync", EINVAL);
        return EINVAL;
    }
    int err;
    if ((err = db->sync(db, flags)) != 0) {
        DB_ERROR("Db::sync", err);
        return err;
    }
    return 0;
}
Beispiel #10
0
int Db::fd(int *fdp)
{
    DB *db = unwrap(this);
    if (!db) {
        DB_ERROR("Db::fd", EINVAL);
        return EINVAL;
    }
    int err;
    if ((err = db->fd(db, fdp)) != 0) {
        DB_ERROR("Db::fd", err);
        return err;
    }
    return 0;
}
Beispiel #11
0
int Db::stat(void *sp, void *(*db_malloc)(size_t), u_int32_t flags)
{
    DB *db = unwrap(this);
    if (!db) {
        DB_ERROR("Db::stat", EINVAL);
        return EINVAL;
    }
    int err;
    if ((err = db->stat(db, sp, db_malloc, flags)) != 0) {
        DB_ERROR("Db::stat", err);
        return err;
    }
    return 0;
}
Beispiel #12
0
int Db::stat(void *sp, db_malloc_fcn_type db_malloc_fcn, u_int32_t flags)
{
	int err;
	DB *db = unwrap(this);

	if (!db) {
		DB_ERROR("Db::stat", EINVAL, error_policy());
		return (EINVAL);
	}
	if ((err = db->stat(db, sp, db_malloc_fcn, flags)) != 0) {
		DB_ERROR("Db::stat", err, error_policy());
		return (err);
	}
	return (0);
}
Beispiel #13
0
int Db::sync(u_int32_t flags)
{
	int err;
	DB *db = unwrap(this);

	if (!db) {
		DB_ERROR("Db::sync", EINVAL, error_policy());
		return (EINVAL);
	}
	if ((err = db->sync(db, flags)) != 0 && err != DB_INCOMPLETE) {
		DB_ERROR("Db::sync", err, error_policy());
		return (err);
	}
	return (err);
}
Beispiel #14
0
int Db::upgrade(const char *name, u_int32_t flags)
{
	int err;
	DB *db = unwrap(this);

	if (!db) {
		DB_ERROR("Db::upgrade", EINVAL, error_policy());
		return (EINVAL);
	}
	if ((err = db->upgrade(db, name, flags)) != 0) {
		DB_ERROR("Db::upgrade", err, error_policy());
		return (err);
	}
	return (0);
}
Beispiel #15
0
tuple_id_t
relation_cardinality(relation_t *rel)
{
  tuple_id_t tuple_id;


  if(rel->cardinality != INVALID_TUPLE) {
    return rel->cardinality;
  }

  if(!RELATION_HAS_TUPLES(rel)) {
    return 0;
  }

  if(DB_ERROR(storage_get_row_amount(rel, &tuple_id))) {
    return INVALID_TUPLE;
  }

  rel->cardinality = tuple_id;

  PRINTF("DB: Relation %s has cardinality %lu\n", rel->name,
	(unsigned long)tuple_id);

  return tuple_id;
}
ehgraph_t* ehgraph_copy(ehgraph_t* graph) {
  bool bRet = false;
  ehgraph_t* ret = NULL;

  do {
    CheckNotNULL(graph);

    ret = ehgraph_alloc(NULL, graph->size, graph->ptrdim, graph->nLinks);
    if (NULL == ret) {
      DB_ERROR("allocation error");
      break;
    }

    ret->closed = graph->closed;
    ret->isTop = false;
    ret->isBottom = false;
    CheckedCall(ehgraph_transfer_info(ret, graph, graph->ptrdim + graph->size));
    bRet = true;
  } while(0);

  if (!bRet) 
    SafeFree(ret);
   
  return ret;
}
Beispiel #17
0
int Db::verify(const char *name, const char *subdb,
	       ostream *ostr, u_int32_t flags)
{
	int err;
	DB *db = unwrap(this);

	if (!db) {
		DB_ERROR("Db::verify", EINVAL, error_policy());
		return (EINVAL);
	}
	if ((err = __db_verify_internal(db, name, subdb, ostr,
					_verify_callback_c, flags)) != 0) {
		DB_ERROR("Db::verify", err, error_policy());
		return (err);
	}
	return (0);
}
ehgraph_t* permute_graph(ehgraph_t* graph, int* perm) {
  ehgraph_t* ret = NULL, *b = NULL;

  do {
    CheckNotNULL(graph);
    CheckNotNULL(perm);

    if (0 != perm[0]) {
      DB_ERROR("the null element should remain unchanged in the permutation");
      break;
    }
    
    b = ehgraph_alloc(NULL, graph->size, graph->ptrdim, graph->nLinks);
    if (!b) {
      DB_ERROR("allocation failed");
      break;
    }

    b->closed = graph->closed;

    for (enode_t i = 0; i < graph->ptrdim; ++i) 
      VAR2NODE(b, i) = perm[ VAR2NODE(graph, i) ];

    for (enode_t i = 0; i < graph->size; ++i) {
      GET_NODE(b, perm[i]).inDoubleLink = GET_NODE(graph, i).inDoubleLink;
      GET_NODE(b, perm[i]).outDoubleLink = GET_NODE(graph, i).outDoubleLink;

      for (size_t l = 0; l < graph->nLinks; ++l) {
	GET_LINK(b, perm[i], l) = perm[ GET_LINK(graph, i, l) ];
	GET_NODE(b, perm[i]).superEdge[l] = GET_NODE(graph, i).superEdge[l];

	for (size_t lp = 0; lp < graph->nLinks; ++lp) {
	  GET_NODE(b, perm[i]).isPredicate[l][lp] = GET_NODE(graph, i).isPredicate[l][lp];
	  GET_NODE(b, perm[i]).predicateTarget[l][lp] = perm[ GET_NODE(graph, i).predicateTarget[l][lp] ];
	}
      }
    }
	   
    ret = b;
  } while(0);
  
  if (!ret)
    SafeFree(b);
  
  return ret;
}
Beispiel #19
0
//static
void Db::_feedback_intercept(DB *db, int opcode, int pct)
{
	if (db == 0) {
		DB_ERROR("Db::feedback_callback", EINVAL, ON_ERROR_UNKNOWN);
		return;
	}
	Db *cxxdb = (Db *)db->cj_internal;
	if (cxxdb == 0) {
		DB_ERROR("Db::feedback_callback", EINVAL, ON_ERROR_UNKNOWN);
		return;
	}
	if (cxxdb->feedback_callback_ == 0) {
		DB_ERROR("Db::feedback_callback", EINVAL, cxxdb->error_policy());
		return;
	}
	(*cxxdb->feedback_callback_)(cxxdb, opcode, pct);
}
Beispiel #20
0
int DbEnv::_recovery_init_intercept(DB_ENV *env)
{
	if (env == 0) {
		DB_ERROR("DbEnv::recovery_init_callback", EINVAL,
			 ON_ERROR_UNKNOWN);
	}
	DbEnv *cxxenv = (DbEnv *)env->cj_internal;
	if (cxxenv == 0) {
		DB_ERROR("DbEnv::recovery_init_callback", EINVAL,
			 ON_ERROR_UNKNOWN);
	}
	if (cxxenv->recovery_init_callback_ == 0) {
		DB_ERROR("DbEnv::recovery_init_callback", EINVAL,
			 cxxenv->error_policy());
	}
	return ((*cxxenv->recovery_init_callback_)(cxxenv));
}
Beispiel #21
0
void DbEnv::_feedback_intercept(DB_ENV *env, int opcode, int pct)
{
	if (env == 0) {
		DB_ERROR("DbEnv::feedback_callback", EINVAL, ON_ERROR_UNKNOWN);
		return;
	}
	DbEnv *cxxenv = (DbEnv *)env->cj_internal;
	if (cxxenv == 0) {
		DB_ERROR("DbEnv::feedback_callback", EINVAL, ON_ERROR_UNKNOWN);
		return;
	}
	if (cxxenv->feedback_callback_ == 0) {
		DB_ERROR("DbEnv::feedback_callback", EINVAL,
			 cxxenv->error_policy());
		return;
	}
	(*cxxenv->feedback_callback_)(cxxenv, opcode, pct);
}
Beispiel #22
0
// static method
int DbEnv::set_tas_spins(u_int32_t arg)
{
	int ret;

	if ((ret = db_env_set_tas_spins(arg)) != 0)
		DB_ERROR("DbEnv::set_tas_spins", ret, last_known_error_policy);

	return (ret);
}
bool ehgraph_del_pred(ehgraph_t* graph, enode_t node, size_t edge, size_t link) {
  if (NULL == graph) {
    DB_ERROR("null argument");
    return false;
  }

  GET_NODE(graph, node).isPredicate[edge][link] = false;
  return true;
}
Beispiel #24
0
// static method
int DbEnv::set_region_init(int arg)
{
	int ret;

	if ((ret = db_env_set_region_init(arg)) != 0)
		DB_ERROR("DbEnv::set_region_init", ret, last_known_error_policy);

	return (ret);
}
Beispiel #25
0
// static method
int DbEnv::set_panicstate(int arg)
{
	int ret;

	if ((ret = db_env_set_panicstate(arg)) != 0)
		DB_ERROR("DbEnv::set_panicstate", ret, last_known_error_policy);

	return (ret);
}
Beispiel #26
0
// static method
int DbEnv::set_pageyield(int arg)
{
	int ret;

	if ((ret = db_env_set_pageyield(arg)) != 0)
		DB_ERROR("DbEnv::set_pageyield", ret, last_known_error_policy);

	return (ret);
}
Beispiel #27
0
block BlockchainDB::get_block_from_height(const uint64_t& height) const
{
  blobdata bd = get_block_blob_from_height(height);
  block b;
  if (!parse_and_validate_block_from_blob(bd, b))
    throw DB_ERROR("Failed to parse block from blob retrieved from the db");

  return b;
}
Beispiel #28
0
block BlockchainDB::get_block(const crypto::hash& h) const
{
  blobdata bd = get_block_blob(h);
  block b;
  if (!parse_and_validate_block_from_blob(bd, b))
    throw DB_ERROR("Failed to parse block from blob retrieved from the db");

  return b;
}
Beispiel #29
0
int DbEnv::set_tx_timestamp(time_t *timestamp)
{
	int ret;
	DB_ENV *dbenv = unwrap(this);

	if ((ret = dbenv->set_tx_timestamp(dbenv, timestamp)) != 0)
		DB_ERROR("DbEnv::set_tx_timestamp", ret, error_policy());

	return (ret);
}
Beispiel #30
0
int DbEnv::set_verbose(u_int32_t which, int onoff)
{
	int ret;
	DB_ENV *dbenv = unwrap(this);

	if ((ret = (*(dbenv->set_verbose))(dbenv, which, onoff)) != 0)
		DB_ERROR("DbEnv::set_verbose", ret, error_policy());

	return (ret);
}