std::string database_getval(std::string col, std::string val){ //fprintf(stderr, "in getval with %s %s", col.c_str(), val.c_str()); col=trim(col); val=trim(val); #ifdef VOLDEMORT_FOUND if(DATABASE==VOLDEMORT){ //log_msg("using vold"); vold_calls++; std::string retstd::string=voldemort_getval(col,val); return retstd::string; } #endif #ifdef REDIS_FOUND if(DATABASE==REDIS){ redis_calls++; std::string retstring=redis_getval(col,val); return retstring; } #endif #ifdef BDB_FOUND if(DATABASE==BDB) { std::string retstd::string = bdb_getval(col, val); return retstd::string; } #endif }
std::string redis_setval(std::string file_id, std::string col, std::string val) { // generate file_id if needed if(file_id.compare("null")==0) { std::string file_id=redis_getval("redis_last_id","val"); //cout << "got file id " << file_id << endl; if(file_id.compare("null")==0) { file_id="1"; } int redis_last_id=0; redis_last_id=atoi(file_id.c_str()); redis_last_id++;//find non-local solution (other table?) std::stringstream result; result<<redis_last_id; //cout << "removing " << file_id << endl; redis_remove_val("redis_last_id","val",file_id); reply = (redisReply*)redisCommand(c,"hget redis_last_id val"); if(reply->len!=0) { std::string rep_str = reply->str; //cout << "did it take?" << rep_str << endl; } freeReplyObject(reply); //cout << "setting " << result.str() << endl; redis_setval("redis_last_id","val",result.str()); file_id = result.str(); redis_setval(file_id,col,val); //cout << "returning " << file_id; return file_id; } // handle file_id key reply = (redisReply*)(redisReply*)redisCommand(c,"hget %s %s",file_id.c_str(),col.c_str()); std::string output = val; if(reply->len != 0) { std::string rep_str = reply->str; output = rep_str + ":" + output; } freeReplyObject(reply); //output = de_dup(output); reply = (redisReply*)redisCommand(c,"hset %s %s %s",file_id.c_str(),col.c_str(),output.c_str()); freeReplyObject(reply); //handle col key reply = (redisReply*)redisCommand(c,"hget %s %s",col.c_str(),val.c_str()); output = file_id; if(reply->len != 0) { std::string rep_str = reply->str; output = rep_str + ":" + output; } freeReplyObject(reply); //output = de_dup(output); reply = (redisReply*)redisCommand(c,"hset %s %s %s",col.c_str(),val.c_str(),output.c_str()); freeReplyObject(reply); return file_id; }
void redis_remove_val(std::string fileid, std::string col, std::string val){ //cout << "in remove val" << endl; //cout << "updating fileid" << endl; reply = (redisReply*)redisCommand(c,"hget %s %s",fileid.c_str(),col.c_str()); if(reply->len != 0 ) { std::string source = reply->str; freeReplyObject(reply); //cout << "got " << source << endl; size_t found = source.find(val); if(found != std::string::npos) { source.erase(found, val.length()); //cout << "after erase " << source << endl; } if(source.length()>0) { reply = (redisReply*)redisCommand(c,"hset %s %s %s",fileid.c_str(),col.c_str(),source.c_str()); freeReplyObject(reply); } else { reply = (redisReply*)redisCommand(c,"hdel %s %s",fileid.c_str(),col.c_str()); freeReplyObject(reply); } } else { freeReplyObject(reply); } //remove from col entry //cout << "updating col entry" << endl; std::string col_entry = redis_getval(col, val); //cout << "got " << col_entry << endl; size_t found = col_entry.find(fileid); if(found != std::string::npos) { col_entry.erase(found, fileid.length()); //cout << "after erase " << col_entry << endl; } reply = (redisReply*)redisCommand(c,"hset %s %s %s",col.c_str(),val.c_str(), col_entry.c_str()); freeReplyObject(reply); }
static int xmp_getxattr(const char *path, const char *name, char *value, size_t size, uint32_t param) { #else static int xmp_getxattr(const char *path, const char *name, char *value, size_t size) { #endif fprintf(stderr, "getxattr call\n %s, %s, %s\n", path, name, value); string xpath = "xattr:"; xpath += path; string db_val = redis_getval( xpath, name); fprintf(stderr, "getxattr call\npath:%s\nname:%s\nvalue:%s\nsize:%lu\n\n\n\n\n", xpath.c_str(), name, db_val.c_str(), size); if(db_val != "null") { db_val = hex2bin(db_val); if(value==NULL) { errno = 0; return db_val.length(); } memcpy(value, db_val.c_str(), size); size_t num = snprintf(value, size, "%s", db_val.c_str()); fprintf(stderr, "returned\nstring:%s\ncount:%lu\n\n", value, num); errno = 0; return size; } errno = ENOATTR; return -1; }