未验证 提交 8587eb0f 编写于 作者: 羽飞's avatar 羽飞 提交者: GitHub

简化rc (#184)

### What problem were solved in this pull request?

Issue Number: close #149 

Problem:
RC return code ,定义的东西太多,不太简洁,并且有很多错误码当前没有使用

### What is changed and how it works?
仅使用enum RC 定义错误码,删掉其它枚举定义。
删除当前没有使用的错误码。

### Other information
上级 3db46984
{
"files.associations": {
"typeinfo": "cpp"
}
}
\ No newline at end of file
......@@ -142,7 +142,7 @@ public:
case RC::SUCCESS: {
stat.delete_success_count++;
} break;
case RC::RECORD_RECORD_NOT_EXIST: {
case RC::RECORD_NOT_EXIST: {
stat.not_exist_count++;
} break;
default: {
......
......@@ -187,7 +187,7 @@ public:
case RC::SUCCESS: {
stat.delete_success_count++;
} break;
case RC::RECORD_RECORD_NOT_EXIST: {
case RC::RECORD_NOT_EXIST: {
stat.not_exist_count++;
} break;
default: {
......
......@@ -82,13 +82,13 @@ RC Client::init(string host, int port)
if ((host = gethostbyname(host.c_str())) == NULL) {
LOG_WARN("failed to gethostbyname. rc=%s", strerror(errno));
return RC::IOERR;
return RC::IOERR_READ;
}
int sockfd = -1;
if ((sockfd = socket(AF_INET, SOCK_STREAM, 0)) == -1) {
LOG_WARN("failed to create socket. rc=%s", strerror(errno));
return RC::IOERROR;
return RC::IOERR_OPEN;
}
memset(&serv_addr, 0, sizeof(serv_addr));
......
......@@ -89,14 +89,14 @@ RC PlainCommunicator::read_event(SessionEvent *&event)
if (data_len > max_packet_size) {
LOG_WARN("The length of sql exceeds the limitation %d", max_packet_size);
return RC::IOERR;
return RC::IOERR_TOO_LONG;
}
if (read_len == 0) {
LOG_INFO("The peer has been closed %s\n", addr());
return RC::IOERR;
return RC::IOERR_CLOSE;
} else if (read_len < 0) {
LOG_ERROR("Failed to read socket of %s, %s\n", addr(), strerror(errno));
return RC::IOERR;
return RC::IOERR_READ;
}
LOG_INFO("receive command(size=%d): %s", data_len, buf.data());
......@@ -123,7 +123,7 @@ RC PlainCommunicator::write_state(SessionEvent *event, bool &need_disconnect)
LOG_WARN("failed to send data to client. err=%s", strerror(errno));
need_disconnect = true;
delete[] buf;
return RC::IOERR;
return RC::IOERR_WRITE;
}
need_disconnect = false;
......@@ -147,12 +147,12 @@ RC PlainCommunicator::write_result(SessionEvent *event, bool &need_disconnect)
if (ret < 0) {
LOG_ERROR("Failed to send data back to client. ret=%d, error=%s", ret, strerror(errno));
return RC::IOERR;
return RC::IOERR_WRITE;
}
ret = common::writen(fd_, &message_terminate, sizeof(message_terminate));
if (ret < 0) {
LOG_ERROR("Failed to send data back to client. ret=%d, error=%s", ret, strerror(errno));
return RC::IOERR;
return RC::IOERR_WRITE;
}
need_disconnect = false;
......@@ -181,7 +181,7 @@ RC PlainCommunicator::write_result(SessionEvent *event, bool &need_disconnect)
int ret = common::writen(fd_, delim, strlen(delim));
if (ret != 0) {
LOG_WARN("failed to send data to client. err=%s", strerror(errno));
return RC::IOERR;
return RC::IOERR_WRITE;
}
}
......@@ -190,7 +190,7 @@ RC PlainCommunicator::write_result(SessionEvent *event, bool &need_disconnect)
if (ret != 0) {
LOG_WARN("failed to send data to client. err=%s", strerror(errno));
sql_result->close();
return RC::IOERR;
return RC::IOERR_WRITE;
}
}
}
......@@ -201,7 +201,7 @@ RC PlainCommunicator::write_result(SessionEvent *event, bool &need_disconnect)
if (ret != 0) {
LOG_WARN("failed to send data to client. err=%s", strerror(errno));
sql_result->close();
return RC::IOERR;
return RC::IOERR_WRITE;
}
}
......@@ -218,7 +218,7 @@ RC PlainCommunicator::write_result(SessionEvent *event, bool &need_disconnect)
if (ret != 0) {
LOG_WARN("failed to send data to client. err=%s", strerror(errno));
sql_result->close();
return RC::IOERR;
return RC::IOERR_WRITE;
}
}
......@@ -236,7 +236,7 @@ RC PlainCommunicator::write_result(SessionEvent *event, bool &need_disconnect)
if (ret != RC::SUCCESS) {
LOG_WARN("failed to send data to client. err=%s", strerror(errno));
sql_result->close();
return RC::IOERR;
return RC::IOERR_WRITE;
}
}
......@@ -245,7 +245,7 @@ RC PlainCommunicator::write_result(SessionEvent *event, bool &need_disconnect)
if (ret != 0) {
LOG_WARN("failed to send data to client. err=%s", strerror(errno));
sql_result->close();
return RC::IOERR;
return RC::IOERR_WRITE;
}
}
......@@ -269,7 +269,7 @@ RC PlainCommunicator::write_result(SessionEvent *event, bool &need_disconnect)
if (ret < 0) {
LOG_ERROR("Failed to send data back to client. ret=%d, error=%s", ret, strerror(errno));
sql_result->close();
return RC::IOERR;
return RC::IOERR_WRITE;
}
need_disconnect = false;
......
......@@ -467,7 +467,7 @@ RC MysqlCommunicator::read_event(SessionEvent *&event)
if (ret != 0) {
LOG_WARN("failed to read packet header. length=%d, addr=%s. error=%s",
sizeof(packet_header), addr_.c_str(), strerror(errno));
return RC::IOERR;
return RC::IOERR_READ;
}
LOG_TRACE("read packet header. length=%d, sequence_id=%d", sizeof(packet_header), packet_header.sequence_id);
......@@ -478,7 +478,7 @@ RC MysqlCommunicator::read_event(SessionEvent *&event)
if (ret != 0) {
LOG_WARN("failed to read packet payload. length=%d, addr=%s, error=%s",
packet_header.payload_length, addr_.c_str(), strerror(errno));
return RC::IOERR;
return RC::IOERR_READ;
}
LOG_TRACE("read packet payload length=%d", packet_header.payload_length);
......@@ -637,7 +637,7 @@ RC MysqlCommunicator::send_packet(const BasePacket &packet)
int ret = common::writen(fd_, net_packet.data(), net_packet.size());
if (ret != 0) {
LOG_WARN("failed to send packet to client. addr=%s, error=%s", addr(), strerror(errno));
return RC::IOERR;
return RC::IOERR_WRITE;
}
LOG_TRACE("send ok packet success. packet length=%d", net_packet.size());
......@@ -689,7 +689,7 @@ RC MysqlCommunicator::send_column_definition(SqlResult *sql_result, bool &need_d
if (ret != 0) {
LOG_WARN("failed to send column count to client. addr=%s, error=%s", addr(), strerror(errno));
need_disconnect = true;
return RC::IOERR;
return RC::IOERR_WRITE;
}
for (int i = 0; i < cell_num; i++) {
......@@ -744,7 +744,7 @@ RC MysqlCommunicator::send_column_definition(SqlResult *sql_result, bool &need_d
if (ret != 0) {
LOG_WARN("failed to write column definition to client. addr=%s, error=%s", addr(), strerror(errno));
need_disconnect = true;
return RC::IOERR;
return RC::IOERR_WRITE;
}
}
......@@ -818,7 +818,7 @@ RC MysqlCommunicator::send_result_rows(SqlResult *sql_result, bool no_column_def
if (ret != 0) {
LOG_WARN("failed to send row packet to client. addr=%s, error=%s", addr(), strerror(errno));
need_disconnect = true;
return RC::IOERR;
return RC::IOERR_WRITE;
}
}
......
......@@ -14,188 +14,22 @@ See the Mulan PSL v2 for more details. */
#include "rc.h"
#define RC_CASE_STRING(rc) \
case rc: \
return #rc
const char *strrc(RC rc)
{
switch (rc) {
RC_CASE_STRING(SUCCESS);
RC_CASE_STRING(GENERIC_ERROR);
RC_CASE_STRING(INVALID_ARGUMENT);
RC_CASE_STRING(UNIMPLENMENT);
RC_CASE_STRING(SQL_SYNTAX);
RC_CASE_STRING(BUFFERPOOL);
RC_CASE_STRING(RECORD);
RC_CASE_STRING(INTERNAL);
RC_CASE_STRING(PERM);
RC_CASE_STRING(ABORT);
RC_CASE_STRING(BUSY);
RC_CASE_STRING(LOCKED);
RC_CASE_STRING(NOMEM);
RC_CASE_STRING(READONLY);
RC_CASE_STRING(INTERRUPT);
RC_CASE_STRING(IOERR);
RC_CASE_STRING(CORRUPT);
RC_CASE_STRING(NOTFOUND);
RC_CASE_STRING(FULL);
RC_CASE_STRING(CANTOPEN);
RC_CASE_STRING(PROTOCOL);
RC_CASE_STRING(EMPTY);
RC_CASE_STRING(SCHEMA);
RC_CASE_STRING(TOOBIG);
RC_CASE_STRING(CONSTRAINT);
RC_CASE_STRING(MISMATCH);
RC_CASE_STRING(MISUSE);
RC_CASE_STRING(NOLFS);
RC_CASE_STRING(AUTH);
RC_CASE_STRING(FORMAT);
RC_CASE_STRING(RANGE);
RC_CASE_STRING(NOTADB);
RC_CASE_STRING(LOGBUF);
RC_CASE_STRING(NOTICE);
RC_CASE_STRING(BUFFERPOOL_EXIST);
RC_CASE_STRING(BUFFERPOOL_FILEERR);
RC_CASE_STRING(BUFFERPOOL_INVALIDNAME);
RC_CASE_STRING(BUFFERPOOL_WINDOWS);
RC_CASE_STRING(BUFFERPOOL_CLOSED);
RC_CASE_STRING(BUFFERPOOL_OPEN);
RC_CASE_STRING(BUFFERPOOL_NOBUF);
RC_CASE_STRING(BUFFERPOOL_EOF);
RC_CASE_STRING(BUFFERPOOL_INVALID_PAGE_NUM);
RC_CASE_STRING(BUFFERPOOL_NOTINBUF);
RC_CASE_STRING(BUFFERPOOL_PAGE_PINNED);
RC_CASE_STRING(BUFFERPOOL_OPEN_TOO_MANY_FILES);
RC_CASE_STRING(BUFFERPOOL_ILLEGAL_FILE_ID);
RC_CASE_STRING(RECORD_CLOSED);
RC_CASE_STRING(RECORD_OPENNED);
RC_CASE_STRING(RECORD_INVALIDRECSIZE);
RC_CASE_STRING(RECORD_INVALIDRID);
RC_CASE_STRING(RECORD_NOMORERECINMEM);
RC_CASE_STRING(RECORD_OPEN);
RC_CASE_STRING(RECORD_NO_MORE_IDX_IN_MEM);
RC_CASE_STRING(RECORD_INVALID_KEY);
RC_CASE_STRING(RECORD_DUPLICATE_KEY);
RC_CASE_STRING(RECORD_NOMEM);
RC_CASE_STRING(RECORD_SCANCLOSED);
RC_CASE_STRING(RECORD_SCANOPENNED);
RC_CASE_STRING(RECORD_EOF);
RC_CASE_STRING(RECORD_RECORD_NOT_EXIST);
RC_CASE_STRING(RECORD_INVISIBLE);
RC_CASE_STRING(SCHEMA_DB_EXIST);
RC_CASE_STRING(SCHEMA_DB_NOT_EXIST);
RC_CASE_STRING(SCHEMA_DB_NOT_OPENED);
RC_CASE_STRING(SCHEMA_TABLE_NOT_EXIST);
RC_CASE_STRING(SCHEMA_TABLE_EXIST);
RC_CASE_STRING(SCHEMA_TABLE_NAME_ILLEGAL);
RC_CASE_STRING(SCHEMA_FIELD_NOT_EXIST);
RC_CASE_STRING(SCHEMA_FIELD_EXIST);
RC_CASE_STRING(SCHEMA_FIELD_NAME_ILLEGAL);
RC_CASE_STRING(SCHEMA_FIELD_MISSING);
RC_CASE_STRING(SCHEMA_FIELD_REDUNDAN);
RC_CASE_STRING(SCHEMA_FIELD_TYPE_MISMATCH);
RC_CASE_STRING(SCHEMA_INDEX_NAME_REPEAT);
RC_CASE_STRING(SCHEMA_INDEX_EXIST);
RC_CASE_STRING(SCHEMA_INDEX_NOT_EXIST);
RC_CASE_STRING(SCHEMA_INDEX_NAME_ILLEGAL);
RC_CASE_STRING(IOERR_READ);
RC_CASE_STRING(IOERR_SHORT_READ);
RC_CASE_STRING(IOERR_WRITE);
RC_CASE_STRING(IOERR_FSYNC);
RC_CASE_STRING(IOERR_DIR_FSYNC);
RC_CASE_STRING(IOERR_TRUNCATE);
RC_CASE_STRING(IOERR_FSTAT);
RC_CASE_STRING(IOERR_DELETE);
RC_CASE_STRING(IOERR_BLOCKED);
RC_CASE_STRING(IOERR_ACCESS);
RC_CASE_STRING(IOERR_CHECKRESERVEDLOCK);
RC_CASE_STRING(IOERR_CLOSE);
RC_CASE_STRING(IOERR_DIR_CLOSE);
RC_CASE_STRING(IOERR_SHMOPEN);
RC_CASE_STRING(IOERR_SHMSIZE);
RC_CASE_STRING(IOERR_SHMLOCK);
RC_CASE_STRING(IOERR_SHMMAP);
RC_CASE_STRING(IOERR_SEEK);
RC_CASE_STRING(IOERR_DELETE_NOENT);
RC_CASE_STRING(IOERR_MMAP);
RC_CASE_STRING(IOERR_GETTEMPPATH);
RC_CASE_STRING(IOERR_CONVPATH);
RC_CASE_STRING(IOERR_VNODE);
RC_CASE_STRING(IOERR_BEGIN_ATOMIC);
RC_CASE_STRING(IOERR_COMMIT_ATOMIC);
RC_CASE_STRING(IOERR_ROLLBACK_ATOMIC);
RC_CASE_STRING(IOERR_DATA);
RC_CASE_STRING(IOERR_CORRUPTFS);
RC_CASE_STRING(IOERR_OPEN_TOO_MANY_FILES);
RC_CASE_STRING(LOCKED_LOCK);
RC_CASE_STRING(LOCKED_UNLOCK);
RC_CASE_STRING(LOCKED_SHAREDCACHE);
RC_CASE_STRING(LOCKED_VIRT);
RC_CASE_STRING(LOCKED_NEED_WAIT);
RC_CASE_STRING(LOCKED_RESOURCE_DELETED);
RC_CASE_STRING(LOCKED_CONCURRENCY_CONFLICT);
RC_CASE_STRING(BUSY_RECOVERY);
RC_CASE_STRING(BUSY_SNAPSHOT);
RC_CASE_STRING(BUSY_TIMEOUT);
RC_CASE_STRING(CANTOPEN_NOTEMPDIR);
RC_CASE_STRING(CANTOPEN_ISDIR);
RC_CASE_STRING(CANTOPEN_FULLPATH);
RC_CASE_STRING(CANTOPEN_CONVPATH);
RC_CASE_STRING(CANTOPEN_DIRTYWAL);
RC_CASE_STRING(CANTOPEN_SYMLINK);
#define DEFINE_RC(name) \
case RC::name: { \
return #name; \
} break;
RC_CASE_STRING(READONLY_RECOVERY);
RC_CASE_STRING(READONLY_CANTLOCK);
RC_CASE_STRING(READONLY_ROLLBACK);
RC_CASE_STRING(READONLY_DBMOVED);
RC_CASE_STRING(READONLY_CANTINIT);
RC_CASE_STRING(READONLY_DIRECTORY);
RC_CASE_STRING(ABORT_ROLLBACK);
RC_CASE_STRING(CONSTRAINT_CHECK);
RC_CASE_STRING(CONSTRAINT_COMMITHOOK);
RC_CASE_STRING(CONSTRAINT_FOREIGNKEY);
RC_CASE_STRING(CONSTRAINT_FUNCTION);
RC_CASE_STRING(CONSTRAINT_NOTNULL);
RC_CASE_STRING(CONSTRAINT_PRIMARYKEY);
RC_CASE_STRING(CONSTRAINT_TRIGGER);
RC_CASE_STRING(CONSTRAINT_UNIQUE);
RC_CASE_STRING(CONSTRAINT_VIRT);
RC_CASE_STRING(CONSTRAINT_ROWID);
RC_CASE_STRING(CONSTRAINT_PINNED);
RC_CASE_STRING(NOTICE_RECOVER_WAL);
RC_CASE_STRING(NOTICE_RECOVER_ROLLBACK);
RC_CASE_STRING(NOTICE_AUTOINDEX);
RC_CASE_STRING(FILE_EXIST);
RC_CASE_STRING(FILE_NOT_EXIST);
RC_CASE_STRING(FILE_NAME);
RC_CASE_STRING(FILE_BOUND);
RC_CASE_STRING(FILE_CREATE);
RC_CASE_STRING(FILE_OPEN);
RC_CASE_STRING(FILE_NOT_OPENED);
RC_CASE_STRING(FILE_CLOSE);
RC_CASE_STRING(FILE_REMOVE);
RC_CASE_STRING(FILE_SEEK);
RC_CASE_STRING(FILE_READ);
RC_CASE_STRING(FILE_WRITE);
RC_CASE_STRING(AUTH_USER);
RC_CASE_STRING(LOGBUF_FULL);
RC_CASE_STRING(LOGBUF_EMPTY);
switch (rc) {
DEFINE_RCS;
default: {
return "UNKNOWN";
return "unkown";
}
}
#undef DEFINE_RC
}
bool OB_SUCC(RC rc) { return rc == RC::SUCCESS; }
bool OB_FAIL(RC rc) { return rc != RC::SUCCESS; }
......@@ -14,373 +14,71 @@ See the Mulan PSL v2 for more details. */
#pragma once
enum RCBufferPool {
BP_EXIST = 1,
BP_FILEERR,
BP_INVALIDNAME,
BP_WINDOWS,
BP_CLOSED,
BP_OPEN,
BP_NOBUF,
BP_EOF,
BP_INVALIDPAGENUM,
BP_NOTINBUF,
BP_PAGE_PINNED,
BP_OPEN_TOO_MANY_FILES,
BP_ILLEGAL_FILE_ID,
};
enum RCRecord {
RD_CLOSED = 1,
RD_OPENNED,
RD_INVALIDRECSIZE,
RD_INVALIDRID,
RD_NO_MORE_RECINMEM,
RD_OPEN,
RD_NO_MORE_IDXINMEM,
RD_INVALID_KEY,
RD_DUPLICATE_KEY,
RD_NOMEM,
RD_SCANCLOSED,
RD_SCANOPENNED,
RD_EOF,
RD_NOT_EXIST,
RD_INVISIBLE,
};
enum RCSchema {
DB_EXIST = 1,
DB_NOT_EXIST,
DB_NOT_OPENED,
TABLE_NOT_EXIST,
TABLE_EXIST,
TABLE_NAME_ILLEGAL,
FIELD_NOT_EXIST,
FIELD_EXIST,
FIELD_NAME_ILLEGAL,
FIELD_MISSING,
FIELD_REDUNDAN,
FIELD_TYPE_MISMATCH,
INDEX_NAME_REPEAT,
INDEX_EXIST,
INDEX_NOT_EXIST,
INDEX_NAME_ILLEGAL,
};
enum RCSQL { SQL_SELECT = 1 };
enum RCIOError {
READ = 1,
SHORT_READ,
WRITE,
FSYNC,
DIR_FSYNC,
TRUNCATE,
FSTAT,
IO_DELETE,
BLOCKED,
ACCESS,
CHECKRESERVEDLOCK,
CLOSE,
DIR_CLOSE,
SHMOPEN,
SHMSIZE,
SHMLOCK,
SHMMAP,
SEEK,
DELETE_NOENT,
MMAP,
GETTEMPPATH,
IO_CONVPATH,
VNODE,
BEGIN_ATOMIC,
COMMIT_ATOMIC,
ROLLBACK_ATOMIC,
DATA,
CORRUPTFS,
OPEN_TOO_MANY_FILES,
};
enum RCLock {
LOCK = 1,
UNLOCK,
SHAREDCACHE,
LVIRT,
NEED_WAIT,
RESOURCE_DELETED,
CONCURRENCY_CONFLICT,
};
enum RCBusy {
BRECOVERY = 1,
SNAPSHOT,
TIMEOUT,
};
enum RCCantOpen {
NOTEMPDIR = 1,
ISDIR,
FULLPATH,
CO_CONVPATH,
DIRTYWAL,
SYMLINK,
};
enum RCCorrupt { CORRUPT_VIRT = 1, CORRUPT_SEQUENCE, CORRUPT_INDEX };
enum RCReadonly {
RO_RECOVERY = 1,
CANTLOCK,
RO_ROLLBACK,
DBMOVED,
CANTINIT,
DIRECTORY,
};
enum RCAbort {
AROLLBACK = 1,
};
enum RCContraint {
CHECK = 1,
COMMITHOOK,
FOREIGNKEY,
FUNCTION,
NOTNULL,
PRIMARYKEY,
TRIGGER,
UNIQUE,
CVIRT,
ROWID,
PINNED,
};
enum RCNotice {
RECOVER_WAL = 1,
RECOVER_ROLLBACK,
AUTOINDEX,
};
enum RCAuth {
USER = 1,
};
enum RCFILE {
F_EXIST = 1,
F_NOT_EXIST,
F_NAME,
F_BOUND,
F_CREATE,
F_OPEN,
F_NOT_OPENED,
F_CLOSE,
F_REMOVE,
F_SEEK,
F_READ,
F_WRITE,
};
enum RCLOGBUF {
LB_FULL = 1,
LB_EMPTY,
};
enum RC {
SUCCESS = 0, /* Successful result */
/* beginning-of-error-codes */
GENERIC_ERROR, /* Generic error */
INVALID_ARGUMENT, /* Invalid argument */
UNIMPLENMENT, /* not implenment yet */
SQL_SYNTAX, /* SQL Syntax error */
BUFFERPOOL, /* Buffer pool error*/
RECORD, /* Record error */
INTERNAL, /* Internal logic error in SQL */
PERM, /* Access permission denied */
ABORT, /* Callback routine requested an abort */
BUSY, /* The database file is locked */
LOCKED, /* A table in the database is locked */
NOMEM, /* A malloc() failed */
READONLY, /* Attempt to write a readonly database */
INTERRUPT, /* Operation terminated by interrupt()*/
IOERR, /* Some kind of disk I/O error occurred */
CORRUPT, /* The database disk image is malformed */
NOTFOUND, /* Unknown opcode in file_control() */
FULL, /* Insertion failed because database is full */
CANTOPEN, /* Unable to open the database file */
PROTOCOL, /* Database lock protocol error */
EMPTY, /* Internal use only */
SCHEMA, /* The database schema error */
TOOBIG, /* String or BLOB exceeds size limit */
CONSTRAINT, /* Abort due to constraint violation */
MISMATCH, /* Data type mismatch */
MISUSE, /* Library used incorrectly */
NOLFS, /* Uses OS features not supported on host */
AUTH, /* Authorization denied */
FORMAT, /* Not used */
RANGE, /* 2nd parameter to bind out of range */
NOTADB, /* File opened that is not a database file */
FILE_ERROR, /* File error */
LOGBUF, /* clog buffer error */
NOTICE = 100, /* Notifications from log() */
/* buffer pool part */
BUFFERPOOL_EXIST = (BUFFERPOOL | (RCBufferPool::BP_EXIST << 8)),
BUFFERPOOL_FILEERR = (BUFFERPOOL | (RCBufferPool::BP_FILEERR << 8)),
BUFFERPOOL_INVALIDNAME = (BUFFERPOOL | (RCBufferPool::BP_INVALIDNAME << 8)),
BUFFERPOOL_WINDOWS = (BUFFERPOOL | (RCBufferPool::BP_WINDOWS << 8)),
BUFFERPOOL_CLOSED = (BUFFERPOOL | (RCBufferPool::BP_CLOSED << 8)),
BUFFERPOOL_OPEN = (BUFFERPOOL | (RCBufferPool::BP_OPEN << 8)),
BUFFERPOOL_NOBUF = (BUFFERPOOL | (RCBufferPool::BP_NOBUF << 8)),
BUFFERPOOL_EOF = (BUFFERPOOL | (RCBufferPool::BP_EOF << 8)),
BUFFERPOOL_INVALID_PAGE_NUM = (BUFFERPOOL | (RCBufferPool::BP_INVALIDPAGENUM << 8)),
BUFFERPOOL_NOTINBUF = (BUFFERPOOL | (RCBufferPool::BP_NOTINBUF << 8)),
BUFFERPOOL_PAGE_PINNED = (BUFFERPOOL | (RCBufferPool::BP_PAGE_PINNED << 8)),
BUFFERPOOL_OPEN_TOO_MANY_FILES = (BUFFERPOOL | (RCBufferPool::BP_OPEN_TOO_MANY_FILES << 8)),
BUFFERPOOL_ILLEGAL_FILE_ID = (BUFFERPOOL | (RCBufferPool::BP_ILLEGAL_FILE_ID << 8)),
/* record part */
RECORD_CLOSED = (RECORD | (RCRecord::RD_CLOSED << 8)),
RECORD_OPENNED = (RECORD | (RCRecord::RD_OPENNED << 8)),
RECORD_INVALIDRECSIZE = (RECORD | (RCRecord::RD_INVALIDRECSIZE << 8)),
RECORD_INVALIDRID = (RECORD | (RCRecord::RD_INVALIDRID << 8)),
RECORD_NOMORERECINMEM = (RECORD | (RCRecord::RD_NO_MORE_RECINMEM << 8)),
RECORD_OPEN = (RECORD | (RCRecord::RD_OPEN << 8)),
RECORD_NO_MORE_IDX_IN_MEM = (RECORD | (RCRecord::RD_NO_MORE_IDXINMEM << 8)),
RECORD_INVALID_KEY = (RECORD | (RCRecord::RD_INVALID_KEY << 8)),
RECORD_DUPLICATE_KEY = (RECORD | (RCRecord::RD_DUPLICATE_KEY << 8)),
RECORD_NOMEM = (RECORD | (RCRecord::RD_NOMEM << 8)),
RECORD_SCANCLOSED = (RECORD | (RCRecord::RD_SCANCLOSED << 8)),
RECORD_SCANOPENNED = (RECORD | (RCRecord::RD_SCANOPENNED << 8)),
RECORD_EOF = (RECORD | (RCRecord::RD_EOF << 8)),
RECORD_RECORD_NOT_EXIST = (RECORD | (RCRecord::RD_NOT_EXIST << 8)),
RECORD_INVISIBLE = (RECORD | (RCRecord::RD_INVISIBLE << 8)),
/* schema part */
SCHEMA_DB_EXIST = (SCHEMA | (RCSchema::DB_EXIST << 8)),
SCHEMA_DB_NOT_EXIST = (SCHEMA | (RCSchema::DB_NOT_EXIST << 8)),
SCHEMA_DB_NOT_OPENED = (SCHEMA | (RCSchema::DB_NOT_OPENED << 8)),
SCHEMA_TABLE_NOT_EXIST = (SCHEMA | (RCSchema::TABLE_NOT_EXIST << 8)),
SCHEMA_TABLE_EXIST = (SCHEMA | (RCSchema::TABLE_EXIST << 8)),
SCHEMA_TABLE_NAME_ILLEGAL = (SCHEMA | (RCSchema::TABLE_NAME_ILLEGAL << 8)),
SCHEMA_FIELD_NOT_EXIST = (SCHEMA | (RCSchema::FIELD_NOT_EXIST << 8)),
SCHEMA_FIELD_EXIST = (SCHEMA | (RCSchema::FIELD_EXIST << 8)),
SCHEMA_FIELD_NAME_ILLEGAL = (SCHEMA | (RCSchema::FIELD_NAME_ILLEGAL << 8)),
SCHEMA_FIELD_MISSING = (SCHEMA | (RCSchema::FIELD_MISSING << 8)),
SCHEMA_FIELD_REDUNDAN = (SCHEMA | (RCSchema::FIELD_REDUNDAN << 8)),
SCHEMA_FIELD_TYPE_MISMATCH = (SCHEMA | (RCSchema::FIELD_TYPE_MISMATCH << 8)),
SCHEMA_INDEX_NAME_REPEAT = (SCHEMA | (RCSchema::INDEX_NAME_REPEAT << 8)),
SCHEMA_INDEX_EXIST = (SCHEMA | (RCSchema::INDEX_EXIST << 8)),
SCHEMA_INDEX_NOT_EXIST = (SCHEMA | (RCSchema::INDEX_NOT_EXIST << 8)),
SCHEMA_INDEX_NAME_ILLEGAL = (SCHEMA | (RCSchema::INDEX_NAME_ILLEGAL << 8)),
/*ioerror part*/
IOERR_READ = (IOERR | (RCIOError::READ << 8)),
IOERR_SHORT_READ = (IOERR | (RCIOError::SHORT_READ << 8)),
IOERR_WRITE = (IOERR | (RCIOError::WRITE << 8)),
IOERR_FSYNC = (IOERR | (RCIOError::FSYNC << 8)),
IOERR_DIR_FSYNC = (IOERR | (RCIOError::DIR_FSYNC << 8)),
IOERR_TRUNCATE = (IOERR | (RCIOError::TRUNCATE << 8)),
IOERR_FSTAT = (IOERR | (RCIOError::FSTAT << 8)),
IOERR_DELETE = (IOERR | (RCIOError::IO_DELETE << 8)),
IOERR_BLOCKED = (IOERR | (RCIOError::BLOCKED << 8)),
IOERR_ACCESS = (IOERR | (RCIOError::ACCESS << 8)),
IOERR_CHECKRESERVEDLOCK = (IOERR | (RCIOError::CHECKRESERVEDLOCK << 8)),
IOERR_CLOSE = (IOERR | (RCIOError::CLOSE << 8)),
IOERR_DIR_CLOSE = (IOERR | (RCIOError::DIR_CLOSE << 8)),
IOERR_SHMOPEN = (IOERR | (RCIOError::SHMOPEN << 8)),
IOERR_SHMSIZE = (IOERR | (RCIOError::SHMSIZE << 8)),
IOERR_SHMLOCK = (IOERR | (RCIOError::SHMLOCK << 8)),
IOERR_SHMMAP = (IOERR | (RCIOError::SHMMAP << 8)),
IOERR_SEEK = (IOERR | (RCIOError::SEEK << 8)),
IOERR_DELETE_NOENT = (IOERR | (RCIOError::DELETE_NOENT << 8)),
IOERR_MMAP = (IOERR | (RCIOError::MMAP << 8)),
IOERR_GETTEMPPATH = (IOERR | (RCIOError::GETTEMPPATH << 8)),
IOERR_CONVPATH = (IOERR | (RCIOError::IO_CONVPATH << 8)),
IOERR_VNODE = (IOERR | (RCIOError::VNODE << 8)),
IOERR_BEGIN_ATOMIC = (IOERR | (RCIOError::BEGIN_ATOMIC << 8)),
IOERR_COMMIT_ATOMIC = (IOERR | (RCIOError::COMMIT_ATOMIC << 8)),
IOERR_ROLLBACK_ATOMIC = (IOERR | (RCIOError::ROLLBACK_ATOMIC << 8)),
IOERR_DATA = (IOERR | (RCIOError::DATA << 8)),
IOERR_CORRUPTFS = (IOERR | (RCIOError::CORRUPTFS << 8)),
IOERR_OPEN_TOO_MANY_FILES = (IOERR | RCIOError::OPEN_TOO_MANY_FILES << 8),
/* Lock part*/
LOCKED_LOCK = (LOCKED | (RCLock::LOCK << 8)),
LOCKED_UNLOCK = (LOCKED | (RCLock::UNLOCK << 8)),
LOCKED_SHAREDCACHE = (LOCKED | (RCLock::SHAREDCACHE << 8)),
LOCKED_VIRT = (LOCKED | (RCLock::LVIRT << 8)),
LOCKED_NEED_WAIT = (LOCKED | (RCLock::NEED_WAIT << 8)),
LOCKED_RESOURCE_DELETED = (LOCKED | (RCLock::RESOURCE_DELETED << 8)),
LOCKED_CONCURRENCY_CONFLICT = (LOCKED | (RCLock::CONCURRENCY_CONFLICT << 8)),
/* busy part */
BUSY_RECOVERY = (BUSY | (RCBusy::BRECOVERY << 8)),
BUSY_SNAPSHOT = (BUSY | (RCBusy::SNAPSHOT << 8)),
BUSY_TIMEOUT = (BUSY | (RCBusy::TIMEOUT << 8)),
/* Can't open part */
CANTOPEN_NOTEMPDIR = (CANTOPEN | (RCCantOpen::NOTEMPDIR << 8)),
CANTOPEN_ISDIR = (CANTOPEN | (RCCantOpen::ISDIR << 8)),
CANTOPEN_FULLPATH = (CANTOPEN | (RCCantOpen::FULLPATH << 8)),
CANTOPEN_CONVPATH = (CANTOPEN | (RCCantOpen::CO_CONVPATH << 8)),
CANTOPEN_DIRTYWAL = (CANTOPEN | (RCCantOpen::DIRTYWAL << 8)),
CANTOPEN_SYMLINK = (CANTOPEN | (RCCantOpen::SYMLINK << 8)),
/* corrupt part */ // compile error
// CORRUPT_VIRT = (CORRUPT | (RCCorrupt::CORRUPT_VIRT << 8)),
// CORRUPT_SEQUENCE = (CORRUPT | (RCCorrupt::CORRUPT_SEQUENCE << 8)),
// CORRUPT_INDEX = (CORRUPT | (RCCorrupt::CORRUPT_INDEX << 8)),
/*readonly part*/
READONLY_RECOVERY = (READONLY | (RCReadonly::RO_RECOVERY << 8)),
READONLY_CANTLOCK = (READONLY | (RCReadonly::CANTLOCK << 8)),
READONLY_ROLLBACK = (READONLY | (RCReadonly::RO_ROLLBACK << 8)),
READONLY_DBMOVED = (READONLY | (RCReadonly::DBMOVED << 8)),
READONLY_CANTINIT = (READONLY | (RCReadonly::CANTINIT << 8)),
READONLY_DIRECTORY = (READONLY | (RCReadonly::DIRECTORY << 8)),
ABORT_ROLLBACK = (ABORT | (RCAbort::AROLLBACK << 8)),
/* contraint part */
CONSTRAINT_CHECK = (CONSTRAINT | (RCContraint::CHECK << 8)),
CONSTRAINT_COMMITHOOK = (CONSTRAINT | (RCContraint::COMMITHOOK << 8)),
CONSTRAINT_FOREIGNKEY = (CONSTRAINT | (RCContraint::FOREIGNKEY << 8)),
CONSTRAINT_FUNCTION = (CONSTRAINT | (RCContraint::FUNCTION << 8)),
CONSTRAINT_NOTNULL = (CONSTRAINT | (RCContraint::NOTNULL << 8)),
CONSTRAINT_PRIMARYKEY = (CONSTRAINT | (RCContraint::PRIMARYKEY << 8)),
CONSTRAINT_TRIGGER = (CONSTRAINT | (RCContraint::TRIGGER << 8)),
CONSTRAINT_UNIQUE = (CONSTRAINT | (RCContraint::UNIQUE << 8)),
CONSTRAINT_VIRT = (CONSTRAINT | (RCContraint::CVIRT << 8)),
CONSTRAINT_ROWID = (CONSTRAINT | (RCContraint::ROWID << 8)),
CONSTRAINT_PINNED = (CONSTRAINT | (RCContraint::PINNED << 8)),
/* notic part */
NOTICE_RECOVER_WAL = (NOTICE | (RCNotice::RECOVER_WAL << 8)),
NOTICE_RECOVER_ROLLBACK = (NOTICE | (RCNotice::RECOVER_ROLLBACK << 8)),
NOTICE_AUTOINDEX = (NOTICE | (RCNotice::AUTOINDEX << 8)),
/* file part */
FILE_EXIST = ( FILE_ERROR | (RCFILE::F_EXIST << 8)),
FILE_NOT_EXIST = ( FILE_ERROR | (RCFILE::F_NOT_EXIST << 8)),
FILE_NAME = ( FILE_ERROR | (RCFILE::F_NAME << 8)),
FILE_BOUND = ( FILE_ERROR | (RCFILE::F_BOUND << 8)),
FILE_CREATE = ( FILE_ERROR | (RCFILE::F_CREATE << 8)),
FILE_OPEN = ( FILE_ERROR | (RCFILE::F_OPEN << 8)),
FILE_NOT_OPENED = ( FILE_ERROR | (RCFILE::F_NOT_OPENED << 8)),
FILE_CLOSE = ( FILE_ERROR | (RCFILE::F_CLOSE << 8)),
FILE_REMOVE = ( FILE_ERROR | (RCFILE::F_REMOVE << 8)),
FILE_SEEK = ( FILE_ERROR | (RCFILE::F_SEEK << 8)),
FILE_READ = ( FILE_ERROR | (RCFILE::F_READ << 8)),
FILE_WRITE = ( FILE_ERROR | (RCFILE::F_WRITE << 8)),
/* auth part*/
AUTH_USER = (AUTH | (RCAuth::USER << 8)),
/* clog buffer part */
LOGBUF_FULL = (LOGBUF | (RCLOGBUF::LB_FULL << 8)),
LOGBUF_EMPTY = (LOGBUF | (RCLOGBUF::LB_EMPTY << 8)),
/**
* @brief 这个文件定义函数返回码/错误码(Return Code)
*/
#define DEFINE_RCS \
DEFINE_RC(SUCCESS) \
DEFINE_RC(INVALID_ARGUMENT) \
DEFINE_RC(UNIMPLENMENT) \
DEFINE_RC(SQL_SYNTAX) \
DEFINE_RC(INTERNAL) \
DEFINE_RC(NOMEM) \
DEFINE_RC(NOTFOUND) \
DEFINE_RC(EMPTY) \
DEFINE_RC(BUFFERPOOL_OPEN) \
DEFINE_RC(BUFFERPOOL_NOBUF) \
DEFINE_RC(BUFFERPOOL_INVALID_PAGE_NUM) \
DEFINE_RC(RECORD_OPENNED) \
DEFINE_RC(RECORD_INVALID_RID) \
DEFINE_RC(RECORD_INVALID_KEY) \
DEFINE_RC(RECORD_DUPLICATE_KEY) \
DEFINE_RC(RECORD_NOMEM) \
DEFINE_RC(RECORD_EOF) \
DEFINE_RC(RECORD_NOT_EXIST) \
DEFINE_RC(RECORD_INVISIBLE) \
DEFINE_RC(SCHEMA_DB_EXIST) \
DEFINE_RC(SCHEMA_DB_NOT_EXIST) \
DEFINE_RC(SCHEMA_DB_NOT_OPENED) \
DEFINE_RC(SCHEMA_TABLE_NOT_EXIST) \
DEFINE_RC(SCHEMA_TABLE_EXIST) \
DEFINE_RC(SCHEMA_FIELD_NOT_EXIST) \
DEFINE_RC(SCHEMA_FIELD_MISSING) \
DEFINE_RC(SCHEMA_FIELD_TYPE_MISMATCH) \
DEFINE_RC(SCHEMA_INDEX_NAME_REPEAT) \
DEFINE_RC(IOERR_READ) \
DEFINE_RC(IOERR_WRITE) \
DEFINE_RC(IOERR_ACCESS) \
DEFINE_RC(IOERR_OPEN) \
DEFINE_RC(IOERR_CLOSE) \
DEFINE_RC(IOERR_SEEK) \
DEFINE_RC(IOERR_TOO_LONG) \
DEFINE_RC(LOCKED_UNLOCK) \
DEFINE_RC(LOCKED_NEED_WAIT) \
DEFINE_RC(LOCKED_CONCURRENCY_CONFLICT) \
DEFINE_RC(FILE_EXIST) \
DEFINE_RC(FILE_NOT_EXIST) \
DEFINE_RC(FILE_NAME) \
DEFINE_RC(FILE_BOUND) \
DEFINE_RC(FILE_CREATE) \
DEFINE_RC(FILE_OPEN) \
DEFINE_RC(FILE_NOT_OPENED) \
DEFINE_RC(FILE_CLOSE) \
DEFINE_RC(FILE_REMOVE) \
DEFINE_RC(FILE_SEEK) \
DEFINE_RC(FILE_READ) \
DEFINE_RC(FILE_WRITE) \
DEFINE_RC(LOGBUF_FULL)
enum RC
{
#define DEFINE_RC(name) name,
DEFINE_RCS
#undef DEFINE_RC
};
extern const char *strrc(RC rc);
extern bool OB_SUCC(RC rc);
extern bool OB_FAIL(RC rc);
......@@ -93,7 +93,7 @@ RC ComparisonExpr::compare_tuple_cell(const TupleCell &left, const TupleCell &ri
} break;
default: {
LOG_WARN("unsupported comparison. %d", comp_);
rc = RC::GENERIC_ERROR;
rc = RC::INTERNAL;
} break;
}
......
......@@ -184,10 +184,10 @@ public:
RC cell_at(int index, TupleCell &cell) const override
{
if (index < 0 || index >= static_cast<int>(speces_.size())) {
return RC::GENERIC_ERROR;
return RC::INTERNAL;
}
if (tuple_ == nullptr) {
return RC::GENERIC_ERROR;
return RC::INTERNAL;
}
const TupleCellSpec *spec = speces_[index];
......
......@@ -23,7 +23,7 @@ RC try_to_get_bool_constant(std::unique_ptr<Expression> &expr, bool &constant_va
constant_value = value_expr->get_tuple_cell().get_boolean();
return RC::SUCCESS;
}
return RC::GENERIC_ERROR;
return RC::INTERNAL;
}
RC ConjunctionSimplificationRule::rewrite(std::unique_ptr<Expression> &expr, bool &change_made)
{
......
......@@ -113,7 +113,7 @@ RC CLogRecord::copy_record(void *dest, int start_off, int copy_len)
{
CLogRecords *log_rec = &log_record_;
if (start_off + copy_len > get_logrec_len()) {
return RC::GENERIC_ERROR;
return RC::INTERNAL;
} else if (flag_ != REDO_INSERT) {
memcpy(dest, (char *)log_rec + start_off, copy_len);
} else {
......@@ -167,7 +167,7 @@ CLogBuffer::~CLogBuffer()
RC CLogBuffer::append_log_record(CLogRecord *log_rec, int &start_off)
{
if (!log_rec) {
return RC::GENERIC_ERROR;
return RC::INTERNAL;
}
if (write_offset_ == CLOG_BUFFER_SIZE) {
return RC::LOGBUF_FULL;
......
......@@ -45,13 +45,13 @@ RC Db::init(const char *name, const char *dbpath)
if (!common::is_directory(dbpath)) {
LOG_ERROR("Failed to init DB, path is not a directory: %s", dbpath);
return RC::GENERIC_ERROR;
return RC::INTERNAL;
}
clog_manager_ = new CLogManager(dbpath);
if (clog_manager_ == nullptr) {
LOG_ERROR("Failed to init CLogManager.");
return RC::GENERIC_ERROR;
return RC::INTERNAL;
}
name_ = name;
......@@ -100,7 +100,7 @@ RC Db::open_all_tables()
int ret = common::list_file(path_.c_str(), TABLE_META_FILE_PATTERN, table_meta_files);
if (ret < 0) {
LOG_ERROR("Failed to list table meta files under %s.", path_.c_str());
return RC::IOERR;
return RC::IOERR_READ;
}
RC rc = RC::SUCCESS;
......@@ -118,7 +118,7 @@ RC Db::open_all_tables()
LOG_ERROR("Duplicate table with difference file name. table=%s, the other filename=%s",
table->name(),
filename.c_str());
return RC::GENERIC_ERROR;
return RC::INTERNAL;
}
opened_tables_[table->name()] = table;
......@@ -175,7 +175,7 @@ RC Db::recover()
if (find_iter == mtr_manager->trx_commited.end()) {
LOG_ERROR("CLog record without commit message! "); // unexpected error
delete clog_record;
return RC::GENERIC_ERROR;
return RC::INTERNAL;
} else if (find_iter->second == false) {
delete clog_record;
continue;
......
......@@ -101,7 +101,7 @@ RC FieldMeta::from_json(const Json::Value &json_value, FieldMeta &field)
{
if (!json_value.isObject()) {
LOG_ERROR("Failed to deserialize field. json is not an object. json value=%s", json_value.toStyledString().c_str());
return RC::GENERIC_ERROR;
return RC::INTERNAL;
}
const Json::Value &name_value = json_value[FIELD_NAME];
......@@ -112,30 +112,30 @@ RC FieldMeta::from_json(const Json::Value &json_value, FieldMeta &field)
if (!name_value.isString()) {
LOG_ERROR("Field name is not a string. json value=%s", name_value.toStyledString().c_str());
return RC::GENERIC_ERROR;
return RC::INTERNAL;
}
if (!type_value.isString()) {
LOG_ERROR("Field type is not a string. json value=%s", type_value.toStyledString().c_str());
return RC::GENERIC_ERROR;
return RC::INTERNAL;
}
if (!offset_value.isInt()) {
LOG_ERROR("Offset is not an integer. json value=%s", offset_value.toStyledString().c_str());
return RC::GENERIC_ERROR;
return RC::INTERNAL;
}
if (!len_value.isInt()) {
LOG_ERROR("Len is not an integer. json value=%s", len_value.toStyledString().c_str());
return RC::GENERIC_ERROR;
return RC::INTERNAL;
}
if (!visible_value.isBool()) {
LOG_ERROR("Visible field is not a bool value. json value=%s", visible_value.toStyledString().c_str());
return RC::GENERIC_ERROR;
return RC::INTERNAL;
}
AttrType type = attr_type_from_string(type_value.asCString());
if (UNDEFINED == type) {
LOG_ERROR("Got invalid field type. type=%d", type);
return RC::GENERIC_ERROR;
return RC::INTERNAL;
}
const char *name = name_value.asCString();
......
......@@ -47,14 +47,14 @@ RC IndexMeta::from_json(const TableMeta &table, const Json::Value &json_value, I
const Json::Value &field_value = json_value[FIELD_FIELD_NAME];
if (!name_value.isString()) {
LOG_ERROR("Index name is not a string. json value=%s", name_value.toStyledString().c_str());
return RC::GENERIC_ERROR;
return RC::INTERNAL;
}
if (!field_value.isString()) {
LOG_ERROR("Field name of index [%s] is not a string. json value=%s",
name_value.asCString(),
field_value.toStyledString().c_str());
return RC::GENERIC_ERROR;
return RC::INTERNAL;
}
const FieldMeta *field = table.field(field_value.asCString());
......
......@@ -79,7 +79,7 @@ RC Table::create(const char *path,
return RC::SCHEMA_TABLE_EXIST;
}
LOG_ERROR("Create table file failed. filename=%s, errmsg=%d:%s", path, errno, strerror(errno));
return RC::IOERR;
return RC::IOERR_OPEN;
}
close(fd);
......@@ -94,7 +94,7 @@ RC Table::create(const char *path,
fs.open(path, std::ios_base::out | std::ios_base::binary);
if (!fs.is_open()) {
LOG_ERROR("Failed to open file for write. file name=%s, errmsg=%s", path, strerror(errno));
return RC::IOERR;
return RC::IOERR_OPEN;
}
// 记录元数据到文件中
......@@ -129,12 +129,12 @@ RC Table::open(const char *meta_file, const char *base_dir)
fs.open(meta_file_path, std::ios_base::in | std::ios_base::binary);
if (!fs.is_open()) {
LOG_ERROR("Failed to open meta file for read. file name=%s, errmsg=%s", meta_file_path.c_str(), strerror(errno));
return RC::IOERR;
return RC::IOERR_OPEN;
}
if (table_meta_.deserialize(fs) < 0) {
LOG_ERROR("Failed to deserialize table meta. file name=%s", meta_file_path.c_str());
fs.close();
return RC::GENERIC_ERROR;
return RC::INTERNAL;
}
fs.close();
......@@ -157,7 +157,7 @@ RC Table::open(const char *meta_file, const char *base_dir)
name(), index_meta->name(), index_meta->field());
// skip cleanup
// do all cleanup action in destructive Table function
return RC::GENERIC_ERROR;
return RC::INTERNAL;
}
BplusTreeIndex *index = new BplusTreeIndex();
......@@ -381,11 +381,11 @@ RC Table::create_index(Trx *trx, const FieldMeta *field_meta, const char *index_
fs.open(tmp_file, std::ios_base::out | std::ios_base::binary | std::ios_base::trunc);
if (!fs.is_open()) {
LOG_ERROR("Failed to open file for write. file name=%s, errmsg=%s", tmp_file.c_str(), strerror(errno));
return RC::IOERR; // 创建索引中途出错,要做还原操作
return RC::IOERR_OPEN; // 创建索引中途出错,要做还原操作
}
if (new_table_meta.serialize(fs) < 0) {
LOG_ERROR("Failed to dump new table meta to file: %s. sys err=%d:%s", tmp_file.c_str(), errno, strerror(errno));
return RC::IOERR;
return RC::IOERR_WRITE;
}
fs.close();
......@@ -396,7 +396,7 @@ RC Table::create_index(Trx *trx, const FieldMeta *field_meta, const char *index_
LOG_ERROR("Failed to rename tmp meta file (%s) to normal meta file (%s) while creating index (%s) on table (%s). "
"system error=%d:%s",
tmp_file.c_str(), meta_file.c_str(), index_name, name(), errno, strerror(errno));
return RC::IOERR;
return RC::IOERR_WRITE;
}
table_meta_.swap(new_table_meta);
......
......@@ -55,7 +55,7 @@ RC DefaultHandler::init(const char *base_dir)
tmp += "/db";
if (!common::check_directory(tmp)) {
LOG_ERROR("Cannot access base dir: %s. msg=%d:%s", tmp.c_str(), errno, strerror(errno));
return RC::GENERIC_ERROR;
return RC::INTERNAL;
}
base_dir_ = base_dir;
......@@ -91,14 +91,14 @@ RC DefaultHandler::create_db(const char *dbname)
if (!common::check_directory(dbpath)) {
LOG_ERROR("Create db fail: %s", dbpath.c_str());
return RC::GENERIC_ERROR; // io error
return RC::INTERNAL; // io error
}
return RC::SUCCESS;
}
RC DefaultHandler::drop_db(const char *dbname)
{
return RC::GENERIC_ERROR;
return RC::INTERNAL;
}
RC DefaultHandler::open_db(const char *dbname)
......@@ -130,12 +130,12 @@ RC DefaultHandler::open_db(const char *dbname)
RC DefaultHandler::close_db(const char *dbname)
{
return RC::GENERIC_ERROR;
return RC::UNIMPLENMENT;
}
RC DefaultHandler::execute(const char *sql)
{
return RC::GENERIC_ERROR;
return RC::UNIMPLENMENT;
}
RC DefaultHandler::create_table(
......@@ -150,7 +150,7 @@ RC DefaultHandler::create_table(
RC DefaultHandler::drop_table(const char *dbname, const char *relation_name)
{
return RC::GENERIC_ERROR;
return RC::UNIMPLENMENT;
}
Db *DefaultHandler::find_db(const char *dbname) const
......
......@@ -46,13 +46,13 @@ RC BPFrameManager::init(int pool_num)
if (ret == 0) {
return RC::SUCCESS;
}
return RC::GENERIC_ERROR;
return RC::NOMEM;
}
RC BPFrameManager::cleanup()
{
if (frames_.count() > 0) {
return RC::GENERIC_ERROR;
return RC::INTERNAL;
}
frames_.destroy();
......
......@@ -1589,7 +1589,7 @@ RC BplusTreeHandler::delete_entry_internal(LatchMemo &latch_memo, Frame *leaf_fr
if (remove_count == 0) {
LOG_TRACE("no data need to remove");
// disk_buffer_pool_->unpin_page(leaf_frame);
return RC::RECORD_RECORD_NOT_EXIST;
return RC::RECORD_NOT_EXIST;
}
// leaf_index_node.validate(key_comparator_, disk_buffer_pool_, file_id_);
......@@ -1620,7 +1620,7 @@ RC BplusTreeHandler::delete_entry(const char *user_key, const RID *rid)
Frame *leaf_frame = nullptr;
RC rc = find_leaf(latch_memo, op, key, leaf_frame);
if (rc == RC::EMPTY) {
rc = RC::RECORD_RECORD_NOT_EXIST;
rc = RC::RECORD_NOT_EXIST;
return rc;
}
......
......@@ -258,7 +258,7 @@ RC RecordPageHandler::delete_record(const RID *rid)
return RC::SUCCESS;
} else {
LOG_DEBUG("Invalid slot_num %d, slot is empty, page_num %d.", rid->slot_num, frame_->page_num());
return RC::RECORD_RECORD_NOT_EXIST;
return RC::RECORD_NOT_EXIST;
}
}
......@@ -266,13 +266,13 @@ RC RecordPageHandler::get_record(const RID *rid, Record *rec)
{
if (rid->slot_num >= page_header_->record_capacity) {
LOG_ERROR("Invalid slot_num:%d, exceed page's record capacity, page_num %d.", rid->slot_num, frame_->page_num());
return RC::RECORD_INVALIDRID;
return RC::RECORD_INVALID_RID;
}
Bitmap bitmap(bitmap_, page_header_->record_capacity);
if (!bitmap.get_bit(rid->slot_num)) {
LOG_ERROR("Invalid slot_num:%d, slot is empty, page_num %d.", rid->slot_num, frame_->page_num());
return RC::RECORD_RECORD_NOT_EXIST;
return RC::RECORD_NOT_EXIST;
}
rec->set_rid(*rid);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册