/**
* Copyright 2011 Wu Zhu Hua
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/
#include "global.h"
#include "msg.h"
#include "item.h"
#include "utils.h"
#include "master.h"
#include "region.h"
#include "rpc.h"
#include "conf.h"
#include "malloc2.h"
#include "buf.h"
#include "log.h"
/***
* The Cli is YunTable Console that used mainly for experimenting and testing the YunTable,
* and not for performance intensive purpose, and add a silent mode for client automate testing.
**/
#define CONF_MASTER_CONN_KEY "master"
/** cli related constants **/
#define CMD_OPTION_KEY "-cmd" /** used in the silent mode **/
#define ADD_KEY "add"
#define GET_KEY "get"
#define SHOW_KEY "show"
#define PUT_KEY "put"
#define DEL_KEY "del"
#define HELP_KEY "help"
#define ROW_KEY "row"
#define QUIT_KEY "quit"
#define TABLE_KEY "table"
#define DEFAULT_YUNTABLE_CLI_PREFIX "yuncli:"
//the unit of below two items are sec
#define DEFAULT_CLI_DAEMON_SLEEP_INTERVAL 10 * 60
typedef struct _CliCache{
char* conf_path; /** default place is conf/cli.conf **/
char* master_conn;
List* tableInfoList;
}CliCache;
CliCache* cliCacheInst = NULL;
private char* get_table_name(char *string){
char *table_name = NULL;
Tokens *fenn_tokens = init_tokens(string, ':');
if(fenn_tokens->size == 2 && match(fenn_tokens->tokens[0], TABLE_KEY)){
table_name = m_cpy(fenn_tokens->tokens[1]);
}
free_tokens(fenn_tokens);
return table_name;
}
/** If can not get the table info from master, the system will return NULL **/
private TableInfo* get_table_info_from_master(char* master_conn, char* table_name){
TableInfo* tableInfo = NULL;
List* params = generate_charactor_params(1, table_name);
RPCRequest* rpcRequest = create_rpc_request(GET_TABLE_INFO_MASTER_CMD, params);
RPCResponse* rpcResponse = connect_conn(master_conn, rpcRequest);
int status_code = get_status_code(rpcResponse);
if(status_code == SUCCESS){
char* table_info_string = get_result(rpcResponse);
if(table_info_string != NULL){
List* lines = generate_list_by_token(table_info_string, LINE_SEPARATOR);
tableInfo = string_to_table_info(table_name, lines);
list_destory(lines, just_free);
}
}else{
printf("Sad News! The Master node has problem: %s\n", get_error_message(status_code));
}
destory_rpc_request(rpcRequest);
destory_rpc_response(rpcResponse);
return tableInfo;
}
private void update_table_info_list(CliCache* cliCache){
List* oldTableInfoList = cliCache->tableInfoList;
int i, size=list_size(oldTableInfoList);
List* newTableInfoList = list_create();
for(i=0; i<size; i++){
TableInfo* oldTableInfo = list_get(oldTableInfoList, i);
TableInfo* newTableInfo = get_table_info_from_master(cliCache->master_conn, oldTableInfo->table_name);
if(newTableInfo == NULL) continue;
list_append(newTableInfoList, newTableInfo);
}
cliCache->tableInfoList = newTableInfoList;
list_destory(oldTableInfoList, destory_table_info);
}
/** if the table info can't not find the tableInfoList, the method will contact master and get new, also will update the local cache **/
private TableInfo* search_and_update_table_info(CliCache* cliCache, char* table_name){
TableInfo *tableInfo = get_table_info(cliCache->tableInfoList, table_name);
if(tableInfo == NULL){
if(cliCache->master_conn == NULL){
printf("%s.\n", ERR_MSG_NO_MASTER);
}else{
tableInfo = get_table_info_from_master(cliCache->master_conn, table_name);
if(tableInfo != NULL) list_append(cliCache->tableInfoList, tableInfo);
}
}
return tableInfo;
}
private boolean create_new_table(char* master_conn, char* table_name){
boolean result = false;
List* params = generate_charactor_params(1, table_name);
RPCRequest* rpcRequest = create_rpc_request(CREATE_NEW_TABLE_MASTER_CMD, params);
RPCResponse* rpcResponse = connect_conn(master_conn, rpcRequest);
int status_code = get_status_code(rpcResponse);
if(status_code == SUCCESS){
result = stob(get_result(rpcResponse));
}else{
printf("Sad News! The Master node has problem: %s\n", get_error_message(status_code));
}
destory_rpc_request(rpcRequest);
destory_rpc_response(rpcResponse);
return result;
}
private boolean add_new_region(char* master_conn, char* region_conn){
boolean result = false;
List* params = generate_charactor_params(1, region_conn);
RPCRequest* rpcRequest = create_rpc_request(ADD_NEW_REGION_MASTER_CMD, params);
RPCResponse* rpcResponse = connect_conn(master_conn, rpcRequest);
int status_code = get_status_code(rpcResponse);
if(status_code == SUCCESS || get_result_length(rpcResponse) > 0){
result = stob(get_result(rpcResponse));
}else{
printf("Sad News! The Master node has problem: %s\n", get_error_message(status_code));
}
destory_rpc_request(rpcRequest);
destory_rpc_response(rpcResponse);
return result;
}
/** Will send a msg to the master node and to check the validity of reported region node **/
private boolean check_problem_region(char* problem_region_conn){
printf("The Region Node %s may have some problem.", problem_region_conn);
boolean result = false;
printf("Now let master check the validity of %s.\n", problem_region_conn);
List* params = generate_charactor_params(1, problem_region_conn);
RPCRequest* rpcRequest = create_rpc_request(CHECK_PROBLEM_REGION_MASTER_CMD, params);
RPCResponse* rpcResponse = connect_conn(problem_region_conn, rpcRequest);
int status_code = get_status_code(rpcResponse);
if(status_code == SUCCESS){
return stob(get_result(rpcResponse));
}else{
printf("Sad News! The Master node has problem: %s!\n", get_error_message(status_code));
}
destory_rpc_request(rpcRequest);
destory_rpc_response(rpcResponse);
return result;
}
/**
* sample cmd:
* add master:172.0.0.1:8301
* add region:172.0.0.1:8302
* add table:people //The input table name shouldn't contain space
*/
public char* add(Tokens* space_tokens){
char* msg = NULL;
//The add normally has two space token
if(space_tokens->size > 2){
msg = ERR_MSG_WRONG_ADD_CMD;
}else{
Tokens *fenn_tokens = init_tokens(space_tokens->tokens[1], ':');
if(match(fenn_tokens->tokens[0], MASTER_KEY)){
char* new_master_conn = m_cats(3, fenn_tokens->tokens[1], ":", fenn_tokens->tokens[2]);
if(check_node_validity(new_master_conn, MASTER_KEY)){
//No need to free the new_master_conn, since it will be inserted to new cliCacheInst
cliCacheInst->master_conn = new_master_conn;
flush_key_value(cliCacheInst->conf_path, CONF_MASTER_CONN_KEY, cliCacheInst->master_conn);
msg = SUCC_MSG_COMPLETED;
}else{
msg = ERR_MSG_WRONG_MASTER;
}
}else if(match(fenn_tokens->tokens[0], REGION_KEY)){
//step 0:check if there is master
if(cliCacheInst->master_conn == NULL){
msg = ERR_MSG_NO_MASTER;
}else{
char* new_region_conn = m_cats(3, fenn_tokens->tokens[1], ":", fenn_tokens->tokens[2]);
if(add_new_region(cliCacheInst->master_c
没有合适的资源?快使用搜索试试~ 我知道了~
云计算机YunTable 0.9 Source Code
共92个文件
svn-base:39个
h:16个
c:15个
4星 · 超过85%的资源 需积分: 9 12 下载量 74 浏览量
2011-09-11
11:23:13
上传
评论 1
收藏 159KB ZIP 举报
温馨提示
云计算机YunTable 0.9源代码,云计算机YunTable 0.9 Source Code
资源推荐
资源详情
资源评论
收起资源包目录
yuntable-read-only_2011_5_25.zip (92个子文件)
yuntable-read-only
conf
.svn
tmp
props
prop-base
text-base
props
all-wcprops 396B
entries 655B
prop-base
text-base
region.conf.template.svn-base 69B
master.conf.template.svn-base 9B
cli.conf.template.svn-base 0B
region.conf.template 69B
cli.conf.template 0B
master.conf.template 9B
build.sh 77B
region
.svn
tmp
props
prop-base
text-base
props
all-wcprops 512B
entries 927B
prop-base
text-base
tablet.c.svn-base 10KB
yfile.c.svn-base 19KB
memstore.c.svn-base 6KB
wal.c.svn-base 4KB
region.c.svn-base 17KB
region.c 17KB
yfile.c 19KB
wal.c 5KB
tablet.c 10KB
memstore.c 6KB
.svn
tmp
props
prop-base
text-base
props
all-wcprops 476B
entries 988B
prop-base
text-base
testcase.sh.svn-base 1KB
Makefile.svn-base 747B
Readme.svn-base 2KB
clean.sh.svn-base 477B
build.sh.svn-base 73B
util
utils.c 21KB
malloc2.c 2KB
.svn
tmp
props
prop-base
text-base
props
all-wcprops 735B
entries 1KB
prop-base
text-base
rpc.c.svn-base 15KB
list.c.svn-base 9KB
log.c.svn-base 2KB
conf.c.svn-base 20KB
item.c.svn-base 22KB
utils.c.svn-base 21KB
buf.c.svn-base 4KB
malloc2.c.svn-base 2KB
buf.c 4KB
list.c 9KB
item.c 22KB
rpc.c 15KB
conf.c 21KB
log.c 2KB
cli
.svn
tmp
props
prop-base
text-base
props
all-wcprops 148B
entries 333B
prop-base
text-base
cli.c.svn-base 24KB
cli.c 24KB
clean.sh 499B
master
.svn
tmp
props
prop-base
text-base
props
all-wcprops 160B
entries 339B
prop-base
text-base
master.c.svn-base 21KB
master.c 22KB
Makefile 747B
Readme 2KB
testcase.sh 1KB
include
list.h 2KB
item.h 3KB
log.h 1KB
conf.h 4KB
.svn
tmp
props
prop-base
text-base
props
all-wcprops 1KB
entries 2KB
prop-base
text-base
list.h.svn-base 2KB
master.h.svn-base 1KB
wal.h.svn-base 1KB
conf.h.svn-base 4KB
log.h.svn-base 1KB
tablet.h.svn-base 2KB
memstore.h.svn-base 1KB
rpc.h.svn-base 3KB
malloc2.h.svn-base 863B
utils.h.svn-base 3KB
yfile.h.svn-base 1KB
item.h.svn-base 3KB
buf.h.svn-base 1KB
global.h.svn-base 3KB
msg.h.svn-base 2KB
region.h.svn-base 2KB
region.h 2KB
memstore.h 1KB
malloc2.h 895B
rpc.h 3KB
msg.h 2KB
master.h 1KB
utils.h 3KB
tablet.h 2KB
buf.h 1KB
yfile.h 1KB
wal.h 1KB
global.h 3KB
共 92 条
- 1
资源评论
- fsmiy2013-07-12云计算从yuntable开始
keven170
- 粉丝: 0
- 资源: 18
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- IMG_20240425_120538.jpg
- My Complete Genome_6k Base-Pairs of Phenotype SNPs_Complete Raw Data.zip
- qt 的mqtt测试demo
- 移动应用开发教程-zip.zip
- mosquitto-2.018-install-windows-x64
- FTPServer FTP 服务器,绿色免安装,单文件
- 梦畅语音点名软件,上课点名
- 利用ADNI数据集和标签,在tensorflow框架上使用tensorlayer接口,通过架构u-net实现海马体的分割
- Kutools for Word v9.0 office word 插件
- 修复Windows 10 LTSC 2021资源占用率高
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功