Fixed up some return values; tests now pass with assert disabled.
This commit is contained in:
parent
eec80a0e38
commit
258dd5f4c4
5 changed files with 96 additions and 71 deletions
|
@ -41,7 +41,8 @@ int main(int argc, char** argv) {
|
|||
|
||||
for(i = 0; i < count ; i++) {
|
||||
int j;
|
||||
assert(TlogicalHashLookup(xid, hash, &i, sizeof(int), &j, sizeof(int)));
|
||||
int exists = TlogicalHashLookup(xid, hash, &i, sizeof(int), &j, sizeof(int));
|
||||
assert(exists);
|
||||
assert(i == j);
|
||||
|
||||
}
|
||||
|
|
|
@ -66,12 +66,16 @@ terms specified in this license.
|
|||
|
||||
/* @define error codes
|
||||
*/
|
||||
#define OUT_OF_MEM 1
|
||||
#define FILE_OPRN_ERROR 2
|
||||
#define FILE_READ_ERROR 3
|
||||
#define FILE_WRITE_ERROR 4
|
||||
#define FILE_WRITE_OPEN_ERROR 5
|
||||
#define MEM_WRITE_ERROR 6
|
||||
#define LLADD_DEADLOCK -1
|
||||
#define LLADD_NO_MEM -2
|
||||
#define LLADD_IO_ERROR -3
|
||||
#define LLADD_INTERNAL_ERROR -4
|
||||
|
||||
//#define FILE_OPRN_ERROR 2
|
||||
//#define FILE_READ_ERROR 3
|
||||
//#define FILE_WRITE_ERROR 4
|
||||
//#define FILE_WRITE_OPEN_ERROR 5
|
||||
//#define MEM_WRITE_ERROR 6
|
||||
|
||||
#define PAGE_SIZE 4096
|
||||
|
||||
|
|
|
@ -146,6 +146,7 @@ int openLogWriter() {
|
|||
assert(!ret); */
|
||||
char * buffer = malloc(BUFSIZE);
|
||||
|
||||
if(!buffer) { return LLADD_NO_MEM; }
|
||||
|
||||
int logFD = open (LOG_FILE, O_CREAT | O_RDWR | O_APPEND /*| O_SYNC*/, S_IRWXU | S_IRWXG | S_IRWXO);
|
||||
if(logFD == -1) {
|
||||
|
@ -157,9 +158,9 @@ int openLogWriter() {
|
|||
|
||||
if (log==NULL) {
|
||||
perror("Couldn't open log file");
|
||||
abort();
|
||||
// abort();
|
||||
/*there was an error opening this file */
|
||||
return FILE_WRITE_OPEN_ERROR;
|
||||
return LLADD_IO_ERROR; //FILE_WRITE_OPEN_ERROR;
|
||||
}
|
||||
|
||||
setbuffer(log, buffer, BUFSIZE);
|
||||
|
@ -200,8 +201,8 @@ int openLogWriter() {
|
|||
int nmemb = fwrite(&zero, sizeof(lsn_t), 1, log);
|
||||
if(nmemb != 1) {
|
||||
perror("Couldn't start new log file!");
|
||||
assert(0);
|
||||
return FILE_WRITE_OPEN_ERROR;
|
||||
// assert(0);
|
||||
return LLADD_IO_ERROR; //FILE_WRITE_OPEN_ERROR;
|
||||
}
|
||||
global_offset = 0;
|
||||
} else {
|
||||
|
@ -330,7 +331,7 @@ static int flushLog() {
|
|||
if(nmemb != 1) {
|
||||
perror("writeLog couldn't write next log entry!");
|
||||
assert(0);
|
||||
return FILE_WRITE_ERROR;
|
||||
return LLADD_IO_ERROR; // FILE_WRITE_ERROR;
|
||||
}
|
||||
return 0;
|
||||
|
||||
|
@ -408,9 +409,8 @@ static LogEntry * readLogEntry() {
|
|||
return NULL;
|
||||
}
|
||||
if(ferror(log)) {
|
||||
perror("Error reading log!");
|
||||
assert(0);
|
||||
return 0;
|
||||
perror("Error reading log");
|
||||
return (LogEntry*)LLADD_IO_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -428,23 +428,24 @@ static LogEntry * readLogEntry() {
|
|||
if(ferror(log)) {
|
||||
perror("Error reading log!");
|
||||
free(ret);
|
||||
assert(0);
|
||||
return 0;
|
||||
return (LogEntry*)LLADD_IO_ERROR;
|
||||
}
|
||||
assert(0);
|
||||
free(ret);
|
||||
return 0;
|
||||
perror("Unknown error in readLogEntry");
|
||||
return (LogEntry*)LLADD_IO_ERROR;
|
||||
}
|
||||
|
||||
|
||||
entrySize = sizeofLogEntry(ret);
|
||||
|
||||
// This sanity check makes no sense -- sizeOfLogEntry() has nothing
|
||||
// to do with the number of bytes read. */
|
||||
|
||||
/** Sanity check -- Did we get the whole entry? */
|
||||
if(size < entrySize) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// if(size < entrySize) {
|
||||
/* Read partial entry. */
|
||||
// free(ret);
|
||||
// return 0;
|
||||
// }
|
||||
|
||||
assert(size == entrySize);
|
||||
|
||||
|
@ -454,15 +455,6 @@ static LogEntry * readLogEntry() {
|
|||
LogEntry * readLSNEntry(lsn_t LSN) {
|
||||
LogEntry * ret;
|
||||
|
||||
/* We would need a lock to support this operation, and that's not worth it.
|
||||
if(!writeLogEntryIsReady) {
|
||||
if(LSN > maxLSNEncountered) {
|
||||
maxLSNEncountered = LSN;
|
||||
}
|
||||
} */
|
||||
|
||||
/* readlock(log_read_lock); */
|
||||
|
||||
/* Irritating overhead; two mutex acquires to do a read. */
|
||||
readlock(log_read_lock, 200);
|
||||
|
||||
|
@ -478,7 +470,6 @@ LogEntry * readLSNEntry(lsn_t LSN) {
|
|||
|
||||
}
|
||||
|
||||
|
||||
int truncateLog(lsn_t LSN) {
|
||||
FILE *tmpLog;
|
||||
|
||||
|
@ -502,10 +493,10 @@ int truncateLog(lsn_t LSN) {
|
|||
tmpLog = fopen(LOG_FILE_SCRATCH, "w+"); /* w+ = truncate, and open for writing. */
|
||||
|
||||
if (tmpLog==NULL) {
|
||||
assert(0);
|
||||
/*there was an error opening this file */
|
||||
pthread_mutex_unlock(&truncateLog_mutex);
|
||||
perror("logTruncate() couldn't create scratch log file!");
|
||||
return FILE_WRITE_OPEN_ERROR;
|
||||
return LLADD_IO_ERROR;
|
||||
}
|
||||
|
||||
/* Need to write LSN - sizeof(lsn_t) to make room for the offset in
|
||||
|
@ -553,26 +544,30 @@ int truncateLog(lsn_t LSN) {
|
|||
fclose(tmpLog);
|
||||
|
||||
if(rename(LOG_FILE_SCRATCH, LOG_FILE)) {
|
||||
perror("Log truncation failed!");
|
||||
abort();
|
||||
writeunlock(log_read_lock);
|
||||
pthread_mutex_unlock(&log_write_mutex);
|
||||
pthread_mutex_unlock(&truncateLog_mutex);
|
||||
|
||||
perror("Error replacing old log file with new log file");
|
||||
return LLADD_IO_ERROR;
|
||||
}
|
||||
|
||||
|
||||
log = fopen(LOG_FILE, "a+");
|
||||
if (log==NULL) {
|
||||
abort();
|
||||
/*there was an error opening this file */
|
||||
return FILE_WRITE_OPEN_ERROR;
|
||||
}
|
||||
|
||||
/* myFseek(log, 0, SEEK_SET); */
|
||||
global_offset = LSN - sizeof(lsn_t); /*= fread(&global_offset, sizeof(lsn_t), 1, log);*/
|
||||
/*assert(count == 1); */
|
||||
|
||||
/* funlockfile(log); */
|
||||
writeunlock(log_read_lock);
|
||||
pthread_mutex_unlock(&log_write_mutex);
|
||||
pthread_mutex_unlock(&truncateLog_mutex);
|
||||
|
||||
perror("Couldn't reopen log after truncate");
|
||||
return LLADD_IO_ERROR;
|
||||
}
|
||||
|
||||
global_offset = LSN - sizeof(lsn_t);
|
||||
|
||||
writeunlock(log_read_lock);
|
||||
pthread_mutex_unlock(&log_write_mutex);
|
||||
pthread_mutex_unlock(&truncateLog_mutex);
|
||||
|
||||
return 0;
|
||||
|
|
|
@ -71,9 +71,11 @@ START_TEST(linearHashNTAtest)
|
|||
val.page = i * NUM_ENTRIES;
|
||||
val.slot = val.page * NUM_ENTRIES;
|
||||
val.size = val.slot * NUM_ENTRIES;
|
||||
assert(-1 == ThashLookup(xid, hashHeader, (byte*)&i, sizeof(int), (byte**)&val2));
|
||||
int found = ThashLookup(xid, hashHeader, (byte*)&i, sizeof(int), (byte**)&val2);
|
||||
assert(-1 == found);
|
||||
ThashInsert(xid, hashHeader, (byte*)&i, sizeof(int), (byte*)&val, sizeof(recordid));
|
||||
assert(sizeof(recordid) == ThashLookup(xid, hashHeader, (byte*)&i, sizeof(int), (byte**)&val2));
|
||||
found = ThashLookup(xid, hashHeader, (byte*)&i, sizeof(int), (byte**)&val2);
|
||||
assert(sizeof(recordid) == found);
|
||||
assert(val2->page == i * NUM_ENTRIES);
|
||||
assert(val2->slot == val2->page * NUM_ENTRIES);
|
||||
assert(val2->size == val2->slot * NUM_ENTRIES);
|
||||
|
@ -88,11 +90,15 @@ START_TEST(linearHashNTAtest)
|
|||
if(!(i % (NUM_ENTRIES/10))) {
|
||||
printf("-"); fflush(stdout);
|
||||
}
|
||||
assert(sizeof(recordid) == ThashLookup(xid, hashHeader, (byte*)&i, sizeof(int), (byte**)&val2));
|
||||
int found = ThashLookup(xid, hashHeader, (byte*)&i, sizeof(int), (byte**)&val2);
|
||||
assert(sizeof(recordid) == found);
|
||||
free(val2);
|
||||
assert(ThashRemove(xid, hashHeader, (byte*)&i, sizeof(int)));
|
||||
assert(-1==ThashLookup(xid, hashHeader, (byte*)&i, sizeof(int), (byte**)&val2));
|
||||
assert(!ThashRemove(xid, hashHeader, (byte*)&i, sizeof(int)));
|
||||
found = ThashRemove(xid, hashHeader, (byte*)&i, sizeof(int));
|
||||
assert(found);
|
||||
found = ThashLookup(xid, hashHeader, (byte*)&i, sizeof(int), (byte**)&val2);
|
||||
assert(-1==found);
|
||||
found = ThashRemove(xid, hashHeader, (byte*)&i, sizeof(int));
|
||||
assert(!found);
|
||||
}
|
||||
printf("\nabort()\n"); fflush(stdout);
|
||||
Tabort(xid);
|
||||
|
@ -101,7 +107,8 @@ START_TEST(linearHashNTAtest)
|
|||
if(!(i % (NUM_ENTRIES/10))) {
|
||||
printf("+"); fflush(stdout);
|
||||
}
|
||||
assert(sizeof(recordid) == ThashLookup(xid, hashHeader, (byte*)&i, sizeof(int), (byte**)&val2));
|
||||
int found = ThashLookup(xid, hashHeader, (byte*)&i, sizeof(int), (byte**)&val2);
|
||||
assert(sizeof(recordid) == found);
|
||||
assert(val2->page == i * NUM_ENTRIES);
|
||||
assert(val2->slot == val2->page * NUM_ENTRIES);
|
||||
assert(val2->size == val2->slot * NUM_ENTRIES);
|
||||
|
@ -131,7 +138,8 @@ START_TEST(linearHashNTAVariableSizetest)
|
|||
val.slot = val.page * NUM_ENTRIES;
|
||||
val.size = val.slot * NUM_ENTRIES;
|
||||
val2 = 0;
|
||||
assert(-1 == ThashLookup(xid, hashHeader, (byte*)&i, sizeof(int), (byte**)&val2));
|
||||
int found = ThashLookup(xid, hashHeader, (byte*)&i, sizeof(int), (byte**)&val2);
|
||||
assert(-1 == found);
|
||||
ThashInsert(xid, hashHeader, (byte*)&i, sizeof(int), (byte*)&val, sizeof(recordid));
|
||||
val2 =0;
|
||||
int ret = ThashLookup(xid, hashHeader, (byte*)&i, sizeof(int), (byte**)&val2);
|
||||
|
@ -150,11 +158,15 @@ START_TEST(linearHashNTAVariableSizetest)
|
|||
if(!(i % (NUM_ENTRIES/10))) {
|
||||
printf("-"); fflush(stdout);
|
||||
}
|
||||
assert(sizeof(recordid) == ThashLookup(xid, hashHeader, (byte*)&i, sizeof(int), (byte**)&val2));
|
||||
int found = ThashLookup(xid, hashHeader, (byte*)&i, sizeof(int), (byte**)&val2);
|
||||
assert(sizeof(recordid) == found);
|
||||
free(val2);
|
||||
assert(ThashRemove(xid, hashHeader, (byte*)&i, sizeof(int)));
|
||||
assert(-1==ThashLookup(xid, hashHeader, (byte*)&i, sizeof(int), (byte**)&val2));
|
||||
assert(!ThashRemove(xid, hashHeader, (byte*)&i, sizeof(int)));
|
||||
found = ThashRemove(xid, hashHeader, (byte*)&i, sizeof(int));
|
||||
assert(found);
|
||||
found = ThashLookup(xid, hashHeader, (byte*)&i, sizeof(int), (byte**)&val2);
|
||||
assert(-1==found);
|
||||
found = ThashRemove(xid, hashHeader, (byte*)&i, sizeof(int));
|
||||
assert(!found);
|
||||
}
|
||||
printf("\nabort()\n"); fflush(stdout);
|
||||
Tabort(xid);
|
||||
|
@ -210,9 +222,12 @@ void * worker(void* arg) {
|
|||
for(i = 0; i < NUM_T_ENTRIES; i+=10) {
|
||||
int * value;
|
||||
recordid key = makekey(thread,i);
|
||||
assert(ThashRemove(xid, hash, (byte*)&key, sizeof(recordid)));
|
||||
assert(-1==ThashLookup(xid, hash, (byte*)&key, sizeof(recordid), (byte**)&value));
|
||||
assert(!ThashRemove(xid, hash, (byte*)&key, sizeof(recordid)));
|
||||
int found = ThashRemove(xid, hash, (byte*)&key, sizeof(recordid));
|
||||
assert(found);
|
||||
found = ThashLookup(xid, hash, (byte*)&key, sizeof(recordid), (byte**)&value);
|
||||
assert(-1==found);
|
||||
found = ThashRemove(xid, hash, (byte*)&key, sizeof(recordid));
|
||||
assert(!found);
|
||||
}
|
||||
|
||||
Tabort(xid);
|
||||
|
@ -221,7 +236,8 @@ void * worker(void* arg) {
|
|||
for(i = 0; i < NUM_T_ENTRIES; i+=10) {
|
||||
recordid key = makekey(thread,i);
|
||||
int * value;
|
||||
assert(sizeof(int) == ThashLookup(xid, hash, (byte*)&key, sizeof(recordid), (byte**)&value));
|
||||
int found = ThashLookup(xid, hash, (byte*)&key, sizeof(recordid), (byte**)&value);
|
||||
assert(sizeof(int) == found);
|
||||
assert(*value == i + thread * NUM_T_ENTRIES);
|
||||
free (value);
|
||||
}
|
||||
|
@ -258,7 +274,8 @@ START_TEST(linearHashNTAIteratortest) {
|
|||
|
||||
for(i = 0; i < NUM_ENTRIES; i++) {
|
||||
recordid value = makekey(0, i);
|
||||
assert(!ThashInsert(xid, hash, (byte*)&i, sizeof(int), (byte*)&value, sizeof(recordid)));
|
||||
int found = ThashInsert(xid, hash, (byte*)&i, sizeof(int), (byte*)&value, sizeof(recordid));
|
||||
assert(!found);
|
||||
}
|
||||
|
||||
int seen[NUM_ENTRIES];
|
||||
|
|
|
@ -67,9 +67,11 @@ START_TEST(linkedListNTAtest)
|
|||
val.page = i * 1000;
|
||||
val.slot = val.page * 1000;
|
||||
val.size = val.slot * 1000;
|
||||
assert(-1==TlinkedListFind(xid, linkedList, (byte*)(&i), sizeof(int), (byte**)&val2));
|
||||
int found = TlinkedListFind(xid, linkedList, (byte*)(&i), sizeof(int), (byte**)&val2);
|
||||
assert(-1==found);
|
||||
TlinkedListInsert(xid, linkedList, (byte*)&i, sizeof(int), (byte*)&val, sizeof(recordid));
|
||||
assert(sizeof(recordid)==TlinkedListFind(xid, linkedList, (byte*)(&i), sizeof(int), (byte**)&val2));
|
||||
found = TlinkedListFind(xid, linkedList, (byte*)(&i), sizeof(int), (byte**)&val2);
|
||||
assert(sizeof(recordid)==found);
|
||||
assert(!memcmp(&val, val2, sizeof(recordid)));
|
||||
free(val2);
|
||||
}
|
||||
|
@ -79,20 +81,26 @@ START_TEST(linkedListNTAtest)
|
|||
xid = Tbegin();
|
||||
for(i = 0; i < 1000; i+=10) {
|
||||
recordid * val2 = NULL;
|
||||
assert(sizeof(recordid)==TlinkedListFind(xid, linkedList, (byte*)(&i), sizeof(int), (byte**)&val2));
|
||||
int found = TlinkedListFind(xid, linkedList, (byte*)(&i), sizeof(int), (byte**)&val2);
|
||||
assert(sizeof(recordid)==found);
|
||||
assert(val2->page == i * 1000);
|
||||
assert(val2->slot == i * 1000 * 1000);
|
||||
assert(val2->size == i * 1000 * 1000 * 1000);
|
||||
free(val2);
|
||||
assert(TlinkedListRemove(xid, linkedList, (byte*)&i, sizeof(int)));
|
||||
assert(-1==TlinkedListFind(xid, linkedList, (byte*)(&i), sizeof(int), (byte**)&val2));
|
||||
assert(!TlinkedListRemove(xid, linkedList, (byte*)&i, sizeof(int)));
|
||||
|
||||
found = TlinkedListRemove(xid, linkedList, (byte*)&i, sizeof(int));
|
||||
assert(found);
|
||||
found = TlinkedListFind(xid, linkedList, (byte*)(&i), sizeof(int), (byte**)&val2);
|
||||
assert(-1==found);
|
||||
found = TlinkedListRemove(xid, linkedList, (byte*)&i, sizeof(int));
|
||||
assert(!found);
|
||||
}
|
||||
Tabort(xid);
|
||||
xid = Tbegin();
|
||||
for(i = 0; i < 1000; i++) {
|
||||
recordid * val2;
|
||||
assert(sizeof(recordid)==TlinkedListFind(xid, linkedList, (byte*)(&i), sizeof(int), (byte**)&val2));
|
||||
int found = TlinkedListFind(xid, linkedList, (byte*)(&i), sizeof(int), (byte**)&val2);
|
||||
assert(sizeof(recordid)==found);
|
||||
assert(val2->page == i * 1000);
|
||||
assert(val2->slot == i * 1000 * 1000);
|
||||
assert(val2->size == i * 1000 * 1000 * 1000);
|
||||
|
|
Loading…
Reference in a new issue