Example #1
0
int test() {
  int i;
  int writeVal, readVal;
  
  /** These need to be reset manually. */
  int xid = 2; 
  recordid rec = { 0,0,sizeof(int) };


  InitiateRecovery();

  printf("\nRunning prepare testing commit.\n");
  

  Tread(xid, rec, &readVal);
  printf("value read is %d\n", readVal);

  Tcommit(xid);

  xid = Tbegin();

  printf("xid = %d\n", xid);

  Tread(xid, rec, &readVal);
  printf("value read is %d\n", readVal);

  Tabort(xid);

  exit(-1);

}
Example #2
0
int test(int argc, char **argv) {
	recordid rec;
	int num_trials;
	/* counters */
	int i;
	
	char *out_buffer = (char *)malloc(sizeof(char) * 300);

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

	num_trials = atoi(argv[1]);
	srand(SEED);

	rec.page = 0;

	for (i = 0; i < num_trials; i++) {
		rec.slot = i;	
		
		Tread(0, rec, out_buffer);
			
		if (VERBOSE) {
			printf("read [%s]\n", out_buffer);
		}		

	}

	return 0;
}
Example #3
0
int main(int argc, char * argv[]) {

  Tinit();
  ReferentialAlgebra_init();

  recordid rootEntry;
  recordid hash;
  int xid = Tbegin();
  if(TrecordType(xid, ROOT_RECORD) == INVALID_SLOT) {
    printf("Creating new store\n");

    rootEntry = Talloc(xid, sizeof(recordid));
    assert(rootEntry.page == ROOT_RECORD.page);
    assert(rootEntry.slot == ROOT_RECORD.slot);

    hash = ReferentialAlgebra_allocContext(xid);

    Tset(xid, rootEntry, &hash);

  } else {
    printf("Opened existing store\n");
    rootEntry.page = ROOT_RECORD.page;
    rootEntry.slot = ROOT_RECORD.slot;
    rootEntry.size = sizeof(recordid);

    Tread(xid, rootEntry, &hash);

  }

  context = ReferentialAlgebra_openContext(xid,hash);

  Tcommit(xid);

  FILE * in;
  if(argc == 3) { // listen on socket
    if(strcmp("--socket", argv[1])) {
      printf("usage:\n\n%s\n%s <filename>\n%s --socket addr:port\n",
	     argv[0],argv[0],argv[0]);
    } else {
      startServer(argv[2], hash);
    }

    printf("Shutting down...\n");
  } else {
    if(argc == 2) {
      in = fopen(argv[1], "r");
      if(!in) {
	printf("Couldn't open input file.\n");
	return 1;
      }
    } else {
      in = stdin;
    }
    openInterpreter(in, stdout, hash);
  }
  Tdeinit();
}
Example #4
0
void TlinkedListDelete(int xid, recordid list) {
  stasis_linkedList_entry * entry = (stasis_linkedList_entry *)malloc(list.size);

  Tread(xid, list, entry);
  Tdealloc(xid, list);

  if(entry->next.size == 0) {
    return;
  }

  while(entry->next.size != -1) {
    recordid nextEntry;
    Tread(xid, nextEntry, entry);
    assert(!memcmp(&nextEntry, &(entry->next), sizeof(recordid)));
    Tdealloc(xid, nextEntry);
  }

  free(entry);
}
Example #5
0
int TlinkedListFind(int xid, recordid list, const byte * key, int keySize, byte ** value) {

  stasis_linkedList_entry * entry = (stasis_linkedList_entry *)malloc(list.size);

  pthread_mutex_lock(&stasis_linked_list_mutex);
  Tread(xid, list, entry);

  if(!entry->next.size) {
    free(entry);
    pthread_mutex_unlock(&stasis_linked_list_mutex);
    return -1; // empty list
  }

  int done = 0;
  int ret = -1;

  while(!done) {

    if(!memcmp(entry + 1, key, keySize)) {
      // Bucket contains the entry of interest.
      int valueSize = list.size - (sizeof(stasis_linkedList_entry) + keySize);
      *value  = stasis_malloc(valueSize, byte);
      memcpy(*value, ((byte*)(entry+1))+keySize, valueSize);
      done = 1;
      ret = valueSize;
    }
    if(entry->next.size != -1) {
      assert(entry->next.size == list.size);  // Don't handle lists with variable length records for now
      Tread(xid, entry->next, entry);
    } else {
      done = 1;
    }
  }
  free(entry);

  pthread_mutex_unlock(&stasis_linked_list_mutex);

  return ret;
}
Example #6
0
void bLSM::openTable(int xid, recordid rid) {
  table_rec = rid;
  Tread(xid, table_rec, &tbl_header);
  tree_c2 = new diskTreeComponent(xid, tbl_header.c2_root, tbl_header.c2_state, tbl_header.c2_dp_state, 0);
  tree_c1 = new diskTreeComponent(xid, tbl_header.c1_root, tbl_header.c1_state, tbl_header.c1_dp_state, 0);
  tree_c0 = new memTreeComponent::rbtree_t;

  merge_mgr = new mergeManager(this, xid, tbl_header.merge_manager);
  merge_mgr->set_c0_size(max_c0_size);

  merge_mgr->new_merge(0);

}
Example #7
0
int test(void) {
	struct timeval start, end, total;
	recordid rids[TESTS];
	long commited[TESTS];
	long aborted[TESTS];
	long temp;
	int i, j, xid = Tbegin();

	for( i = 0; i < TESTS; i++ ) {
		rids[i] = Talloc(xid, sizeof(long));
		commited[i] = random();
		aborted[i] = random();
		Tset(xid, rids[i], &commited[i]);
	}

	gettimeofday(&start, NULL);
	Tcommit(xid);
	gettimeofday(&end, NULL);
	timersub(&end, &start, &total);
	printf("commit %u: %ld.%ld\n", TESTS, total.tv_sec, total.tv_usec);

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

		xid = Tbegin();

		for( i = 0; i < TESTS*j; i++ ) {
			Tset(xid, rids[random() % TESTS], &aborted[i%TESTS]);
		}

		gettimeofday(&start, NULL);
		Tabort(xid);
		gettimeofday(&end, NULL);
		timersub(&end, &start, &total);
		printf("abort %u: %ld.%ld\n", TESTS*j, total.tv_sec, total.tv_usec);

		xid = Tbegin();
		for( i = 0; i < TESTS; i++ ) {
			Tread( xid, rids[i], &temp );
			if( temp != commited[i] )
				return -1;
		}
		Tabort(xid);
	}

	return 0;
}
Example #8
0
int test(int argc, char **argv) {
	int xid;
	int writeVals[NUM_TRIALS];
	int readVals[NUM_TRIALS];
	recordid recs[NUM_TRIALS];

	int i;
	int failed = 0;

	printf("\nRunning %s\n", __FILE__);

	xid = Tbegin();

	for (i = 0; i < NUM_TRIALS; i++) {
		writeVals[i] = rand();

		recs[i] = Talloc(xid, sizeof(int));

		Tset(xid, recs[i], &writeVals[i]);
	}

	Tcommit(xid);
	xid = Tbegin();

	for (i = 0; i < NUM_TRIALS; i++) {
		Tread(xid, recs[i], &readVals[i]);

		if (VERBOSE) 
			printf("value set is %d, value read is %d\n", writeVals[i], readVals[i]); 

		if (writeVals[i] != readVals[i]) 
			failed = 1;
	}

	Tcommit(xid);

	printf("%s\n\n", failed ? "****FAILED****" : "PASSED");

	return failed;
}
Example #9
0
static void stasis_linked_list_insert_helper(int xid, recordid list, const byte * key, int keySize, const byte * value, int valueSize) {
  stasis_linkedList_entry * entry = stasis_malloc_trailing_array(stasis_linkedList_entry, keySize + valueSize);

  Tread(xid, list, entry);
  if(!entry->next.size) {
    memcpy(entry+1, key, keySize);
    memcpy(((byte*)(entry+1))+keySize, value, valueSize);
    entry->next.page = 0;
    entry->next.slot = 0;
    entry->next.size = -1;
    Tset(xid, list, entry);
  } else {
    stasis_linkedList_entry * newEntry = stasis_malloc_trailing_array(stasis_linkedList_entry, keySize + valueSize);
    memcpy(newEntry + 1, key, keySize);
    memcpy(((byte*)(newEntry+1))+keySize, value, valueSize);
    newEntry->next = entry->next;
    recordid newRid = Talloc(xid, sizeof(stasis_linkedList_entry) + keySize + valueSize);
    Tset(xid, newRid, newEntry);
    entry->next = newRid;
    Tset(xid, list, entry);
    free(newEntry);
  }
  free(entry);
}
Example #10
0
int TlinkedListNext(int xid, stasis_linkedList_iterator * it, byte ** key, int * keySize, byte **value, int * valueSize) {

  if(it->next.size == -1)  {
    return 0;
  }

  int done = 0;
  int ret = 0;
  stasis_linkedList_entry * entry;

  pthread_mutex_lock(&stasis_linked_list_mutex);

  if(it->first == -1) {
    it->first = 1;
  } else if(it->first) {
    entry = (stasis_linkedList_entry *)malloc(it->next.size);
    Tread(xid, it->listRoot, entry);
    int listTouched;
    listTouched = memcmp(&(entry->next), &(it->next), sizeof(recordid));
    free(entry);
    if(listTouched) {
      //The root entry was removed.  Reset the iterator.
      it->first = -1;
      it->next = it->listRoot;
      ret = TlinkedListNext(xid, it, key, keySize, value, valueSize);
      done = 1;
    } else {
      //continue as normal.
      it->first = 0;
    }
  }

  if(done) {
    pthread_mutex_unlock(&stasis_linked_list_mutex);
    return ret;
  }

  assert(it->keySize + it->valueSize + sizeof(stasis_linkedList_entry) == it->next.size);
  entry = (stasis_linkedList_entry *)malloc(it->next.size);
  Tread(xid, it->next, entry);

  if(entry->next.size) {
    *keySize = it->keySize;
    *valueSize = it->valueSize;
    *key = stasis_malloc(*keySize, byte);
    *value = stasis_malloc(*valueSize, byte);

    it->next = entry->next;

    memcpy(*key, entry+1, *keySize);
    memcpy(*value, ((byte*)(entry + 1))+*keySize, *valueSize);

    ret = 1;
  } else {
    // This entry was empty (this case occurs with empty lists)
    ret = 0;
  }
  free(entry);

  pthread_mutex_unlock(&stasis_linked_list_mutex);
  return ret;
}
Example #11
0
static int stasis_linked_list_remove_helper(int xid, recordid list, const byte * key, int keySize) {
  stasis_linkedList_entry * entry = (stasis_linkedList_entry *)malloc(list.size);
  pthread_mutex_lock(&stasis_linked_list_mutex);

  Tread(xid, list, entry);

  if(entry->next.size == 0) {
    //Empty List.
    free(entry);
    pthread_mutex_unlock(&stasis_linked_list_mutex);
    return 0;
  }
  int listRoot = 1;
  recordid lastRead = list;
  recordid oldLastRead;
  oldLastRead.size = -2;
  int ret = 0;

  while(1) {
    if(!memcmp(entry + 1, key, keySize)) {
      // Bucket contains the entry of interest.
      if(listRoot) {
        if(entry->next.size == -1) {
          memset(entry, 0, list.size);
          Tset(xid, lastRead, entry);
        } else {
          assert(entry->next.size == list.size);  // Otherwise, something strange is happening, or the list contains entries with variable sizes.
          stasis_linkedList_entry * entry2 = (stasis_linkedList_entry *)malloc(list.size);
          Tread(xid, entry->next, entry2);
          Tdealloc(xid, entry->next); // could break iterator, since it writes one entry ahead.
          Tset(xid, lastRead, entry2);
          free(entry2);
        }
      } else {
        stasis_linkedList_entry * entry2 = (stasis_linkedList_entry *)malloc(list.size);
        assert(oldLastRead.size != -2);
        Tread(xid, oldLastRead, entry2);
        memcpy(&(entry2->next), &(entry->next), sizeof(recordid));
        Tset(xid, oldLastRead, entry2);
        Tdealloc(xid, lastRead);
        free (entry2);
      }
      ret = 1;
      break;
    } else { // Entry doesn't match the key we're looking for.
      if(entry->next.size != -1) {
        assert(entry->next.size == list.size);  // Don't handle lists with variable length records for now
        oldLastRead = lastRead;
        lastRead = entry->next;
        Tread(xid, entry->next, entry);
        listRoot = 0;
      } else {
        break;
      }
    }
  }
  free(entry);
  pthread_mutex_unlock(&stasis_linked_list_mutex);

  return ret;
}
Example #12
0
int test() {
  int i;
  int xid, writeVal, readVal;
  recordid rec;
  
  printf("\nRunning test1\n");
  

  writeVal = 10;
  
  xid = Tbegin();

  rec = Talloc(xid, sizeof(int));

  Tset(xid, rec, &writeVal);
  Tread(xid, rec, &readVal);
  
  printf("value set is %d, value read is %d\n", writeVal, readVal);
    
  Tcommit(xid);

  xid = Tbegin();
  Tread(xid, rec, &readVal);
  printf("value read is %d\n", readVal);

  Tincrement(xid, rec);
  printf("calling Tincrement\n");

  Tread(xid, rec, &readVal);
  printf("value read is %d\n", readVal);

  Tincrement(xid, rec);
  printf("calling Tincrement\n");

  Tread(xid, rec, &readVal);
  printf("value read is %d\n", readVal);

  Tabort(xid);
  printf("aborting\n");
  xid = Tbegin();

  Tread(xid, rec, &readVal);
  printf("value read is %d\n", readVal);

  Tincrement(xid, rec);
  printf("calling Tincrement\n");

  Tread(xid, rec, &readVal);
  printf("value read is %d\n", readVal);

  Tdecrement(xid, rec);
  printf("calling Tdecrement\n");

  Tread(xid, rec, &readVal);
  printf("value read is %d\n", readVal);
  Tdecrement(xid, rec);
  printf("calling Tdecrement\n");

  Tread(xid, rec, &readVal);
  printf("value read is %d\n", readVal);
  Tdecrement(xid, rec);
  printf("calling Tdecrement\n");

  Tread(xid, rec, &readVal);
  printf("value read is %d\n", readVal);

  for (i = 0; i < 10; i++) {
    Tdecrement(xid, rec);
    printf("calling Tdecrement\n");
    
    Tread(xid, rec, &readVal);
    printf("value read is %d\n", readVal);
  }

  Tcommit(xid);
  printf("committing\n");
  xid = Tbegin();

  Tread(xid, rec, &readVal);
  printf("value read is %d\n", readVal);

  Tdecrement(xid, rec);
  printf("calling Tdecrement\n");

  Tread(xid, rec, &readVal);
  printf("value read is %d\n", readVal);

  Tincrement(xid, rec);
  printf("calling Tincrement\n");

  Tread(xid, rec, &readVal);
  printf("value read is %d\n", readVal);

  Tdecrement(xid, rec);
  printf("calling Tdecrement\n");

  Tread(xid, rec, &readVal);
  printf("value read is %d\n", readVal);

  
  

  printf("\n");
  return 0;

}
Example #13
0
int test(int argc, char **argv) {
  int xids[NUM_TRIALS];
  int initVals[NUM_TRIALS];
  int writeVals[NUM_TRIALS];
  int readVals[NUM_TRIALS];
  int commits[NUM_TRIALS];
  int i;
  recordid recs[NUM_TRIALS];
  int failed = 0;

  printf("\nRunning %s\n", __FILE__);

  for (i = 0; i < NUM_TRIALS; i++) {
    xids[i] = Tbegin();
    initVals[i] = rand();
    recs[i] = Talloc(xids[i], sizeof(int));
    Tset(xids[i], recs[i], &initVals[i]);
    Tcommit(xids[i]);
  }

  

  for (i = 0; i < NUM_TRIALS; i++) {
    xids[i] = Tbegin();
    commits[i] = 0;
    writeVals[i] = rand();
  }

  for (i = 0; i < NUM_TRIALS; i++) {
    Tset(xids[i], recs[i], &writeVals[i]);
  }
  
  for (i = 0; i < NUM_TRIALS; i++) {
    if (rand() % 2) { 
      Tcommit(xids[i]);
      commits[i] = 1;
    } else {
      Tabort(xids[i]);
   }
  }

  for (i = 0; i < NUM_TRIALS; i++) {
      Tread(xids[i], recs[i], &readVals[i]);
  }


  for (i = 0; i < NUM_TRIALS; i++) {
    if (VERBOSE) {
      if (commits[i])
         printf("xid %d commited value %d, and read %d\n", xids[i], writeVals[i], readVals[i]);
      else
         printf("xid %d aborted while setting value %d, and read %d and should've read %d\n", xids[i], writeVals[i], readVals[i], initVals[i]);
          
    }
    
  if (commits[i]) {
     if (writeVals[i] != readVals[i])
        failed = 1;
  } else {
     if (initVals[i] != readVals[i])
        failed = 1;    
  }  
}  
  
  printf("%s\n\n", failed ? "****FAILED****" : "PASSED");

  return failed;
}
Example #14
0
int test() {
  int xid;
  char *handle_in = "jkit";
  char *name_in = "Jimmy Kittiyachavalit";
  int phone_in = 8821417;
  
  char *handle_out = (char *)malloc(strlen(handle_in)+1);
  char *name_out = (char *)malloc(strlen(name_in)+1);
  int phone_out;
  
  recordid r_name, r_handle, r_phone;
  
  xid = Tbegin();
  
  r_handle = Talloc(xid, strlen(handle_in)+1);
  r_name = Talloc(xid, strlen(name_in)+1);
  r_phone = Talloc(xid, sizeof(int));

  Tset(xid, r_handle, handle_in);
  printf("set handle to [%s]\n", handle_in);
  Tset(xid, r_name, name_in);
  printf("set name to [%s]\n", name_in);
  Tset(xid, r_phone, &phone_in);
  printf("set name to [%d]\n", phone_in);
  
  Tread(xid, r_handle, handle_out);
  printf("read handle is [%s]\n", handle_out);
  Tread(xid, r_name, name_out);
  printf("read name is [%s]\n", name_out);
  Tread(xid, r_phone, &phone_out);
  printf("read name is [%d]\n", phone_out);
    
  
  Tcommit(xid);



  xid = Tbegin();
  handle_in = "tikj";
  name_in = "tilavahcayittik ymmij";
  phone_in = 3142116;
  handle_out = (char *)malloc(strlen(handle_in)+1);
  name_out = (char *)malloc(strlen(name_in)+1);
  phone_out = 0;
  Tset(xid, r_handle, handle_in);
  printf("set handle to [%s]\n", handle_in);
  Tset(xid, r_name, name_in);
  printf("set name to [%s]\n", name_in);
  Tset(xid, r_phone, &phone_in);
  printf("set name to [%d]\n", phone_in);
  
  Tread(xid, r_handle, handle_out);
  printf("read handle is [%s]\n", handle_out);
  Tread(xid, r_name, name_out);
  printf("read name is [%s]\n", name_out);
  Tread(xid, r_phone, &phone_out);
  printf("read name is [%d]\n", phone_out);
  
  printf("aborted the transaction\n");  

  Tabort(xid);

  xid = Tbegin();
  handle_out = (char *)malloc(strlen(handle_in)+1);
  name_out = (char *)malloc(strlen(name_in)+1);
  phone_out = 0;
  Tread(xid, r_handle, handle_out);
  printf("read handle is [%s]\n", handle_out);
  Tread(xid, r_name, name_out);
  printf("read name is [%s]\n", name_out);
  Tread(xid, r_phone, &phone_out);
  printf("read name is [%d]\n", phone_out);
  

  Tcommit(xid);
  
  return 0;
}
Example #15
0
int test() {
	int xid;
	int NUM_TRIALS=100;
	recordid rec;

	/* counters */
	int i;
	char c;

	/* used for making the random strings*/
	double r;
	int start, end;

	/* used to make a long string */	
	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);

	/* an array of strings */
	char **strings = (char **)malloc(sizeof(char*) * NUM_TRIALS);

	/* output buffer */
	char *out_buffer = (char *)malloc(sizeof(char) * ascii_length);


	srand(SEED);

	/* create the long string from which random strings will be made */
	for (c = 0; c < ascii_length; c++) {
		ASCII[(int)c] = first_printable_ascii + c;
	}

	for (i = 0; i < NUM_TRIALS; i++) {

		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)); /* returns [0, 1)*/
		r = r*ascii_length;
		end = (int)r; /* an int in the rand [0, ascii_length) */
	
		if (start == end) {
			i--;
			continue;
		}

		if (end < start) {
			int swap = start;
			start = end;
			end = swap;
		}
		

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

	for (i = 0; i < NUM_TRIALS; i++) {
		xid = Tbegin();
		rec = Talloc(xid, sizeof(char)*(strlen(strings[i]) +1));
		Tset(xid, rec, strings[i]);

		Tread(xid, rec, out_buffer);
			
		if (VERBOSE) {
			printf("xid %d set rid (%d, %d) to [%s], and read [%s]\n", xid, rec.page, rec.slot, strings[i], out_buffer);
		}		
		assert(strcmp(strings[i], out_buffer) == 0); 
		Tcommit(xid);
	}
	
	return 0;
}