bool Query_Processor::insert(QP_rule_t *qr, bool lock) {
	bool ret=true;
	if (lock) spin_wrlock(&rwlock);
	rules.push_back(qr);
	if (lock) spin_wrunlock(&rwlock);
	return ret;
};
Example #2
0
File: parms.c Project: dulton/nvr
int
free_vnode(_sbinfo sbinfo, vnode * v)
{
    //added by wsr 20121029
    char buf[Vnode_SIZE * MaxUsers];
    memset(buf, 0, Vnode_SIZE * MaxUsers);
    spin_wrlock(v->spin);
    buf_to_vnode(buf, v);
    spin_rwunlock(v->spin);
    //end
    spin_rwdestroy(v->spin);
    return clrbit_(sbinfo->vnodemapping, (address_of_pointer(v) - address_of_pointer(sbinfo->vnodeTable)) / (sizeof(vnode)));
}
Example #3
0
void KV_BtreeArray::empty() {
  spin_wrlock(&lock);

	btree::btree_map<uint64_t, QC_entry_t *>::iterator lookup;

	while (bt_map.size()) {
		lookup = bt_map.begin();
		if ( lookup != bt_map.end() ) {
			lookup->second->expire_ms=EXPIRE_DROPIT;
			//const char *f=lookup->first;
			bt_map.erase(lookup);
		}
	}
	spin_wrunlock(&lock);
};
Example #4
0
void KV_BtreeArray::purge_some(unsigned long long QCnow_ms) {
	uint64_t ret=0, i, _size=0;
	QC_entry_t *qce;
  spin_rdlock(&lock);
	for (i=0; i<ptrArray->len;i++) {
		qce=(QC_entry_t *)ptrArray->index(i);
		if (qce->expire_ms==EXPIRE_DROPIT || qce->expire_ms<QCnow_ms) {
			ret++;
			_size+=qce->length;
		}
	}
	freeable_memory=_size;
	spin_rdunlock(&lock);
	if ( (freeable_memory + ret * (sizeof(QC_entry_t)+sizeof(QC_entry_t *)*2+sizeof(uint64_t)*2) ) > get_data_size()*0.01) {
		uint64_t removed_entries=0;
		uint64_t freed_memory=0;
  	spin_wrlock(&lock);
		for (i=0; i<ptrArray->len;i++) {
			qce=(QC_entry_t *)ptrArray->index(i);
			if ((qce->expire_ms==EXPIRE_DROPIT || qce->expire_ms<QCnow_ms) && (__sync_fetch_and_add(&qce->ref_count,0)<=1)) {
				qce=(QC_entry_t *)ptrArray->remove_index_fast(i);

		    btree::btree_map<uint64_t, QC_entry_t *>::iterator lookup;
  				lookup = bt_map.find(qce->key);
     		if (lookup != bt_map.end()) {
					bt_map.erase(lookup);
				}
				i--;
				freed_memory+=qce->length;
				removed_entries++;
				free(qce->value);
				free(qce);
			}
		}
  	spin_wrunlock(&lock);
		THR_DECREASE_CNT(__thr_num_deleted,Glo_num_entries,removed_entries,1);
		if (removed_entries) {
			__sync_fetch_and_add(&Glo_total_freed_memory,freed_memory);
			__sync_fetch_and_sub(&Glo_size_values,freed_memory);
			__sync_fetch_and_add(&Glo_cntPurge,removed_entries);
//				if (removed_entries) fprintf(stderr,"Removed: %lu, total: %lu, arraylen: %d\n", removed_entries, __sync_fetch_and_sub(&Glo_num_entries,0), ptrArray.len);
//				if (removed_entries) firintf(stderr,"Size of  KVBtreeArray:%d , freed_memory:%lu, Glo_cntGet:%lu, Glo_cntGetOK:%lu, Glo_cntSet:%lu, cntPurge:%lu, dataIN:%lu, dataOUT:%lu\n", cnt() , Glo_total_freed_memory, Glo_cntGet, Glo_cntGetOK, Glo_cntSet, Glo_cntPurge, Glo_dataIN, Glo_dataOUT);
		}
	}
};
void Query_Processor::update_query_digest(void *p, MySQL_Connection_userinfo *ui, unsigned long long t, unsigned long long n) {
	SQP_par_t *qp=(SQP_par_t *)p;
	spin_wrlock(&digest_rwlock);

	QP_query_digest_stats *qds;	

	btree::btree_map<uint64_t, void *>::iterator it;
	it=digest_bt_map.find(qp->digest_total);
	if (it != digest_bt_map.end()) {
		// found
		qds=(QP_query_digest_stats *)it->second;
		qds->add_time(t,n);
	} else {
		qds=new QP_query_digest_stats(ui->username, ui->schemaname, qp->digest, qp->digest_text);
		qds->add_time(t,n);
		digest_bt_map.insert(std::make_pair(qp->digest_total,(void *)qds));
	}

	spin_wrunlock(&digest_rwlock);
}
Example #6
0
bool KV_BtreeArray::replace(uint64_t key, QC_entry_t *entry) {
  spin_wrlock(&lock);
	THR_UPDATE_CNT(__thr_cntSet,Glo_cntSet,1,100);
	THR_UPDATE_CNT(__thr_size_values,Glo_size_values,entry->length,100);
	THR_UPDATE_CNT(__thr_dataIN,Glo_dataIN,entry->length,100);
	THR_UPDATE_CNT(__thr_num_entries,Glo_num_entries,1,1);

	entry->ref_count=1;
  ptrArray->add(entry);
  btree::btree_map<uint64_t, QC_entry_t *>::iterator lookup;
  lookup = bt_map.find(key);
  if (lookup != bt_map.end()) {
		lookup->second->expire_ms=EXPIRE_DROPIT;
		__sync_fetch_and_sub(&lookup->second->ref_count,1);
		bt_map.erase(lookup);
 	}
	bt_map.insert(std::make_pair(key,entry));
	spin_wrunlock(&lock);
	return true;
}
SQLite3_result * Query_Processor::get_query_digests_reset() {
	SQLite3_result *result=new SQLite3_result(10);
	spin_wrlock(&digest_rwlock);
	result->add_column_definition(SQLITE_TEXT,"schemaname");
	result->add_column_definition(SQLITE_TEXT,"usernname");
	result->add_column_definition(SQLITE_TEXT,"digest");
	result->add_column_definition(SQLITE_TEXT,"digest_text");
	result->add_column_definition(SQLITE_TEXT,"count_star");
	result->add_column_definition(SQLITE_TEXT,"first_seen");
	result->add_column_definition(SQLITE_TEXT,"last_seen");
	result->add_column_definition(SQLITE_TEXT,"sum_time");
	result->add_column_definition(SQLITE_TEXT,"min_time");
	result->add_column_definition(SQLITE_TEXT,"max_time");
	for (btree::btree_map<uint64_t, void *>::iterator it=digest_bt_map.begin(); it!=digest_bt_map.end(); ++it) {
		QP_query_digest_stats *qds=(QP_query_digest_stats *)it->second;
		char **pta=qds->get_row();
		result->add_row(pta);
		qds->free_row(pta);
		delete qds;
	}
	digest_bt_map.erase(digest_bt_map.begin(),digest_bt_map.end());
	spin_wrunlock(&digest_rwlock);
	return result;
}
Example #8
0
File: parms.c Project: dulton/nvr
int
delete_vi(_sbinfo sbinfo, vnode * v, char mode, int key)
{
    _vnodeInfo vi, p;
    while (spin_wrlock(v->spin));
    if (mode == WriteRECORD) {
        vi = v->_bf;
        while(vi) {
            if (vi->status == WriteRECORD && vi->key == key)
                break;
            p = vi;
            vi = vi->next;
        }
    }
    else {
        vi = v->_bf;
        while(vi) {
            if (vi->status == ReadRECORD && vi->key == key)
                break;
            p = vi;
            vi = vi->next;
        }
    }
    if (!vi) {
        spin_rwunlock(v->spin);
        return -1;
    }
    if(vi == v->_bf)
        v->_bf = vi->next;
    else
        p->next = vi->next;
    spin_rwunlock(v->spin);
    //if(!v->_bf) spin_rwdestroy(v->spin);
// v->status--;
    return (((char *)vi) - (char *)sbinfo->_bf) / sizeof(struct vnodeInfo);
}
// when commit is called, the version number is increased and the this will trigger the mysql threads to get a new Query Processor Table
// The operation is asynchronous
void Query_Processor::commit() {
	spin_wrlock(&rwlock);
	__sync_add_and_fetch(&version,1);
	proxy_debug(PROXY_DEBUG_MYSQL_QUERY_PROCESSOR, 4, "Increasing version number to %d - all threads will notice this and refresh their rules\n", version);
	spin_wrunlock(&rwlock);
};
Example #10
0
void Query_Processor::sort(bool lock) {
	if (lock) spin_wrlock(&rwlock);
	proxy_debug(PROXY_DEBUG_MYSQL_QUERY_PROCESSOR, 4, "Sorting rules\n");
	std::sort (rules.begin(), rules.end(), rules_sort_comp_function);
	if (lock) spin_wrunlock(&rwlock);
};
Example #11
0
void Query_Processor::reset_all(bool lock) {
	if (lock) spin_wrlock(&rwlock);
	__reset_rules(&rules);
	if (lock) spin_wrunlock(&rwlock);
};
Example #12
0
void Query_Processor::wrlock() {
	spin_wrlock(&rwlock);
};
Example #13
0
File: parms.c Project: dulton/nvr
char *
extend_buf(vnode * v, _sbinfo sbinfo, char mode)
{
    int nr;
    uint8_t key = 0;
    _vnodeInfo vi, p;
    while (spin_trywrlock(sbinfo->_bh->spin));
    if ((nr = find_first_zero(sbinfo->_bh->map, MaxBufBitmapLen * 8)) == MaxBufBitmapLen * 8) {
        ErrorFlag = MAX_RDWR_COUNT;
        spin_rwunlock(sbinfo->_bh->spin);
        return NULL;
    }
    setbit_(sbinfo->_bh->map, nr);
    spin_rwunlock(sbinfo->_bh->spin);
    // if(!v->_bf) spin_rwinit(v->spin);
    while (spin_wrlock(v->spin));
    vi = v->_bf;
    if (vi == NULL || vi->key > key) {	//分配key是有序的。
        p = v->_bf;
        v->_bf = (_vnodeInfo) (sbinfo->_bf + sizeof(struct vnodeInfo) * nr);
        v->_bf->next = p;
        vi = v->_bf;
        p = NULL;
    } else {
        while (vi) {
            key++;
            if (!vi->next || vi->next->key > key) {
                p = vi->next;
                vi->next = (_vnodeInfo) (sbinfo->_bf + sizeof(struct vnodeInfo) * nr);
                vi->next->next = p;
                p = vi;
                vi = vi->next;
                break;
            }
            vi = vi->next;
        }
    }
    pthread_mutex_lock(&sbinfo->mutex);
    vi->fd = open(sbinfo->volName, O_RDWR);
    pthread_mutex_unlock(&sbinfo->mutex);
    pthread_mutex_init(&vi->mutex, NULL);
    if (vi->fd <= 2) {
        pthread_mutex_lock(&sbinfo->mutex);
        vi->fd = open(sbinfo->volName, O_RDWR);
        pthread_mutex_unlock(&sbinfo->mutex);
    }
    spin_rwunlock(v->spin);
    // }
    /* else {
       ErrorFlag=LOCK_ERR;
       return NULL;
       } */
    vi->key = key;
    vi->ID = ((char *)v - (char *)sbinfo->vnodeTable) / sizeof(vnode);
    if (mode == ReadRECORD) {
        vi->status = ReadRECORD;
        vi->nextTimeAddr = 0;
        vi->count = TimeNULL;
        //vi->fd=open(sbinfo->volName,O_RDWR);
        //   if(vi->fd<=2){
        //      vi->fd=open(sbinfo->volName,O_RDWR);
        //      }
    } else {
        vi->count = 0;
        vi->status = WriteRECORD;
        vi->is_starttime = NOTSET;
        // vi->fd=open(sbinfo->volName,O_RDWR);
        //  if(vi->fd<=2){
        //close(vi->fd);
        //   vi->fd=open(sbinfo->volName,O_RDWR);
        //   }
    }
    //////////////////////////////////////////////
    if (vi->fd < 0) {
        while (spin_trywrlock(sbinfo->_bh->spin));
        clrbit_(sbinfo->_bh->map, nr);
        spin_rwunlock(sbinfo->_bh->spin);
        while (spin_trywrlock(v->spin));
        if (p)
            p->next = p->next->next;
        else
            v->_bf = vi->next;
        spin_rwunlock(v->spin);
        pthread_mutex_destroy(&vi->mutex);
        ErrorFlag = ALLOC_FD_ERR;
        return NULL;
    }
    //  v->status++;
    return (char *)vi;
}
Example #14
0
void SQLite3DB::wrlock() {
	spin_wrlock(&rwlock);
}
Example #15
0
void MySQL_Logger::wrlock() {
  spin_wrlock(&rwlock);
};