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);



}
예제 #2
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;

}
예제 #3
0
int main()
{
  int err;
  off_t size;
  size_t sz,sz2;
  mode_t mode = 0x81B4;
  char *path,*buf,buffer[30];
  char *url="dbfs\0";
  char *rl="/tmp/dbfs_vol\0";
  char newoff[10];
  char input[100],tok1[20],tok2[20],tok3[20];
  off_t offset=0,off2=0;
  struct stat stbuf;
  if(err=mangoo_initstore(url,rl,&ms))
    printf("Error in store\n");
  else
    printf("store opened\n");
  env_dir_create();
  offset=getdata("/.newoffset");
  while(1)
    {
      scanf("%[^\n]%*c",input);
      sscanf(input,"%s%s%s",tok1,tok2,tok3);  
      if(!strcmp(tok1,"write"))
	{
	  path=tok3;
	  buf=tok2;
	  sampwrite(path,buf,&sz,&offset);
	}
      else if(!strcmp(tok1,"read"))
	{
	  path=tok2;
	  sampread(path);
	}
      else if(!strcmp(tok1,"exit"))
	{
	  sprintf(newoff,"%jd",(intmax_t)offset);
	  sampwrite("/.newoffset",newoff,&sz2,&off2);
	  mangoo_closestore(ms);
	  exit(0);
	}
      else if(!strcmp(tok1,"getattr"))
	{
	  path=tok2;
	  getattr(path,&stbuf);
	}
      else if(!strcmp(tok1,"mkdir"))
	{
	  path=tok2;
	  makedir(path);
	}
      else if(!strcmp(tok1,"help"))
	{
	  help();
	}
      else{
	printf("Command Not Found! Enter help to know working commands\n");
      }
    }
  return 0;
}
예제 #4
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;
}
예제 #5
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);
}
예제 #6
0
파일: dbInsert.c 프로젝트: Zhoutall/stasis
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;

}