Exemple #1
0
static void stasis_alloc_register_old_regions(stasis_alloc_t* alloc) {
  pageid_t boundary = REGION_FIRST_TAG;
  boundary_tag t;
  DEBUG("registering old regions\n");
  int succ = TregionReadBoundaryTag(-1, boundary, &t);
  if(succ) {
    do {
      DEBUG("boundary tag %lld type %d\n", boundary, t.allocation_manager);
      if(t.allocation_manager == STORAGE_MANAGER_TALLOC) {
        for(pageid_t i = 0; i < t.size; i++) {
          Page * p = loadPage(-1, boundary + i);
          readlock(p->rwlatch,0);
          if(p->pageType == SLOTTED_PAGE) {
            stasis_allocation_policy_register_new_page(alloc->allocPolicy, p->id, stasis_record_freespace(-1, p));
            DEBUG("registered page %lld\n", boundary+i);
          } else {
            abort();
          }
          unlock(p->rwlatch);
          releasePage(p);
        }
      }
    } while(TregionNextBoundaryTag(-1, &boundary, &t, 0));  //STORAGE_MANAGER_TALLOC)) {
  }
}
Exemple #2
0
int openInterpreter(FILE * in, FILE * out, recordid hash) {
  char * line = NULL;
  size_t len = 0;
  int AUTOCOMMIT = 1;
  int debug = 0;
  int xid = -1;
  size_t read;

  fprintf(out, "> ");
  int ret = 0;
  if(!AUTOCOMMIT) { xid = Tbegin(); }
  while((read = getline(&line, &len, in)) != -1) {
    if(line[0] == '!') {
      if(!strncmp(line+1,"debug",strlen("debug"))) {
	debug = !debug;
	if(debug)
	  fprintf(out, "Enabling debugging\n");
	else
	  fprintf(out, "Disabling debugging\n");
      } else if(!strncmp(line+1,"regions",strlen("regions"))) {
	fprintf(out, "Boundary tag pages:\n");
	pageid_t pid = REGION_FIRST_TAG;
	boundary_tag tag;
	TregionReadBoundaryTag(-1,pid,&tag);
	int done = 0;
	while(!done) {
	  fprintf(out, "\tpageid=%lld\ttype=%d\tsize=%lld\n", pid, tag.allocation_manager, tag.size);
	  if(tag.size == UINT32_MAX) { fprintf(out, "\t[EOF]\n"); }
	  int err = TregionNextBoundaryTag(-1,&pid,&tag,0);
	  if(!err) { done = 1; }
	}
      } else if(!strncmp(line+1,"autocommit",strlen("autocommit"))) {
	if(AUTOCOMMIT) {
	  // we're not in a transaction
	  fprintf(out, "Disabling autocommit\n");
	  AUTOCOMMIT = 0;
	  xid = Tbegin();
	} else {
	  fprintf(out, "Enabling autocommit\n");
	  AUTOCOMMIT = 1;
	  Tcommit(xid);
	}
   /* } else if(!strncmp(line+1,"parseTuple",strlen("parseToken"))) {
	char * c = line + 1 + strlen("parseToken");
	char ** toks = parseTuple(&c);
	for(int i = 0; toks[i]; i++) {
	  fprintf(out, "col %d = ->%s<-\n", i, toks[i]);
	}
	fprintf(out, "trailing stuff: %s", c);
      } else if(!strncmp(line+1,"parseExpression",
			 strlen("parseExpression"))) {
	char * c = line + 1 + strlen("parseExpression");
	lladdIterator_t * it = parseExpression(xid, hash, &c);
	it = 0; */
      } else if(!strncmp(line+1,"exit",strlen("exit"))) {
	break;
      } else if(!strncmp(line+1,"shutdown",strlen("shutdown"))) {
	ret = SHUTDOWN_SERVER;
	break;
      }
    } else {
      expr_list * results = 0;
      parse(line, &results);
      for(int i = 0; results && i < results->count; i++) {
	expr * e = results->ents[i];
	switch(e->typ) {
	case query_typ: {
	  lladdIterator_t * it = ReferentialAlgebra_ExecuteQuery(xid, context, e->u.q);
	  if(it) {
	    while(Titerator_next(xid,it)) {
	      byte * tup;
	      Titerator_value(xid,it, &tup);
	      char * tupleString = stringTuple(*(tuple_t*)tup);
	      fprintf(out, "%s\n", tupleString);
	      free(tupleString);
	    }
	    Titerator_close(xid,it);
	  }
	} break;
	case insert_typ: {
	  if(AUTOCOMMIT) { xid = Tbegin(); }
	  ReferentialDML_ExecuteInsert(xid, context, e->u.i);
	  if(AUTOCOMMIT) { Tcommit(xid); xid = -1;}
	} break;
	case delete_typ: {
	  if(AUTOCOMMIT) { xid = Tbegin(); }
	  ReferentialDML_ExecuteDelete(xid, context, e->u.d);
	  if(AUTOCOMMIT) { Tcommit(xid); xid = -1;}
	} break;
	case create_typ: {
	  if(AUTOCOMMIT) { xid = Tbegin(); }
	  ReferentialDDL_CreateTable(xid, context, e->u.c);
	  if(AUTOCOMMIT) { xid = Tcommit(xid); xid = -1;}
	} break;
	default:
	  abort();
	}
      }

      //XXX typecheck(context, results);
      if(results) {
	char * str = pp_expr_list(results);
	printf("%s", str);
	free(str);
      } else {
	printf("No results\n");
      }
    }
    fprintf(out, "> ");
  }
  if(!AUTOCOMMIT) { Tcommit(xid); }

  free(line);
  fprintf(out, "\n");
  return ret;
}