From 3db0d4557c67c5d436e6d7405308514e506b94e5 Mon Sep 17 00:00:00 2001 From: prabatuty Date: Wed, 25 May 2011 02:42:50 +0000 Subject: [PATCH] Trie Index changes for retreiving metadata through catalog tool and rollback with logical undo logs for trie index --- include/DatabaseManagerImpl.h | 1 + include/Index.h | 4 ++-- include/Transaction.h | 4 ++++ src/storage/DatabaseManagerImpl.cxx | 25 ++++++++++++++++++++ src/storage/TrieIndex.cxx | 47 ++++++++++++++++++++++++++++++------- src/tools/catalog.cxx | 15 +++++++++++- 6 files changed, 84 insertions(+), 12 deletions(-) diff --git a/include/DatabaseManagerImpl.h b/include/DatabaseManagerImpl.h index bf37ce4b..1b2af8a7 100644 --- a/include/DatabaseManagerImpl.h +++ b/include/DatabaseManagerImpl.h @@ -148,6 +148,7 @@ class DllExport DatabaseManagerImpl : public DatabaseManager DbRetVal checkPoint(); DbRetVal recover(); DbRetVal printIndexInfo(char *name); + DbRetVal printIndexDebugInfo(char *name); void printTreeIndexNodeInfo(char *name,bool flag); friend class SessionImpl; }; diff --git a/include/Index.h b/include/Index.h index 3730dc35..7c94ae8e 100644 --- a/include/Index.h +++ b/include/Index.h @@ -168,8 +168,8 @@ class TrieIndex: public Index static void computeHashValues(DataType type, void *key, char *in, int length=0); static DbRetVal insertLogicalUndoLog(Database *sysdb, void *info); static DbRetVal deleteLogicalUndoLog(Database *sysdb, void *info); - void displayAll(TrieNode *node, int level =1); - void printTrieNode(TrieNode *node, int level); + static void displayAll(TrieNode *node, int level =1); + static void printTrieNode(TrieNode *node, int level); private: DbRetVal addToValueList(Database*, void**, Chunk*, IndexInfo*, void*, void*); DbRetVal removeFromValueList(Database*, void**, Chunk*, void*, void*); diff --git a/include/Transaction.h b/include/Transaction.h index 3b01bd82..fcc0a016 100644 --- a/include/Transaction.h +++ b/include/Transaction.h @@ -89,6 +89,10 @@ class TreeUndoLogInfo }; class TrieUndoLogInfo:public HashUndoLogInfo { + public: + + void **bucketPtr_; + TrieUndoLogInfo() { bucketPtr_ = NULL; } }; class DllExport Transaction diff --git a/src/storage/DatabaseManagerImpl.cxx b/src/storage/DatabaseManagerImpl.cxx index e042326c..2e46201b 100644 --- a/src/storage/DatabaseManagerImpl.cxx +++ b/src/storage/DatabaseManagerImpl.cxx @@ -1811,7 +1811,32 @@ void DatabaseManagerImpl::printTreeIndexNodeInfo(char *name, bool flag) if(hchunk) ((TreeNode*) hchunk)->displayAll(offset); } } +DbRetVal DatabaseManagerImpl::printIndexDebugInfo(char *name) +{ + CatalogTableINDEX cIndex(systemDatabase_); + DbRetVal rv = OK; + void *chunk = NULL, *hchunk = NULL; + void *tptr =NULL; + rv = cIndex.get(name, chunk, hchunk, tptr); + if (OK != rv) return rv; + IndexType iType = CatalogTableINDEX::getType(tptr); + if(hashIndex == iType) { + } + else if (treeIndex == iType) { + CINDEX *iptr = (CINDEX*)tptr; + TreeNode *start = (TreeNode*) iptr->hashNodeChunk_; + start->displayAll(0); + } + else if (trieIndex == iType) { + ChunkIterator citer = CatalogTableINDEX::getIterator(tptr); + TrieNode* start = (TrieNode*)citer.nextElement(); + if(start) TrieIndex::displayAll(start); + } + else + printf("Unknown Index\n"); + +} DbRetVal DatabaseManagerImpl::printIndexInfo(char *name) { CatalogTableINDEX cIndex(systemDatabase_); diff --git a/src/storage/TrieIndex.cxx b/src/storage/TrieIndex.cxx index ec2e6de7..688f9a8d 100644 --- a/src/storage/TrieIndex.cxx +++ b/src/storage/TrieIndex.cxx @@ -154,9 +154,10 @@ DbRetVal TrieIndex::insert(TableImpl *tbl, Transaction *tr, void *indexPtr, Inde //create logical undo log TrieUndoLogInfo hInfo; hInfo.metaData_ = tbl->db_->getMetaDataPtr(); - hInfo.bucket_ = NULL; + hInfo.bucketPtr_ = ptr; hInfo.tuple_ = tuple; hInfo.keyPtr_ = keyPtr; + hInfo.hChunk_ = hIdxNodeChunk; if (!loadFlag) { rv = tr->appendLogicalTrieUndoLog(tbl->sysDB_, InsertTrieIndexOperation, &hInfo, sizeof(TrieUndoLogInfo)); @@ -213,7 +214,8 @@ DbRetVal TrieIndex::removeFromValueList(Database *db, void **ptr, Chunk *hIdxNod DbRetVal rv = OK; if (!head) { - printError(rv, "Trie value list head is empty"); + rv = ErrSysFatal; + printError(rv, "Fatal:Trie value list head is empty"); return rv; } else @@ -276,9 +278,10 @@ DbRetVal TrieIndex::remove(TableImpl *tbl, Transaction *tr, void *indexPtr, Inde //create logical undo log TrieUndoLogInfo hInfo; hInfo.metaData_ = tbl->db_->getMetaDataPtr(); - hInfo.bucket_ = NULL; + hInfo.bucketPtr_ = ptr; hInfo.tuple_ = tuple; hInfo.keyPtr_ = keyPtr; + hInfo.hChunk_ = hIdxNodeChunk; if (!loadFlag) { rv = tr->appendLogicalTrieUndoLog(tbl->sysDB_, DeleteTrieIndexOperation, &hInfo, sizeof(TrieUndoLogInfo)); @@ -290,6 +293,7 @@ DbRetVal TrieIndex::remove(TableImpl *tbl, Transaction *tr, void *indexPtr, Inde DbRetVal TrieIndex::update(TableImpl *tbl, Transaction *tr, void *indexPtr, IndexInfo *indInfo, void *tuple, bool loadFlag) { DbRetVal rv = OK; + printError(ErrNotYet, "Not Yet Implemented"); return rv; } @@ -300,9 +304,32 @@ DbRetVal TrieIndex::insertLogicalUndoLog(Database *sysdb, void *data) Database db; db.setMetaDataPtr((DatabaseMetaData *) info->metaData_); db.setProcSlot(sysdb->procSlot); - IndexNode *head = (IndexNode *)((Bucket *)info->bucket_)->bucketList_; + void **bkt = info->bucketPtr_; + IndexNode *head = (IndexNode *)*bkt; BucketList list(head); - DbRetVal rv = list.insert(hChunk, &db, info->keyPtr_, info->tuple_); + DbRetVal rv = OK; + if (!head) + { + printDebug(DM_TrieIndex, "TrieIndex insert head is empty"); + IndexNode *firstNode= NULL; + firstNode= (IndexNode*) hChunk->tryAllocate(sysdb, &rv); + if (firstNode == NULL){ + printError(rv, "Unable to allocate index node for Trie index after retry"); + return rv; + } + firstNode->ptrToKey_ = info->keyPtr_; + firstNode->ptrToTuple_ = info->tuple_; + firstNode->next_ = NULL; + if (0 != Mutex::CASL((long*)bkt, 0, (long)firstNode)) { + printError(ErrLockTimeOut, "Trie Index bucket lock timeout.. retry"); + hChunk->free(sysdb, firstNode); + return ErrLockTimeOut; + } + printDebug(DM_TrieIndex, "TrieIndex insert new node %x in empty bucket", head); + return OK; + } + + rv = list.insert(hChunk, sysdb, info->keyPtr_, info->tuple_); if (rv != OK) { printError(ErrLockTimeOut, "Unable to add to bucket..retry\n"); @@ -318,12 +345,14 @@ DbRetVal TrieIndex::deleteLogicalUndoLog(Database *sysdb, void *data) Database db; db.setMetaDataPtr((DatabaseMetaData *)info->metaData_); db.setProcSlot(sysdb->procSlot); - IndexNode *head = (IndexNode *)((Bucket *)info->bucket_)->bucketList_; + void **bkt = info->bucketPtr_; + IndexNode *head = (IndexNode *)*bkt; BucketList list(head); DbRetVal rc = list.remove(hChunk, &db, info->keyPtr_); + *bkt = list.getBucketListHead(); if (SplCase == rc) { - if (0 != Mutex::CASL((long*)& (((Bucket *)info->bucket_)->bucketList_), - (long)(((Bucket *)info->bucket_)->bucketList_), + if (0 != Mutex::CASL((long*)bkt, + (long)*bkt, (long)list.getBucketListHead())) { printError(ErrLockTimeOut, "Unable to set the head of trie index bucket\n"); @@ -331,7 +360,7 @@ DbRetVal TrieIndex::deleteLogicalUndoLog(Database *sysdb, void *data) } }else if (rc != OK) { - printError(ErrLockTimeOut, "Unable to remove hash index node"); + printError(ErrLockTimeOut, "Unable to remove trie index node"); return ErrLockTimeOut; } return OK; diff --git a/src/tools/catalog.cxx b/src/tools/catalog.cxx index 686492c5..b2e646a6 100644 --- a/src/tools/catalog.cxx +++ b/src/tools/catalog.cxx @@ -50,7 +50,7 @@ int main(int argc, char **argv) password [0] = '\0'; int c = 0, opt = 0; char name[IDENTIFIER_LENGTH]; - while ((c = getopt(argc, argv, "u:p:T:I:D:licdsS?")) != EOF) + while ((c = getopt(argc, argv, "u:p:T:I:D:vlicdsS?")) != EOF) { switch (c) { @@ -69,6 +69,11 @@ int main(int argc, char **argv) else printf("Use -I IndexName -S\n"); break; }//print db usage statistics case '?' : { opt = 10; break; } //print help + case 'v' : { + if (opt == 5) opt = 15; + else if (opt == 6) opt=16; + break; + } default: opt=1; //list all the tables } @@ -251,6 +256,14 @@ int main(int argc, char **argv) dbMgr->printTreeIndexNodeInfo(name, true); } else if (opt == 12){ dbMgr->printTreeIndexNodeInfo(name,false); + } else if (opt ==15) { + } else if (opt ==16) { + rv = dbMgr->printIndexDebugInfo(name); + if (rv != OK) + { + printf(" %s \n", name); + ret =1; + } } iter.reset(); while (iter.hasElement()) delete iter.nextElement(); -- 2.11.4.GIT