示例#1
0
void sampwrite(char *path,char *buf,size_t *sz,off_t *offset)
{
  int err;
  mode_t mode=0x81B6;
 back:
  if(err=mangoo_open(ms,path,mangoo_stream_interface,&handle))
    {
      printf("ERROR %d\n",err);
      if(err=mangoo_create(ms,path,mode,mangoo_data))
	printf("Error creating\n");
      else
	{
	  printf("File created\n");
	  goto back;
	}
    }
  else
    {
      printf("OPEN\n");
      dh = (struct dbfs_handle*)handle;
      printf("Size : %jd\n ",(intmax_t)(dh->attr_ddd.ddd_size));
      printf("Mode : %o\n ",(dh->attr_ddd.ddd_mode));
      *sz=strlen(buf)+1;
      env_open(&dbenv);
      if(err=mstream_write(handle,buf,sz,*offset))
	printf("Error while writing buf : %d\n",err);
      else
	*offset+=strlen(buf);      
      (void)dbenv->close(dbenv,0);
      (void)mangoo_close(handle);
    }
}
示例#2
0
void sampread(char *path)
{
  off_t offset=0;
  size_t sz;
  char buffer[30];
  int err;
  if(err=mangoo_open(ms,path,mangoo_stream_interface,&handle))
    {
      printf("Error Opening %d\n",err);
    }
  else
    {
      printf("OPEN\n");
      dh = (struct dbfs_handle*)handle;
      printf("Size : %jd\n ",(intmax_t)(dh->attr_ddd.ddd_size));
      printf("Mode : %o\n ",(dh->attr_ddd.ddd_mode));
      offset=0;
      sz=(size_t)(dh->attr_ddd.ddd_size);
      env_open(&dbenv);
      if(err=mstream_read(handle,buffer,&sz,offset))
	{
	  printf("Error while reading %d\n",err);
	  offset=0;
	}
      else
	puts(buffer);
      (void)dbenv->close(dbenv,0);
      (void)mangoo_close(handle);
    }

}
示例#3
0
int    B_login(int argc,char *argv[],void *extra)
{
	struct checkpt *pp;
	register struct login *logp=0;
	register Shell_t *shp;
	const char *pname;
	if(argc)
		shp = ((Shbltin_t*)extra)->shp;
	else
	{
		logp = (struct login*)extra;
		shp = logp->sh;
	}
	pp = (struct checkpt*)shp->jmplist;
	if(sh_isoption(SH_RESTRICTED))
		errormsg(SH_DICT,ERROR_exit(1),e_restricted,argv[0]);
	else
        {
		register struct argnod *arg=shp->envlist;
		register Namval_t* np;
		register char *cp;
		if(shp->subshell && !shp->subshare)
			sh_subfork();
		if(logp && logp->clear)
		{
#ifdef _ENV_H
			env_close(shp->env);
			shp->env = env_open((char**)0,3);
#else
			nv_scan(shp->var_tree,noexport,0,NV_EXPORT,NV_EXPORT);
#endif
		}
		while(arg)
		{
			if((cp=strchr(arg->argval,'=')) &&
				(*cp=0,np=nv_search(arg->argval,shp->var_tree,0)))
			{
				nv_onattr(np,NV_EXPORT);
				sh_envput(shp->env,np);
			}
			if(cp)
				*cp = '=';
			arg=arg->argnxt.ap;
		}
		pname = argv[0];
		if(logp && logp->arg0)
			argv[0] = logp->arg0;
#ifdef JOBS
		if(job_close(shp) < 0)
			return(1);
#endif /* JOBS */
		/* force bad exec to terminate shell */
		pp->mode = SH_JMPEXIT;
		sh_sigreset(2);
		sh_freeup(shp);
		path_exec(pname,argv,NIL(struct argnod*));
		sh_done(shp,0);
        }
	return(1);
}
示例#4
0
int dbopen()
{
    LOG;
	char basedir[] = "./dbbench/";
	char dbname[] = "test.db";

	e = env_open(basedir, -1);
	db = db_open(e, dbname);
	if (!db) {
		fprintf(stderr, "open db error, see ness.event for details\n");
		return 0;
	}

	if (!env_set_cache_size(e, FLAGS_cache_size)) {
		fprintf(stderr, "set cache size error, see ness.event for details\n");
		return 0;
	}

	if (!env_set_compress_method(e, FLAGS_method)) {
		fprintf(stderr, "set compress method error, see ness.event for details\n");
		return 0;
	}

    LOG;
	return 1;
}
void 
initDB(/*DB_ENV ** dbenv, */pthread_attr_t * attr, int type)  
{

	pthread_t ptid;

	env_dir_create();
	env_open(&dbenv);
	int ret;
	/*
	///Start a checkpoint thread.
	if ((ret = pthread_create(
	    &ptid, attr, checkpoint_thread, (void *)dbenv)) != 0) {
		fprintf(stderr,
		    "txnapp: failed spawning checkpoint thread: %s\n",
		    strerror(ret));
		exit (1);
	}

	/// Start a logfile removal thread. 
	if ((ret = pthread_create(
	    &ptid, attr, logfile_thread, (void *)dbenv)) != 0) {
		fprintf(stderr,
		    "txnapp: failed spawning log file removal thread: %s\n",
		    strerror(ret));
		exit (1);
	}
	*/
	db_open(dbenv, &db_cats, "cats", type);



}
示例#6
0
int main() {
	DB *dbp;
	DB_ENV *dbenv;
	DB_TXN *xid;
	DBT key, data;
	const unsigned int INSERT_NUM = 100;
	char value[22]; /* should be log INSERT_NUM */
	int ret, i, t_ret;

        env_dir_create();
        env_open(&dbenv);

	if ((ret = db_create(&dbp, dbenv, 0)) != 0) {
		fprintf(stderr, "db_create: %s\n", db_strerror(ret));
		exit (1);
	}

	dbenv->txn_begin(dbenv, NULL, &xid, 0);
	if ((ret = dbp->open(dbp,
					xid, DATABASE, NULL, DB_BTREE, DB_CREATE, 0664)) != 0) {
		dbp->err(dbp, ret, "%s", DATABASE);
		goto err;
	}

	memset(&key, 0, sizeof(key));
	memset(&data, 0, sizeof(data));

	key.size = sizeof(int);
	key.data = malloc(sizeof(int));
	data.data = value;

	for( i = 0; i < INSERT_NUM; i++ ) {
		*((int*)key.data) = i;
		data.size = sizeof(char)*strlen(data.data);
		sprintf(value, "value: %u\n", i);
		dbp->put(dbp, xid, &key, &data, 0);
	}

	xid->commit(xid, 0);
	dbenv->txn_begin(dbenv, NULL, &xid, 0);
	
	for( i = 0; i < INSERT_NUM; i++ ) {
		*((int*)key.data) = i;
		dbp->get(dbp, xid, &key, &data, 0);
		printf("db: %u: key retrieved: data was %s.\n", *((int*)key.data), (char *)data.data);
	}

	xid->abort(xid);

err:    if ((t_ret = dbp->close(dbp, 0)) != 0 && ret == 0)
			ret = t_ret; 


	return 0;

}
示例#7
0
int main(int argc, char **argv) {
	DB *dbp;
	DB_ENV *dbenv;
	DBT key, data;
	db_recno_t recno;
	DB_TXN *xid;

	int num_xactions;
	int  num_inserts_per_xaction;
	char *string;
	int i, j;



	if (argc != 3)  {
		printf("usage: %s <num xactions> <num inserts per xaction>\n", argv[0]);
		exit(-1);
	}

	num_xactions = atoi(argv[1]);
	num_inserts_per_xaction = atoi(argv[2]);

	env_dir_create();
	env_open(&dbenv);
	rand_str_init();

	if (db_open(dbenv, &dbp, DATABASE, 0)) {
		return (1); 	
	}

	memset(&key, 0, sizeof(DBT));
	memset(&data, 0, sizeof(DBT));

	recno = 1;
	for (i = 1; i <= num_xactions; i++ ) {

		dbenv->txn_begin(dbenv, NULL, &xid, 0);

		for (j = 0; j < num_inserts_per_xaction; j++) {

			string = rand_str();

			key.size = sizeof(recno);
			key.data = &recno;
			data.size = strlen(string) + 1; // + 1 for the null terminator	
			data.data = string;
			
/*
			if(VERBOSE) {
				printf("%s\n", string);
			}
*/
			dbp->put(dbp, xid, &key, &data, 0);
			recno++;
			/* Its unclear from BDB docs whether we should free string */
		}

		xid->commit(xid, 0);
	}


	return 0;
}
示例#8
0
文件: bdbHash.c 项目: Zhoutall/stasis
int
main(int argc, char *argv[])
{
	extern int optind;
	DB *db_cats; /*, *db_color, *db_fruit; */
	DB_ENV *dbenv;
	pthread_t ptid;
	int ch, ret;

	/*	while ((ch = getopt(argc, argv, "")) != EOF)
		switch (ch) {
		case '?':
		default:
			usage();
		}
	argc -= optind;
	argv += optind; */

	assert(argc == 3);
	

	env_dir_create();
	env_open(&dbenv);

	/* Start a checkpoint thread. */
	if ((ret = pthread_create(
	    &ptid, NULL, checkpoint_thread, (void *)dbenv)) != 0) {
		fprintf(stderr,
		    "txnapp: failed spawning checkpoint thread: %s\n",
		    strerror(ret));
		exit (1);
	}

	/* Start a logfile removal thread. */
	if ((ret = pthread_create(
	    &ptid, NULL, logfile_thread, (void *)dbenv)) != 0) {
		fprintf(stderr,
		    "txnapp: failed spawning log file removal thread: %s\n",
		    strerror(ret));
		exit (1);
	}

	/* Open database: Key is fruit class; Data is specific type. */
	/*	db_open(dbenv, &db_fruit, "fruit", 0); */

	/* Open database: Key is a color; Data is an integer. */
	/*db_open(dbenv, &db_color, "color", 0); */

	/*
	 * Open database:
	 *	Key is a name; Data is: company name, address, cat breeds.
	 */
	db_open(dbenv, &db_cats, "cats", 1);

	/*	add_fruit(dbenv, db_fruit, "apple", "yellow delicious");

	add_color(dbenv, db_color, "blue", 0);
	add_color(dbenv, db_color, "blue", 3); */

	/*	add_cat(dbenv, db_cats,
		"Amy Adams",
		"Sleepycat Software",
		"394 E. Riding Dr., Carlisle, MA 01741, USA",
		"abyssinian",
		"bengal",
		"chartreaux",
		NULL);*/
	int r;
	int num_xact        = atoi(argv[1]); //100;
	int insert_per_xact = atoi(argv[2]); //1000;
	for(r = 0; r < num_xact; r ++) {
	  run_xact(dbenv, db_cats, 1+r*insert_per_xact, insert_per_xact);
	}
	return (0);
}
示例#9
0
int main(int argc, char **argv) {
	DB *dbp;
	DB_ENV *dbenv;
	DB_TXN *xid;
	DBT key, data;
	db_recno_t recno;

	int num_trials;
	int ret;
	char c;


	double r;
	int start, end;

	char first_printable_ascii = ' ';
	char last_printable_ascii = '~';
	int ascii_length = (int)(last_printable_ascii - first_printable_ascii);
	char *ASCII = (char *)malloc(sizeof(char) * ascii_length);
	char *string;

	for (c = 0; c < ascii_length; c++) {
		ASCII[(int)c] = first_printable_ascii + c;
	}

	if (argc != 2)  {
		printf("usage: %s <num trials>\n", argv[0]);
		exit(-1);
	}


	env_dir_create();
	env_open(&dbenv);
	if (db_open(dbenv, &dbp, DATABASE, 0))
		return (1); 	

        memset(&key, 0, sizeof(DBT));
        memset(&data, 0, sizeof(DBT));
	num_trials = atoi(argv[1]);
	for (recno = 1; (int)recno <= num_trials; recno++) {
		start = 0;
		end = 0;
		while (start == end) {	
			r = ((double)rand()/(double)((double)RAND_MAX+1)); /* returns [0, 1)*/
			r = r*ascii_length;
			start = (int)r; /* an int in the rand [0, ascii_length) */

			r = ((double)rand()/(double)((double)RAND_MAX+1)); /* re turns [0, 1)*/
			r = r*ascii_length;
			end = (int)r; /* an int in the rand [0, ascii_length) */
		}
		if (end < start) {
			int swap = start;
			start = end;
			end = swap;
		}

		string = (char *)malloc(sizeof(char) * (end - start) + 1);
		strncpy(string, ASCII + start, end-start);
		string[end-start] = '\0'; /* make the string null terminated */

		dbenv->txn_begin(dbenv, NULL, &xid, 0);
		key.size = sizeof(recno);
		key.data = &recno;
		data.size = strlen(string) + 1; // + 1 for the null terminator	
		data.data = string;
		switch (ret = dbp->put(dbp, xid, &key, &data, 0)) {
			case 0:
				xid->commit(xid, 0);
				break;
			default:
				dbp->err(dbp, ret, "DB->put");
				xid->abort(xid);
				break;
		}


	}


	return 0;

}