void sync_object::add_child(sync_object *object) { p_object->m_child_count += 1; uint currentKey = p_object->m_child_count; object->set_parent(this); p_object->m_child_map[currentKey] = object; update_time_stamp(); }
sync_object::sync_object(sync_object *parent) : p_object(new Privatesync_object) { update_time_stamp(); p_object->m_object_key = -1; p_object->m_child_count = -1; p_object->m_parent = 0; if (parent) parent->add_child(this); }
int HeartbeatAgent::do_heartbeat_handshake(HEARTBEAT_TYPE type , InReq &req) { MsgHeader header = req.m_msgHeader; std::string empty_data; std::string input_data(req.ioBuf , header.length); uint32_t storage_limit = 0; uint32_t cmd_ack = 0; cstore::pb_MSG_MU_CS_HEARTBEAT_HANDSHAKE in_mu_handshake; cstore::pb_MSG_SU_CS_HEARTBEAT_HANDSHAKE in_su_handshake; update_time_stamp(); m_type = type; if(MU_HEARTBEAT == type) { cmd_ack = MSG_MU_CS_HEARTBEAT_HANDSHAKE_ACK; if(!in_mu_handshake.ParseFromString(input_data)) { LOG_ERROR("HeartbeatAgent::parse protobuf of mu heartbeat handshake error !"); goto ERR; } std::cerr<<in_mu_handshake.DebugString()<<std::endl<<std::endl; storage_limit = in_mu_handshake.storage_load_limit(); } else if(SU_HEARTBEAT == type) { cmd_ack = MSG_SU_CS_HEARTBEAT_HANDSHAKE_ACK; if(!in_su_handshake.ParseFromString(input_data)) { LOG_ERROR("HeartbeatAgent::parse protobuf of su heartbeat handshake error !"); goto ERR; } std::cerr<<in_su_handshake.DebugString()<<std::endl<<std::endl; storage_limit = in_su_handshake.storage_load_limit(); } std::cout<<"get heartbeat handshake type is "<<(type == SU_HEARTBEAT ? "SU !" : "MU!")<<endl; if(MU_HEARTBEAT == type) HBManager::getInstance()->init_node_heartbeat_info(MU_RULER , this , storage_limit); else if(SU_HEARTBEAT == type) HBManager::getInstance()->init_node_heartbeat_info(SU_RULER , this , storage_limit ); CSTCPAgent::reply_request(cmd_ack , CS_OK , 0 , 0 , empty_data); return 0; ERR : CSTCPAgent::reply_request(cmd_ack , CS_ERROR , 0 , 0 , empty_data); return -1; }
void sync_object::set_property(const std::string &name, const std::string &value) { p_object->m_property_dict[name] = value; update_time_stamp(); }
int HeartbeatAgent::do_heartbeat(HEARTBEAT_TYPE type , InReq &req) { MsgHeader header = req.m_msgHeader; std::string input_data(req.ioBuf , header.length); std::string empty_data; uint32_t cmd_ack = 0; uint32_t local_ip = INVALID_IP; cstore::pb_MSG_MU_CS_HEARTBEAT in_mu_heartbeat; cstore::pb_MSG_SU_CS_HEARTBEAT in_su_heartbeat; cstore::Bucket_Item bucket_item; std::list<cstore::Bucket_Item> bucket_item_list; int bucket_num = 0; update_time_stamp(); m_type = type; if(RS_HEARTBEAT == type) { CSTCPAgent::reply_request(MSG_RS_CS_HEARTBEAT_ACK , CS_OK , 0 , 0 , empty_data); return 0; } if(MU_HEARTBEAT == type) { cmd_ack = MSG_MU_CS_HEARTBEAT_ACK; if(!in_mu_heartbeat.ParseFromString(input_data)) { LOG_ERROR("HeartbeatAgent::parse protobuf of mu heartbeat error !"); goto ERR; } // std::cerr<<in_mu_heartbeat.DebugString()<<std::endl<<std::endl;; bucket_num = in_mu_heartbeat.bucket_item_size(); for(int i = 0 ; i < bucket_num ; ++ i) { bucket_item = in_mu_heartbeat.bucket_item(i); bucket_item_list.push_back(bucket_item); } } else if(SU_HEARTBEAT == type) { cmd_ack = MSG_SU_CS_HEARTBEAT_ACK; if(!in_su_heartbeat.ParseFromString(input_data)) { LOG_ERROR("HeartbeatAgent::parse protobuf of mu heartbeat error !"); goto ERR; } // std::cerr<<in_su_heartbeat.DebugString()<<std::endl<<std::endl;; bucket_num = in_su_heartbeat.bucket_item_size(); for(int i = 0 ; i < bucket_num ; ++ i) { bucket_item = in_su_heartbeat.bucket_item(i); bucket_item_list.push_back(bucket_item); } } if(string_to_int_ip(m_Addr.getIP() , local_ip) < 0) { LOG_ERROR("HeartbeatAgent::change int ip to string error !"); goto ERR; } if(MU_HEARTBEAT == type) update_last_bucket_load(MU_RULER , local_ip , bucket_item_list); else if(SU_HEARTBEAT == type) update_last_bucket_load(SU_RULER , local_ip , bucket_item_list); CSTCPAgent::reply_request(cmd_ack , CS_OK , 0 , 0 , empty_data); return 0; ERR : CSTCPAgent::reply_request(cmd_ack , CS_ERROR , 0 , 0 , empty_data); return -1; }
// Fault any disk block that is read in to memory by // loading it from disk. static void bc_pgfault(struct UTrapframe *utf) { void *addr = (void *) utf->utf_fault_va; uint32_t blockno = ((uint32_t)addr - DISKMAP) / BLKSIZE; int r; // Check that the fault was within the block cache region if (addr < (void*)DISKMAP || addr >= (void*)(DISKMAP + DISKSIZE)) panic("page fault in FS: eip %08x, va %08x, err %04x", utf->utf_eip, addr, utf->utf_err); // Sanity check the block number. if (super && blockno >= super->s_nblocks) panic("reading non-existent block %08x\n", blockno); // Allocate a page in the disk map region, read the contents // of the block from the disk into that page. // Hint: first round addr to page boundary. fs/ide.c has code to read // the disk. // // LAB 5: you code here: addr = ROUNDDOWN(addr, PGSIZE); update_blk_count(); update_time_stamp(); print_block_list(); if (curr_disk_size == MAXFILECACHE) //no memory for disk mapping, have to evict { uint32_t i, min_blk = 0, min_count = 0xffffffff; for (i=0; i<MAXBLK; ++i) if (plist[i].valid && plist[i].tstamp<min_count && i!=1) //use LRU policy to evict a block { assert(i!=blockno); min_blk = i; min_count = plist[i].tstamp; } cprintf("evict block at %x, used %d times, last used at time %x, load block at %x\n", diskaddr(min_blk), plist[min_blk].count, plist[min_blk].tstamp, addr); flush_block(diskaddr(min_blk)); curr_disk_size -=PGSIZE; plist[min_blk].valid =0; sys_page_unmap(0, diskaddr(min_blk)); } else { cprintf("load block at %x, no eviction\n", addr); } cprintf("total miss: %d\n", timestamp); curr_disk_size += PGSIZE; if ((r = sys_page_alloc(0, addr, PTE_SYSCALL)) <0) panic("in bc_pgfault, sys_page_alloc: %e", r); if ((r = ide_read(blockno * BLKSECTS, addr, BLKSECTS)) < 0) panic("in bc_pgfault, ideread: %e", r); // Clear the dirty bit for the disk block page since we just read the // block from disk if ((r = sys_page_map(0, addr, 0, addr, uvpt[PGNUM(addr)] & PTE_SYSCALL)) < 0) panic("in bc_pgfault, sys_page_map: %e", r); plist[blockno].valid = 1; plist[blockno].count = 0; plist[blockno].tstamp = ++timestamp; // Check that the block we read was allocated. (exercise for // the reader: why do we do this *after* reading the block // in?) if (bitmap && block_is_free(blockno)) panic("reading free block %08x\n", blockno); sys_ptea_flush(); }