示例#1
0
// we don't consolidate reserved regions, since they may be categorized
// in different types.
bool VMMemPointerIterator::add_reserved_region(MemPointerRecord* rec) {
  assert(rec->is_allocation_record(), "Sanity check");
  VMMemRegion* reserved_region = (VMMemRegion*)current();

  // we don't have anything yet
  if (reserved_region == NULL) {
    return insert_record(rec);
  }

  assert(reserved_region->is_reserved_region(), "Sanity check");
  // duplicated records
  if (reserved_region->is_same_region(rec)) {
    return true;
  }
  // Overlapping stack regions indicate that a JNI thread failed to
  // detach from the VM before exiting. This leaks the JavaThread object.
  if (CheckJNICalls)  {
      guarantee(FLAGS_TO_MEMORY_TYPE(reserved_region->flags()) != mtThreadStack ||
         !reserved_region->overlaps_region(rec),
         "Attached JNI thread exited without being detached");
  }
  // otherwise, we should not have overlapping reserved regions
  assert(FLAGS_TO_MEMORY_TYPE(reserved_region->flags()) == mtThreadStack ||
    reserved_region->base() > rec->addr(), "Just check: locate()");
  assert(FLAGS_TO_MEMORY_TYPE(reserved_region->flags()) == mtThreadStack ||
    !reserved_region->overlaps_region(rec), "overlapping reserved regions");

  return insert_record(rec);
}
示例#2
0
/*
 * This function has to be called for each recursion into the inter-hunk
 * parts, as previously non-unique lines can become unique when being
 * restricted to a smaller part of the files.
 *
 * It is assumed that env has been prepared using xdl_prepare().
 */
static int fill_hashmap(mmfile_t *file1, mmfile_t *file2,
		xpparam_t const *xpp, xdfenv_t *env,
		struct hashmap *result,
		int line1, int count1, int line2, int count2)
{
	result->file1 = file1;
	result->file2 = file2;
	result->xpp = xpp;
	result->env = env;

	/* We know exactly how large we want the hash map */
	result->alloc = count1 * 2;
	result->entries = (struct entry *)
		xdl_malloc(result->alloc * sizeof(struct entry));
	if (!result->entries)
		return -1;
	memset(result->entries, 0, result->alloc * sizeof(struct entry));

	/* First, fill with entries from the first file */
	while (count1--)
		insert_record(xpp, line1++, result, 1);

	/* Then search for matches in the second file */
	while (count2--)
		insert_record(xpp, line2++, result, 2);

	return 0;
}
示例#3
0
// we do consolidate committed regions
bool VMMemPointerIterator::add_committed_region(MemPointerRecord* rec) {
  assert(rec->is_commit_record(), "Sanity check");
  VMMemRegion* reserved_rgn = (VMMemRegion*)current();
  assert(reserved_rgn->is_reserved_region() && reserved_rgn->contains_region(rec),
    "Sanity check");

  // thread's native stack is always marked as "committed", ignore
  // the "commit" operation for creating stack guard pages
  if (FLAGS_TO_MEMORY_TYPE(reserved_rgn->flags()) == mtThreadStack &&
      FLAGS_TO_MEMORY_TYPE(rec->flags()) != mtThreadStack) {
    return true;
  }

  // if the reserved region has any committed regions
  VMMemRegion* committed_rgn  = (VMMemRegion*)next();
  while (committed_rgn != NULL && committed_rgn->is_committed_region()) {
    // duplicated commit records
    if(committed_rgn->contains_region(rec)) {
      return true;
    } else if (committed_rgn->overlaps_region(rec)) {
      // overlaps front part
      if (rec->addr() < committed_rgn->addr()) {
        committed_rgn->expand_region(rec->addr(),
          committed_rgn->addr() - rec->addr());
      } else {
        // overlaps tail part
        address committed_rgn_end = committed_rgn->addr() +
              committed_rgn->size();
        assert(committed_rgn_end < rec->addr() + rec->size(),
             "overlap tail part");
        committed_rgn->expand_region(committed_rgn_end,
          (rec->addr() + rec->size()) - committed_rgn_end);
      }
    } else if (committed_rgn->base() + committed_rgn->size() == rec->addr()) {
      // adjunct each other
      committed_rgn->expand_region(rec->addr(), rec->size());
      VMMemRegion* next_reg = (VMMemRegion*)next();
      // see if we can consolidate next committed region
      if (next_reg != NULL && next_reg->is_committed_region() &&
        next_reg->base() == committed_rgn->base() + committed_rgn->size()) {
          committed_rgn->expand_region(next_reg->base(), next_reg->size());
          // delete merged region
          remove();
      }
      return true;
    } else if (committed_rgn->base() > rec->addr()) {
      // found the location, insert this committed region
      return insert_record(rec);
    }
    committed_rgn = (VMMemRegion*)next();
  }
  return insert_record(rec);
}
示例#4
0
/* 1. Split: choose a new frame other than the one containing parent page. Write
      it out if it's used and then load it with a new page. Update the index accordingly.
   2. Redistributes records in the parent page. Overflow page may exist. Mind it!
   3. The insert the record again. If insertion fails, add an overflow page and insert
      it into the overflow page. */
void split_page_insert_again (struct page *target_page, char *depot, int *pos,
								bool *finished, bool *split, FILE *out_stream)
{
	int new_page_fnum;
	unsigned int pid_again;
	int ovp_pid;
	struct page *new_page, *overflow_page;
	char s_key[20];

	target_page->pin_cnt++;
	new_page_fnum = choose ();
	new_page = &buffer[new_page_fnum];
	target_page->pin_cnt--;

	if (used[new_page_fnum])
	{
		fseek (out_stream, sizeof (struct page) * new_page->pid, SEEK_SET);
		fwrite (new_page, sizeof (struct page), 1, out_stream);
	}
	used[new_page_fnum] = true;

	//prepare_page (target_page, tmp);
	init_page (new_page, target_page->local_depth + 1);
	update_index (target_page->pid, new_page->pid, target_page->local_depth + 1,
					power (2, target_page->local_depth), out_stream);

	unsigned int pid1 = target_page->pid, pid2 = new_page->pid; // debug
	redistribute (target_page, new_page, out_stream);
	assert (pid1 == target_page->pid && pid2 == new_page->pid); // debug
	*split = false;

	get_search_key (s_key, depot, *pos);
	pid_again = *index (hash_func(s_key), out_stream);
	if (pid_again == target_page->pid)
		ovp_pid = insert_record (target_page, depot, pos, finished, split, out_stream, true);
	else if (pid_again == new_page->pid)
		ovp_pid = insert_record (new_page, depot, pos, finished, split, out_stream, true);
	else
	{
		printf ("Page number panic!\n");
		exit (1);
	}

	if (*split)		// add overflow page.
	{
		assert (ovp_pid != -2 && ovp_pid != -3); // debug
		overflow_page = add_overflow_page (ovp_pid, out_stream);
		insert_record (overflow_page, depot, pos, finished, split, out_stream);
	}
}
示例#5
0
/* 1. Use the target_key to find the corresponding bucket. Read it into buffer if necessary.
   2. Make use of the directory to traverse each record in the bucket. Compare each search
      key value to the value of target_key. If they are equal, copy the record to the result
	  page.
   3. If there is any overflow pages, repeat step 2 for those pages as well.
   P.S. The result page should have been initialized. */
bool search_by_key (const char *target_key, struct page *result, FILE *data_stream)
{
	unsigned int target_pid = *index (hash_func (target_key), data_stream);
	int target_fnum = find_target_frame (target_pid, data_stream);
	int start_offset, ovp_pid;
	char s_key[20];
	bool dummy, overflow = false;

	assert (result->dirctory[0] == 0 && result->dirctory[1] == 1);	// The result page should be empty.

	do
	{
		for (int i = 0; i < buffer[target_fnum].dirctory[1] -1; i++)
		{
			start_offset = buffer[target_fnum].dirctory[i + 2];
			get_search_key (s_key, buffer[target_fnum].data, start_offset);
			if (strcmp (target_key, s_key) == 0)
				insert_record (result, buffer[target_fnum].data, &start_offset, &dummy, &overflow, data_stream);

			assert (overflow == false);	// The result cannot over one page size recently.
		}

		if ((ovp_pid = buffer[target_fnum].opid) != -1)
		{
			target_pid = ovp_pid;
			target_fnum = find_target_frame (target_pid, data_stream);
		}
	} while (ovp_pid != -1);

	if (result->dirctory[1] == 1)
		return false;		// No such record.
	return true;
}
示例#6
0
void events_add( EVENT_TYPE et, char *info1, char *info2 )
{
	event_type new_event;
	
	id = id + 1;
	new_event.id    = id;
	new_event.type  = et;
	new_event.info1 = NULL;
	new_event.info2 = NULL;

	if ( info1 != NULL ) {
		new_event.info1 = malloc( strlen( info1 ) + 1 );
		strcpy( new_event.info1, info1 );
		//printf( "event_info1[%s]\n", info1 );
	}
	
	if ( info2 != NULL ) {
		new_event.info2 = malloc( strlen( info2 ) + 1 );
		strcpy( new_event.info2, info2 );
		//printf( "event_info2[%s]\n", info1 );
	}

	insert_record( &game_events, &new_event );

}
示例#7
0
bool VMMemPointerIterator::insert_reserved_region(MemPointerRecord* rec) {
  // skip all 'commit' records associated with previous reserved region
  VMMemRegion* p = (VMMemRegion*)next();
  while (p != NULL && p->is_committed_region() &&
         p->base() + p->size() < rec->addr()) {
    p = (VMMemRegion*)next();
  }
  return insert_record(rec);
}
示例#8
0
/******************************************************
 Search/Insert/Delete
 based on input flag determines whether to go to the search insert or delete function
 */
void searchOrInsert(FILE *fp, int insertflag, FILE **fpInput)
{
    
    char line[100];
    long address;
    char *lastname;
    char *firstname;
    int id;
    char * idstring;
    double amount=0.0;
    char *amtstring;
    char *end;
    
    if (insertflag==2)
        printf("\nDELETE\n");
    else if (insertflag==1)
        printf("\nINSERT\n");
    else
        printf("\nSEARCH\n");

    while(printf("Enter student id, last name, first name, and amount or quit to stop: "), fgets(line, sizeof(line), stdin), strcmp(line, "quit\n") != 0)
    {
        idstring = strtok(line, "\040\t");
        id=atoi(idstring);
        lastname=strtok(NULL, "\040\t");
        firstname=strtok(NULL, "\040\t");
        amtstring=strtok(NULL, "\n");
        if (amtstring)
        {
            amount=strtod(amtstring, &end);
            if (*end == '\0')
                printf("\n");
            else
                printf("Not a number: it contains %c!\n", *end);
        }
        
        isValid(lastname, firstname, id, amount);
        printf("%d %s %s %.2f\n", id, lastname, firstname, amount);
        
        address = hash(idstring, 100);
        if (insertflag==2)
        {
            delete_record(lastname, firstname, id, amount, address, fp);
        }
        else if (insertflag==1)
        {
            insert_record(lastname, firstname, id, amount, address, fp);
        }
        else
        {
            search_record(lastname, firstname, id, amount, address, fp);
        }
    }
    return;
}
示例#9
0
文件: gui.c 项目: shr-project/e-tasks
void save_button_clicked(void *data, Evas_Object *obj, void *event_info)
{
	char te_data[255], *task_entry;
	
	//get task no
	Elm_Object_Item *item = (Elm_Object_Item *)elm_genlist_selected_item_get(list);
	if (item) {
		_Task *tsk = (_Task *)elm_object_item_data_get(item);
		
		//get data from entry
		sprintf(te_data, "%s", (const char *)elm_entry_entry_get(tk));
		task_entry = strtok(te_data, "<");
		sprintf(tsk->text, "%s", task_entry);
		
		//save data to database
		update_record(tsk->no);
		elm_genlist_item_update(task_list[tsk->no]);
	}
	else { //add a new record with this data
		time_t curtime;
		struct tm *loctime;
		char dt[6], te_data[255], *task_entry;
		int i = total_tasks;

		total_tasks ++;
		
		//get the time
		curtime = time (NULL);
		loctime = localtime (&curtime);
		strftime(dt, 6, "%d-%m", loctime);

		Task[i].no = i;
		Task[i].cb = 0;
		if (dummy_pr) Task[i].pr = dummy_pr;
		else Task[i].pr = 1;
		//get entry data
		sprintf(te_data, "%s", (const char *)elm_entry_entry_get(tk));
		task_entry = strtok(te_data, "<");
		if (strcmp(task_entry, "") !=0) strcpy(Task[i].text, task_entry);
		else strcpy(Task[i].text, "Task");
		//set current date
		if (strcmp(dummy_date, "") != 0) strcpy(Task[i].date, dummy_date);
		else strcpy(Task[i].date, dt);
		if(strcmp(sel_category, " All Tasks ")==0) strcpy(Task[i].cat, "Personal");
		else strcpy(Task[i].cat, sel_category);
		task_list[i] = elm_genlist_item_append(list, &itc1, &Task[i], NULL, ELM_GENLIST_ITEM_NONE,
							 	 	NULL, NULL);
		last_rec = -1;
		//insert record
		insert_record(i);
		elm_genlist_item_selected_set(task_list[i], 1);
	}
}
bool db_tab_widget::set_model(db_relational_model *model)
{
  // Init the model
  pv_table_model = model;
  pv_table_model->set_user_headers();
  //pv_table_model->setEditStrategy(QSqlTableModel::OnManualSubmit);
  lb_user_table_name->setText(pv_table_model->get_user_table_name());

  // Init the view
  pv_tab_view = new db_tab_view(this);
  pv_tab_view->setModel(pv_table_model);
  //pv_tab_view->display_nav();
  if(pv_table_model->editStrategy() == QSqlTableModel::OnManualSubmit){
    pv_tab_view->set_auto_submit(false);
    std::cout << "****  Auto submit OFF, edit strategy: " << pv_table_model->editStrategy() << std::endl;
  }else{
    pv_tab_view->set_auto_submit(true);
    std::cout << "****  Auto submit ON, edit strategy: " << pv_table_model->editStrategy() << std::endl;
  }

  pv_layout->addWidget(pv_tab_view);

  // Signal from tab_view whenn selected
  connect( pv_tab_view,
    SIGNAL(current_row_changed(int)),
    this, SLOT(current_row_changed(int)) );

  connect( this,
    SIGNAL(sig_current_row_changed(const QModelIndex&)),
    pv_table_model, SLOT(current_row_changed(const QModelIndex&)) );

  //connect( 
/*
  connect(myTableView->selectionModel(), SIGNAL(currentRowChanged(QModelIndex,QModelIndex)),
         mapper, SLOT(setCurrentModelIndex(QModelIndex)));
*/
/*
  connect(
    pv_table_model, SIGNAL(beforeInsert(QSqlRecord&)),
    this, SLOT(as_child_before_insert(QSqlRecord&) )
  );
*/
  connect( pv_tab_view, SIGNAL(sig_delete_row(int)), this, SLOT(delete_record(int)));
  connect( pv_tab_view, SIGNAL(sig_insert_row()), this, SLOT(insert_record()));
  connect( pv_tab_view, SIGNAL(sig_submit(int)), this, SLOT(submit_all(int)));
  connect( pv_tab_view, SIGNAL(sig_revert()), this, SLOT(revert_all()));

  pv_table_model->setSort(0, Qt::AscendingOrder);
  select();

  return true;
}
示例#11
0
文件: db.c 项目: SanketDG/db_c
int main(int argc, char *argv[])
{

    int fd;
    person_record rec;

    /* fd = open_record("data1"); */

    if(argc > 1)
    {
        // insert data

        if(argc > 5 && !strcmp(argv[1], "insert"))
        {
            fd = update_record("data1", 1);
            rec.key = atoi(argv[2]);
            strcpy(rec.fname, argv[3]);
            strcpy(rec.lname, argv[4]);
            rec.age = atoi(argv[5]);

            insert_record(fd, &rec);
        }

        /* delete data */

        if(argc > 2 && !strcmp(argv[1], "delete"))
        {
            fd = update_record("data1", 0);
            delete_record(fd, atoi(argv[2]));
        }

        /* print data */

        if(argc > 2 && !strcmp(argv[1], "print"))
        {
            fd = update_record("data1", 1);

            get_record(fd, &rec, atoi(argv[2]));

            printf("key = %d\n", rec.key);
            printf("First = %s\n", rec.fname);
            printf("Last = %s\n", rec.lname);
            printf("Age = %d\n", rec.age);
        }
    }

    close_record(fd);
    return 0;
}
示例#12
0
文件: gui.c 项目: shr-project/e-tasks
void create_new_task(void *data, Evas_Object *obj, void *event_info)
{
	int i = total_tasks;
	total_tasks ++;

	if(strcmp(sel_category, "Deleted") == 0) {
		purge_tasks();
		elm_genlist_clear(list);
		return;
	}
	time_t curtime;
	struct tm *loctime;
	char dt[6];
	
	//get the time
	curtime = time (NULL);
	loctime = localtime (&curtime);
	strftime(dt, 6, "%d-%m", loctime);
	
	//get selected task if any
	Evas_Object *li = data;
	Elm_Object_Item *item = (Elm_Object_Item *)elm_genlist_selected_item_get(li);
	if (!item) item = elm_genlist_last_item_get(list);	//insert new line at end of list

	Task[i].no = i;
	Task[i].cb = 0;
	Task[i].pr = 1;
	strcpy(Task[i].text, "Task");
	strcpy(Task[i].date, dt);
	if(strcmp(sel_category, " All Tasks ")==0) strcpy(Task[i].cat, "Personal");
	else strcpy(Task[i].cat, sel_category);
	if(item) { 
		task_list[i] = elm_genlist_item_insert_after(list, &itc1, &Task[i], NULL, item, ELM_GENLIST_ITEM_NONE,
								  NULL, NULL);
	}
	//cater for no items in list
	else task_list[i] = elm_genlist_item_append(list, &itc1, &Task[i], NULL, ELM_GENLIST_ITEM_NONE,
								  NULL, NULL);
	last_rec = -1;
	WRITE = 0;
	//insert record
	//printf("total %d\n", i);
	insert_record(i);
	elm_genlist_item_selected_set(task_list[i], 1);
}
示例#13
0
/*****************************************************************
 Hashing to disk: search or insert
 */
void insertFromInFile(FILE *fp, int insertflag, FILE **fpInput)
{
    
    char line[100];
    long address;
    char *lastname;
    char *firstname;
    int id;
    char * idstring;
    double amount;
    char *amtstring;
    char *end;
    
    printf("%s\n", insertflag ? "\nINSERT" : "\nSEARCH");
    while(fgets(line, sizeof(line), *fpInput)!=NULL)
    {
        idstring = strtok(line, "\040\t");
        id=atoi(idstring);
        lastname=strtok(NULL, "\040\t");
        firstname=strtok(NULL, "\040\t");
        amtstring=strtok(NULL, "\n");
        amount=strtod(amtstring, &end);
        if (*end == '\0')
            //printf("%f\n", amount);
            printf("\n");
        else
            printf("Not a number: it contains %c!\n", *end);
        
        
        printf("%d %s %s %.2f\n", id, lastname, firstname, amount);
        isValid(lastname, firstname, id, amount);
        address = hash(idstring, 100);
        if (insertflag)
        {
            insert_record(lastname, firstname, id, amount, address, fp);
        }
        else
        {
            search_record(lastname, firstname, id, amount, address, fp);
        }
    }
    return;
}
示例#14
0
FILE *data_import (FILE *in_stream, FILE *out_stream)
{
	char depot[DEPOT_SIZE];
	char remainder[200];
	char s_key[20];
	int r_num = 0;
	int target_frame;
	int pos;				// The next position in depot to be operated.
	bool finished, split;

	while (!feof (in_stream))
	{
		finished = split = false;
		pos = 0;

		bulk_read (depot, remainder, &r_num, in_stream);

		while (!finished)						// If depot hasn't been used up, loop again.
		{
		//int j = 10;
		//while (j--){
			get_search_key (s_key, depot, pos);
			target_frame = find_target_frame (*index (hash_func (s_key), out_stream), out_stream);
			
			unsigned int pid1 = buffer[target_frame].pid; // debug
			insert_record (&buffer[target_frame], depot, &pos, &finished, &split, out_stream);
			assert (pid1 == buffer[target_frame].pid); // debug
		//}
		//for (j = 0; j < BUFFER_NUM; j++ )
		//	printf ("\n\n%d\n%s\n\n", buffer[j].pid, buffer[j].data);
			if (split)
			{
				split_page_insert_again (&buffer[target_frame], depot, &pos, &finished, &split, out_stream);
				split = false;
			}
		} // while (!finished)
		pos = 0; // debug
	} // while (!feof (in_stream))

	return out_stream;
}
示例#15
0
文件: 450.c 项目: ksyu/uvajudge
int main()
{
    char ch;
    list_t *t, *h = NULL;
    
    scanf("%*d");
    
    while(ch = getc(stdin), ch != EOF)
    {
        if(ch == '\n')
        {
            scanf("%[^\n]", dbuf), getchar();
        }
        else
        {
            ungetc(ch, stdin);
            scanf("%[^\n]", buf), getchar();
            t = parse_record(dbuf, buf);
            h = insert_record(h, t);
            buf[0] = NULL;
        }
    }
    
    t = h;
    while(t)
    {
        printf("----------------------------------------\n");
        printf("%s %s %s\n", t->rec->title, t->rec->fname, t->rec->lname);
        printf("%s\n", t->rec->adrs);
        printf("Department: %s\n", t->rec->dept);
        printf("Home Phone: %s\n", t->rec->hphone);
        printf("Work Phone: %s\n", t->rec->wphone);
        printf("Campus Box: %s\n", t->rec->cambox);
        
        t = t->next;
    }
    
    return 0;
}
示例#16
0
static int load_sca_info_from_db(void)
{
	db_res_t * res = NULL;
	db_val_t * values;
	db_row_t * rows;
	int i, j, nr_rows;
	unsigned int valid_record;
	unsigned int n_result_cols = 0;
	unsigned int shared_line_col, watchers_col;
	unsigned int app_shared_entity_col[MAX_APPEARANCE_INDEX];
	unsigned int app_call_state_col[MAX_APPEARANCE_INDEX];
	unsigned int app_call_info_uri_col[MAX_APPEARANCE_INDEX];
	unsigned int app_call_info_appearance_uri_col[MAX_APPEARANCE_INDEX];
	unsigned int app_b2bl_key_col[MAX_APPEARANCE_INDEX];
	db_key_t q_cols[SCA_TABLE_TOTAL_COL_NO];

	str shared_line, watchers_csv;
	//str_lst_t *watchers;
	//unsigned int size, watcher_size, watchers_no;
	//unsigned int size;
	unsigned int hash_index;
	//char *p;
	b2b_sca_record_t *record;
	b2b_sca_call_t *call;
	unsigned int shared_entity, appearance_index, call_state;
	str call_info_uri, call_info_apperance_uri, b2bl_key;
	b2bl_cb_ctx_t *cb_params;

	if(use_sca_table()) return -1;

	q_cols[shared_line_col = n_result_cols++] = &shared_line_column;
	q_cols[watchers_col = n_result_cols++] = &watchers_column;

	for (i=0; i<MAX_APPEARANCE_INDEX; i++) {
		q_cols[app_shared_entity_col[i]	= n_result_cols++] = &app_shared_entity_column[i];
		q_cols[app_call_state_col[i] = n_result_cols++] = &app_call_state_column[i];
		q_cols[app_call_info_uri_col[i] = n_result_cols++] = &app_call_info_uri_column[i];
		q_cols[app_call_info_appearance_uri_col[i] = n_result_cols++] =
						&app_call_info_appearance_uri_column[i];
		q_cols[app_b2bl_key_col[i] = n_result_cols++] = &app_b2bl_key_column[i];
	}

	/* select the whole tabel and all the columns */
	if (DB_CAPABILITY(sca_dbf, DB_CAP_FETCH)) {
		if(sca_dbf.query(sca_db_handle, 0, 0, 0, q_cols, 0,
				SCA_TABLE_TOTAL_COL_NO, 0, 0) < 0) {
			LM_ERR("Error while querying (fetch) database\n");
			return -1;
		}
		if(sca_dbf.fetch_result(sca_db_handle, &res, SCA_FETCH_SIZE)<0){
			LM_ERR("fetching rows failed\n");
			return -1;
		}
	} else {
		if(sca_dbf.query(sca_db_handle, 0, 0, 0, q_cols, 0,
				SCA_TABLE_TOTAL_COL_NO, 0, &res) < 0) {
			LM_ERR("Error while querying database\n");
			return -1;
		}
	}

	nr_rows = RES_ROW_N(res);

	do {
		LM_DBG("loading [%i] records from db\n", nr_rows);
		rows = RES_ROWS(res);
		/* for every row/record */
		for(i=0; i<nr_rows; i++){
			values = ROW_VALUES(rows + i);
			if (VAL_NULL(values+shared_line_col) || VAL_NULL(values+watchers_col)) {
				LM_ERR("columns [%.*s] or/and [%.*s] cannot be null -> skipping\n",
					shared_line_column.len, shared_line_column.s,
					watchers_column.len, watchers_column.s);
				continue;
			}
			shared_line.s = (char*)values[shared_line_col].val.string_val;
			shared_line.len = strlen(shared_line.s);

			watchers_csv.s = (char*)values[watchers_col].val.string_val;
			watchers_csv.len = strlen(watchers_csv.s);

			record = restore_record(&shared_line, &watchers_csv);
			if (record == NULL)
				goto error;
			hash_index = core_hash(&shared_line, NULL, b2b_sca_hsize);

			j = 0;
			while (j < MAX_APPEARANCE_INDEX) {
				if(	VAL_NULL(values + app_shared_entity_col[j]) ||
					VAL_NULL(values + app_call_state_col[j]) ||
					VAL_NULL(values + app_call_info_uri_col[j]) ||
					VAL_NULL(values + app_call_info_appearance_uri_col[j]) ||
					VAL_NULL(values + app_b2bl_key_col[j]) ) {
					goto cont;
				}
				appearance_index = j + 1;
				/* 1 - get shared_entity */
				shared_entity = values[app_shared_entity_col[j]].val.int_val;
				if (shared_entity!=0 && shared_entity!=1) {
					LM_ERR("Unexpected shared_entity [%d] "
						"for shared_line [%.*s]\n",
						shared_entity, shared_line.len, shared_line.s);
					goto cont;
				}
				/* 2 - get call_state */
				call_state = values[app_call_state_col[j]].val.int_val;
				if (call_state == IDLE_STATE) {
					LM_DBG("empty call[%d]\n", appearance_index);
					goto cont;
				}
				if (call_state > MAX_INDEX_STATE) {
					LM_ERR("Unexpected call_state [%d] for shared_line [%.*s]\n",
						call_state, shared_line.len, shared_line.s);
					goto cont;
				}
				/* 3 - get call_info_uri */
				call_info_uri.s =
					(char*)values[app_call_info_uri_col[j]].val.string_val;
				if (call_info_uri.s)
					call_info_uri.len = strlen(call_info_uri.s);
				else {
					LM_ERR("Missing call_info_uri for shared_line [%.*s][%d]\n",
						shared_line.len, shared_line.s, appearance_index);
					goto cont;
				}
				LM_DBG("call_info_uri=[%.*s]\n",
					call_info_uri.len, call_info_uri.s);
				/* 4 - get call_info_apperance_uri */
				call_info_apperance_uri.s =
					(char*)
					values[app_call_info_appearance_uri_col[j]].val.string_val;
				if (call_info_apperance_uri.s)
					call_info_apperance_uri.len =
						strlen(call_info_apperance_uri.s);
				else {
					LM_ERR("Missing call_info_apperance_uri for "
						"shared_line [%.*s][%d]\n",
						shared_line.len, shared_line.s, appearance_index);
					goto cont;
				}
				LM_DBG("call_info_apperance_uri=[%.*s]\n",
					call_info_apperance_uri.len, call_info_apperance_uri.s);
				/* 5 - get b2bl_key */
				b2bl_key.s = (char*)values[app_b2bl_key_col[j]].val.string_val;
				if (b2bl_key.s) {
					b2bl_key.len = strlen(b2bl_key.s);
					if (b2bl_key.len > B2BL_MAX_KEY_LEN) {
						LM_ERR("buffer overflow on b2bl_key [%.*s]"
							" for shared_line [%.*s][%d]\n",
							b2bl_key.len, b2bl_key.s,
							shared_line.len, shared_line.s,
							appearance_index);
						goto cont;
					}
					LM_DBG("b2bl_key=[%.*s]\n", b2bl_key.len, b2bl_key.s);
				} else {
					LM_ERR("Missing b2bl_key for shared_line [%.*s][1]\n",
						shared_line.len, shared_line.s);
					goto cont;
				}
				/* restore the call */
				call = restore_call(record, appearance_index,
					shared_entity, call_state,
					&call_info_uri, &call_info_apperance_uri);
				if (call == NULL) {
					goto error;
				}
				/* update record */
				if (0!=b2b_sca_update_call_record_key(call, &b2bl_key)) {
					LM_ERR("Unable to update b2bl_key [%.*s]\n",
						b2bl_key.len, b2bl_key.s);
					shm_free(call);
					call = NULL;
					record->call[appearance_index-1] = NULL;
					goto cont;
				}
				/* Prepare b2b_logic callback params. */
				cb_params = build_cb_params(hash_index,
							&shared_line, appearance_index);
				if (cb_params == NULL) {
					LM_ERR("Unable to build cb_params\n");
					goto error;
				}
				/* re-register callbacks */
				if(b2bl_api.register_cb(&b2bl_key, &sca_logic_notify, cb_params,
					B2B_RE_INVITE_CB|B2B_CONFIRMED_CB|B2B_DESTROY_CB) != 0){
					LM_ERR("Unable register b2b cb\n");
					shm_free(call);
					call = NULL;
					record->call[appearance_index-1] = NULL;
					goto cont;
				}
cont:
				j++;
			}

			valid_record = j = 0;
			while (j < MAX_APPEARANCE_INDEX) {
				if (record->call[j]) {
					valid_record = 1;
					goto check_valid_record;
				}
				j++;
			}
check_valid_record:
			if (valid_record) {
				b2b_sca_print_record(record);
				insert_record(hash_index, record);
			} else {
				LM_DBG("removing the record from db!\n");
				delete_sca_info_from_db(record);
			}
			LM_DBG("Done\n");
		}

		/* any more data to be fetched ?*/
		if (DB_CAPABILITY(sca_dbf, DB_CAP_FETCH)) {
			if (sca_dbf.fetch_result(sca_db_handle, &res, SCA_FETCH_SIZE)<0) {
				LM_ERR("fetching more rows failed\n");
				goto error;
			}
			nr_rows = RES_ROW_N(res);
		} else {
			nr_rows = 0;
		}
	}while (nr_rows>0);

	sca_dbf.free_result(sca_db_handle, res);
	return 0;
error:
	sca_dbf.free_result(sca_db_handle, res);
	return -1;
}
示例#17
0
/**
 * @brief Recovery system based on log file
 */
void WriteBehindFrontendLogger::DoRecovery() {
  // Set log file size
  log_file_size = GetLogFileSize(log_file_fd);

  // Go over the log size if needed
  if (log_file_size > 0) {
    bool reached_end_of_file = false;

    // check whether first item is LOGRECORD_TYPE_TRANSACTION_COMMIT
    // if not, no need to do recovery.
    // if yes, need to replay all log records before we hit
    // LOGRECORD_TYPE_TRANSACTION_DONE
    bool need_recovery = NeedRecovery();
    if (need_recovery == true) {
      TransactionRecord dummy_transaction_record(LOGRECORD_TYPE_INVALID);
      cid_t current_commit_id = INVALID_CID;

      // Go over each log record in the log file
      while (reached_end_of_file == false) {
        // Read the first byte to identify log record type
        // If that is not possible, then wrap up recovery
        LogRecordType log_type = GetNextLogRecordType(log_file, log_file_size);

        switch (log_type) {
          case LOGRECORD_TYPE_TRANSACTION_DONE:
          case LOGRECORD_TYPE_TRANSACTION_COMMIT: {
            // read but do nothing
            ReadTransactionRecordHeader(dummy_transaction_record, log_file,
                                        log_file_size);
          } break;

          case LOGRECORD_TYPE_WBL_TUPLE_INSERT: {
            TupleRecord insert_record(LOGRECORD_TYPE_WBL_TUPLE_INSERT);
            ReadTupleRecordHeader(insert_record, log_file, log_file_size);

            auto insert_location = insert_record.GetInsertLocation();
            auto info = SetInsertCommitMark(insert_location);
            current_commit_id = info.first;
          } break;

          case LOGRECORD_TYPE_WBL_TUPLE_DELETE: {
            TupleRecord delete_record(LOGRECORD_TYPE_WBL_TUPLE_DELETE);
            ReadTupleRecordHeader(delete_record, log_file, log_file_size);

            auto delete_location = delete_record.GetDeleteLocation();
            auto info = SetDeleteCommitMark(delete_location);
            current_commit_id = info.first;
          } break;

          case LOGRECORD_TYPE_WBL_TUPLE_UPDATE: {
            TupleRecord update_record(LOGRECORD_TYPE_WBL_TUPLE_UPDATE);
            ReadTupleRecordHeader(update_record, log_file, log_file_size);

            auto delete_location = update_record.GetDeleteLocation();
            SetDeleteCommitMark(delete_location);

            auto insert_location = update_record.GetInsertLocation();
            auto info = SetInsertCommitMark(insert_location);
            current_commit_id = info.first;
          } break;

          default:
            reached_end_of_file = true;
            break;
        }
      }

      // Update latest commit id
      if (latest_commit_id < current_commit_id) {
        latest_commit_id = current_commit_id;
      }

      // write out a trasaction done log record to file
      // to avoid redo next time during recovery
      WriteTransactionLogRecord(
          TransactionRecord(LOGRECORD_TYPE_TRANSACTION_DONE));
    }

    // After finishing recovery, set the next oid with maximum oid
    // observed during the recovery
    auto &manager = catalog::Manager::GetInstance();
    manager.SetNextOid(max_oid);
  }
}
示例#18
0
/* Each record is terminated with a '\n'.
   1. copy the record start at depot[pos] character by character, until '\n' or
      fsp == DEPOT_SIZE.
   2. If '\n' is encountered, insertion succeeded. If next character is '\0' or
      i == DEPOT_SIZE, finished = true;
   3. If fsp == DEPOT_SIZE, the page is full. If there is an overflow page, get
      it, and repeat insertion for it. If finally no more overflow page exists,
	  then insertion failed. Thus, split = true. Fill remainders with '\0'.
   4. return the pid of the last overflow page for cascading new overflow page. */
int insert_record (struct page *target_page, const char *depot, int *pos,
					bool *finished, bool *split, FILE *out_stream, bool forced)
{
	assert (*pos < DEPOT_SIZE && *pos >= 0);
	//printf ("\n%d ", *pos);

	int i;
	int fnum_for_ovp;
	int last_opid = target_page->pid;		// return -2 if insertion is succeed.
											// return -3 if depot is empty.
											// otherwise, it's the pid of the last overflow
											// page (self inclusive).
	unsigned int fsp = target_page->dirctory[0];
	if (!forced)
		target_page->pin_cnt++;

	for (i = *pos; depot[i] != '\0' && depot[i] != '\n' && fsp < DEPOT_SIZE; i++)
		target_page->data[fsp++] = depot[i];

	if (depot[i] == '\0')
	{
		assert (i == 0); // debug
		*finished = true;
		*split = false;
		return -3;
	}
	else if (depot[i] == '\n' && fsp < DEPOT_SIZE)
	{
		target_page->data[fsp++] = depot[i++];
		if (i == DEPOT_SIZE || depot[i] == '\0')
			*finished = true;
		else
			*finished = false;
		*pos = i;
		target_page->dirctory[++target_page->dirctory[1]] = target_page->dirctory[0];
		target_page->dirctory[0] = fsp;
		*split = false;
		last_opid = -2;
	}
	else
	{
		for (fsp = target_page->dirctory[0]; fsp < DEPOT_SIZE; fsp++)
			target_page->data[fsp] = '\0';
		
		*split = true;
		*finished = false;

		if (target_page->opid != -1)
		{
			fnum_for_ovp = find_target_frame (target_page->opid, out_stream);
			last_opid = insert_record (&buffer[fnum_for_ovp], depot, pos, finished, split, out_stream, true);
			if (last_opid == -2)
				last_opid = target_page->opid;
		}
	}

	//printf ("%d  %d\n", *pos, fsp);
	if (!forced)
	{
		target_page->pin_cnt--;
		target_page->ref_bit = true;
	}
	return last_opid;
}
示例#19
0
/* 1. Redistribute the records in splited_page to itself and its split.
   2. If splited_page has overflow page(s), also do redistribution for
      it(them).
   3. If split_page is full, add overflow page cascading it and continue
      redistribution by using the overflow page. */
void redistribute (struct page *splited_page, struct page *split_page, FILE *out_stream)
{
	struct page *p_ovp = splited_page, *s_ovp = split_page;
	bool finished, overflow;
	unsigned int target_pid;
	int ovp_pid;
	int tmp_pos, ovp_fnum;
	char s_key[20];
	char tmp[DEPOT_SIZE];

	splited_page->pin_cnt++;
	split_page->pin_cnt++;

	do
	{
		prepare_page (p_ovp, tmp);
		tmp_pos = 0;
		finished = false;
		overflow = false;
		
		while (!finished)		// temp hasn't been used up
		{
			get_search_key (s_key, tmp, tmp_pos);
			target_pid = *index (hash_func (s_key), out_stream);

			if (target_pid == splited_page->pid)
			{
				s_ovp->pin_cnt++;
				insert_record (p_ovp, tmp, &tmp_pos, &finished, &overflow, out_stream, true);
				// sth wrong here. p_ovp contains incomplete record!!!
				s_ovp->pin_cnt--;
			}
			else if (target_pid == split_page->pid)
			{
				p_ovp->pin_cnt++;
				insert_record (s_ovp, tmp, &tmp_pos, &finished, &overflow, out_stream);
				p_ovp->pin_cnt--;
			}
			else
			{
				printf ("Page number panic!\n");
				exit (2);
			}

			if (overflow)
			{
				p_ovp->pin_cnt++;
				s_ovp = add_overflow_page (s_ovp->pid, out_stream);
				p_ovp->pin_cnt--;
				overflow = false;
			}
		} // while (!finished)

		if ((ovp_pid = p_ovp->opid) != -1)
		{
			s_ovp->pin_cnt++;
			ovp_fnum = find_target_frame (ovp_pid, out_stream);
			p_ovp = &buffer[ovp_fnum];
			s_ovp->pin_cnt--;
		}
	} while (ovp_pid != -1);

	splited_page->pin_cnt--;
	split_page->pin_cnt--;
}
示例#20
0
int bl_insert_record(PLATE_RECORD_T *pPlateRecord)
{
    return insert_record(szBlackListTable, pPlateRecord);
}
示例#21
0
int wl_insert_record(PLATE_RECORD_T *pPlateRecord)
{
    return insert_record(szWhiteListTable, pPlateRecord);
}
示例#22
0
int b2b_sca_add_call_record(int hash_index, str *shared_line,
		unsigned int shared_entity, unsigned int app_index,
		str *call_info_uri, str *call_info_apperance_uri,
		b2b_sca_record_t **record_ctx, b2b_sca_call_t **call_ctx)
{
	//b2b_sca_record_t *rec, *prev_rec;
	b2b_sca_record_t *record;
	b2b_sca_call_t *call;
	unsigned int i, size, watcher_size, watchers_no;
	char *p;
	str_lst_t *watchers;

	if (app_index>=MAX_APPEARANCE_INDEX) {
		LM_ERR("Required app_index [%d] too big\n", app_index);
		return -1;
	}

	record = b2b_sca_search_record_safe(hash_index, shared_line);
	if (record) {
		/* We already have active calls for this shared line */
		if (app_index) {
			i = app_index - 1;
			if (record->call[i]) {
				LM_DBG("Searching for a new slot\n");
				for (i=0; i<MAX_APPEARANCE_INDEX; i++) {
					if (record->call[i] == NULL)
						break;
				}
			}
		} else {
			LM_DBG("no forced app_index\n");
			for (i=0; i<MAX_APPEARANCE_INDEX; i++) {
				if (record->call[i] == NULL)
					break;
			}
		}
		if (i == MAX_APPEARANCE_INDEX) {
			LM_ERR("No available slots for this call\n");
			return -1;
		}
		call = restore_call(record, i+1, shared_entity, ALERTING_STATE,
				call_info_uri, call_info_apperance_uri);
		if (call == NULL) {
			return -1;
		}
	} else {
		/* First call for this shared line */

		/* Get the list of watchers */
		get_watchers_from_avp(&watchers, &watcher_size, &watchers_no);

		size = sizeof(b2b_sca_record_t) + shared_line->len + watcher_size;
		record = (b2b_sca_record_t *)shm_malloc(size);
		if (record == NULL) {
			LM_ERR("OOM\n");
			return -1;
		}
		memset(record, 0, size);
		p = (char*)(record + 1);

		record->watchers_no = watchers_no;
		record->shared_line.len = shared_line->len;
		record->shared_line.s = p;
		memcpy(p, shared_line->s, shared_line->len);
		p += shared_line->len;

		if (watchers && watcher_size) {
			record->watchers = (str_lst_t *)p;
			memcpy_watchers(record->watchers, watchers, watcher_size);
			if (watchers)
				free_watchers(watchers);
		} else {
			record->watchers = NULL;
			LM_WARN("We have no watchers: watchers=[%p] and watcher_size=[%d]\n",
				watchers, watcher_size);
		}

		/* Let's take care of the call now */
		call = restore_call(record, app_index?app_index:1, shared_entity, ALERTING_STATE,
				call_info_uri, call_info_apperance_uri);
		if (call == NULL)
			goto error;

		/* Insert record into the table */
		insert_record(hash_index, record);
		/*
		rec = b2b_sca_htable[hash_index].first;
		if (rec) {
			while(rec) {
				prev_rec = rec;
				rec = rec->next;
			}
			prev_rec->next = record;
			record->prev = prev_rec;
		} else {
			b2b_sca_htable[hash_index].first = record;
			record->prev = record->next = NULL;
		}
		*/
	}

	*record_ctx = record;
	*call_ctx = call;
	return 0;
error:
	shm_free(record);
	return -1;
}