/* Copyright (C) 2014 InfiniDB, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; version 2 of the License. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ // $Id: systemcatalog.cpp 2101 2013-01-21 14:12:52Z rdempsey $ #include #include #include using namespace std; #include "systemcatalog.h" #include "configcpp.h" using namespace execplan; #include "we_colopcompress.h" using namespace WriteEngine; #include "resourcemanager.h" using namespace joblist; #include "dbbuilder.h" void SystemCatalog::build() { TxnID txnID = 0; int rc; //int t= 1000; remove(); cout << "Creating System Catalog..." << endl; cout << endl; // SYSTABLE timeval startTime; gettimeofday( &startTime, 0); ostringstream msg; WErrorCodes ec; //------------------------------------------------------------------------------ // Get the DBRoot count, and rotate the tables through those DBRoots. // All the columns in the first table (SYSTABLE) start on DBRoot1, all the // columns in the second table (SYSCOLUMN) start on DBRoot2, etc. //------------------------------------------------------------------------------ config::Config* cf = config::Config::makeConfig(); string root = cf->getConfig("SystemConfig","DBRootCount"); uint32_t dbRootCount = cf->uFromText(root); //------------------------------------------------------------------------------ // Create SYSTABLE table //------------------------------------------------------------------------------ uint32_t dbRoot = 1; int compressionType = 0; uint32_t partition = 0; uint16_t segment=0; ResourceManager rm; std::map oids; if( rm.useHdfs() ) { compressionType = 2; oids[OID_SYSTABLE_TABLENAME] = OID_SYSTABLE_TABLENAME; oids[DICTOID_SYSTABLE_TABLENAME] = DICTOID_SYSTABLE_TABLENAME; oids[OID_SYSTABLE_SCHEMA] = OID_SYSTABLE_SCHEMA; oids[DICTOID_SYSTABLE_SCHEMA] = DICTOID_SYSTABLE_SCHEMA; oids[OID_SYSTABLE_OBJECTID] = OID_SYSTABLE_OBJECTID; oids[OID_SYSTABLE_CREATEDATE] = OID_SYSTABLE_CREATEDATE; oids[OID_SYSTABLE_LASTUPDATE] = OID_SYSTABLE_LASTUPDATE; oids[OID_SYSTABLE_INIT] = OID_SYSTABLE_INIT; oids[OID_SYSTABLE_NEXT] = OID_SYSTABLE_NEXT; oids[OID_SYSTABLE_NUMOFROWS] = OID_SYSTABLE_NUMOFROWS; oids[OID_SYSTABLE_AVGROWLEN] = OID_SYSTABLE_AVGROWLEN; oids[OID_SYSTABLE_NUMOFBLOCKS] = OID_SYSTABLE_NUMOFBLOCKS; oids[OID_SYSTABLE_AUTOINCREMENT] = OID_SYSTABLE_AUTOINCREMENT; } fWriteEngine.setTransId(1); fWriteEngine.setBulkFlag(true); cout << "Creating SYSTABLE" << endl; cout << "---------------------------------------" << endl; // TableName msg << " Creating TableName column OID: "<< OID_SYSTABLE_TABLENAME; cout << msg.str() << endl; rc = fWriteEngine.createColumn( txnID, OID_SYSTABLE_TABLENAME, CalpontSystemCatalog::VARCHAR, 40, dbRoot, partition, compressionType ); if (rc) throw runtime_error(msg.str() + ec.errorString(rc)); msg.str(""); msg << " Creating TableName column dictionary"; //Dictionary files cout << msg.str() << endl; rc = fWriteEngine.createDctnry(txnID, DICTOID_SYSTABLE_TABLENAME, 65, dbRoot, partition, segment, compressionType ); if (rc) throw runtime_error(msg.str() + ec.errorString(rc)); msg.str(""); // Schema msg << " Creating Schema column OID: "< dbRootCount) // dbRoot = 1; //SYSCOLUMN if( rm.useHdfs() ) { oids[OID_SYSCOLUMN_SCHEMA] = OID_SYSCOLUMN_SCHEMA; oids[DICTOID_SYSCOLUMN_SCHEMA] = DICTOID_SYSCOLUMN_SCHEMA; oids[OID_SYSCOLUMN_TABLENAME] = OID_SYSCOLUMN_TABLENAME; oids[DICTOID_SYSCOLUMN_TABLENAME] = DICTOID_SYSCOLUMN_TABLENAME; oids[OID_SYSCOLUMN_COLNAME] = OID_SYSCOLUMN_COLNAME; oids[DICTOID_SYSCOLUMN_COLNAME] = DICTOID_SYSCOLUMN_COLNAME; oids[OID_SYSCOLUMN_OBJECTID] = OID_SYSCOLUMN_OBJECTID; oids[OID_SYSCOLUMN_DICTOID] = OID_SYSCOLUMN_DICTOID; oids[OID_SYSCOLUMN_LISTOBJID] = OID_SYSCOLUMN_LISTOBJID; oids[OID_SYSCOLUMN_TREEOBJID] = OID_SYSCOLUMN_TREEOBJID; oids[OID_SYSCOLUMN_DATATYPE] = OID_SYSCOLUMN_DATATYPE; oids[OID_SYSCOLUMN_COLUMNLEN] = OID_SYSCOLUMN_COLUMNLEN; oids[OID_SYSCOLUMN_COLUMNPOS] = OID_SYSCOLUMN_COLUMNPOS; oids[OID_SYSCOLUMN_LASTUPDATE] = OID_SYSCOLUMN_LASTUPDATE; oids[OID_SYSCOLUMN_DEFAULTVAL] = OID_SYSCOLUMN_DEFAULTVAL; oids[DICTOID_SYSCOLUMN_DEFAULTVAL] = DICTOID_SYSCOLUMN_DEFAULTVAL; oids[OID_SYSCOLUMN_NULLABLE] = OID_SYSCOLUMN_NULLABLE; oids[OID_SYSCOLUMN_SCALE] = OID_SYSCOLUMN_SCALE; oids[OID_SYSCOLUMN_PRECISION] = OID_SYSCOLUMN_PRECISION; oids[OID_SYSCOLUMN_AUTOINC] = OID_SYSCOLUMN_AUTOINC; oids[OID_SYSCOLUMN_DISTCOUNT] = OID_SYSCOLUMN_DISTCOUNT; oids[OID_SYSCOLUMN_NULLCOUNT] = OID_SYSCOLUMN_NULLCOUNT; oids[OID_SYSCOLUMN_MINVALUE] = OID_SYSCOLUMN_MINVALUE; oids[DICTOID_SYSCOLUMN_MINVALUE] = DICTOID_SYSCOLUMN_MINVALUE; oids[OID_SYSCOLUMN_MAXVALUE] = OID_SYSCOLUMN_MAXVALUE; oids[DICTOID_SYSCOLUMN_MAXVALUE] = DICTOID_SYSCOLUMN_MAXVALUE; oids[OID_SYSCOLUMN_COMPRESSIONTYPE] = OID_SYSCOLUMN_COMPRESSIONTYPE; oids[OID_SYSCOLUMN_NEXTVALUE] = OID_SYSCOLUMN_NEXTVALUE; } cout<< endl; cout << "Creating SYSCOLUMN" << endl; // Schema cout << "---------------------------------------" << endl; msg << " Creating Schema column OID: "< dbRootCount) dbRoot = 1; //flush data files fWriteEngine.flushDataFiles(rc, 1, oids); // save brm msg.str(" BRMWrapper saving state "); rc = BRMWrapper::getInstance()->saveState(); if (rc) throw runtime_error(msg.str() + ec.errorString(rc)); timeval endTime; gettimeofday( &endTime, 0); double elapsedTime = (endTime.tv_sec + (endTime.tv_usec / 1000000.0)) - (startTime.tv_sec + (startTime.tv_usec / 1000000.0)); cout << "System Catalog creation took: " << elapsedTime << " seconds to complete." << endl; cout << endl; cout << "System Catalog created" << endl; cout << endl; } void SystemCatalog::remove() { ColumnOpCompress0 colOp; for ( int c = 1001; c <= 1074; c++ ) colOp.deleteFile( c ); for ( int d = 2001; d <= 2312; d++ ) colOp.deleteFile( d ); }