From edd8a30142435d6c61345e45fb49ed8977dda197 Mon Sep 17 00:00:00 2001 From: David Hall Date: Fri, 20 Jan 2017 13:35:13 -0600 Subject: [PATCH 01/35] MCOL-455 Add check for system running to prevent mcsadmin crash --- oamapps/mcsadmin/mcsadmin.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/oamapps/mcsadmin/mcsadmin.cpp b/oamapps/mcsadmin/mcsadmin.cpp index 00b8efbeb..af556ec47 100644 --- a/oamapps/mcsadmin/mcsadmin.cpp +++ b/oamapps/mcsadmin/mcsadmin.cpp @@ -719,6 +719,11 @@ int processCommand(string* arguments) vector srcDbroots; // all of the currently configured dbroots vector destDbroots; // srcDbroots - removeDbroots set::iterator dbiter; + if (!oam.checkSystemRunning()) + { + cout << "Mariadb ColumnStore is not running" << endl; + break; + } if (arguments[1] == "start") { // Get a list of all the configured dbroots in the xml file. From 892906d40b99e0332df475177e4e1db0aa77323e Mon Sep 17 00:00:00 2001 From: David Hall Date: Tue, 24 Jan 2017 16:27:11 -0600 Subject: [PATCH 02/35] MCOL-513 Use threadpool for session threads --- exemgr/main.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/exemgr/main.cpp b/exemgr/main.cpp index cb84213fd..8ccebcba5 100644 --- a/exemgr/main.cpp +++ b/exemgr/main.cpp @@ -97,6 +97,8 @@ using namespace querytele; #include "utils_utf8.h" #include "boost/filesystem.hpp" +#include "threadpool.h" + namespace { //If any flags other than the table mode flags are set, produce output to screeen @@ -1431,12 +1433,14 @@ int main(int argc, char* argv[]) } } + threadpool::ThreadPool exeMgrThreadPool(serverThreads, serverQueueSize); for (;;) { IOSocket ios; ios = mqs->accept(); - boost::thread thd(SessionThread(ios, ec, rm)); + exeMgrThreadPool.invoke(SessionThread(ios, ec, rm)); } + exeMgrThreadPool.wait(); return 0; } From e2d66222cd439577bd973cfd7bab409d5556d694 Mon Sep 17 00:00:00 2001 From: David Hall Date: Wed, 25 Jan 2017 10:39:03 -0600 Subject: [PATCH 03/35] MCOL-513 Use threadpool for FEMsgHandler --- exemgr/femsghandler.cpp | 8 ++++++-- exemgr/femsghandler.h | 9 ++++++++- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/exemgr/femsghandler.cpp b/exemgr/femsghandler.cpp index 776a7cc83..c3df2ba92 100644 --- a/exemgr/femsghandler.cpp +++ b/exemgr/femsghandler.cpp @@ -24,6 +24,8 @@ using namespace std; using namespace joblist; using namespace messageqcpp; +threadpool::ThreadPool FEMsgHandler::threadPool(100,200); + namespace { class Runner @@ -50,14 +52,15 @@ FEMsgHandler::FEMsgHandler(boost::shared_ptr j, IOSocket *s) : FEMsgHandler::~FEMsgHandler() { stop(); - thr.join(); +// thr.join(); + boost::unique_lock lk(joinMutex); } void FEMsgHandler::start() { if (!running) { running = true; - thr = boost::thread(Runner(this)); + threadPool.invoke(Runner(this)); } } @@ -106,6 +109,7 @@ bool FEMsgHandler::aborted() void FEMsgHandler::threadFcn() { int err = 0; + boost::unique_lock lk(joinMutex); int connectionNum = sock->getConnectionNum(); /* This waits for the next readable event on sock. An abort is signaled diff --git a/exemgr/femsghandler.h b/exemgr/femsghandler.h index b7bac18f0..1d51e6d95 100644 --- a/exemgr/femsghandler.h +++ b/exemgr/femsghandler.h @@ -20,6 +20,7 @@ #include "joblist.h" #include "inetstreamsocket.h" +#include "threadpool.h" class FEMsgHandler { @@ -40,8 +41,14 @@ private: bool die, running, sawData; messageqcpp::IOSocket *sock; boost::shared_ptr jl; - boost::thread thr; boost::mutex mutex; +// boost::thread thr; + static threadpool::ThreadPool threadPool; + + // Because we can't join() a thread from a thread pool, threadFcn will + // unlock when it exits and the destructor can block until the thread is done. + boost::mutex joinMutex; + }; #endif /* FEMSGHANDLER_H_ */ From c4742b83630355afef40d37956da2b8014d68d36 Mon Sep 17 00:00:00 2001 From: David Hall Date: Fri, 27 Jan 2017 15:53:11 -0600 Subject: [PATCH 04/35] MCOL-513 Modify ThreadPool to have a join() method --- utils/threadpool/threadpool.cpp | 42 ++++++++++++++++++++++++++------- utils/threadpool/threadpool.h | 14 +++++++---- 2 files changed, 44 insertions(+), 12 deletions(-) diff --git a/utils/threadpool/threadpool.cpp b/utils/threadpool/threadpool.cpp index f25367090..14aa074f6 100644 --- a/utils/threadpool/threadpool.cpp +++ b/utils/threadpool/threadpool.cpp @@ -73,6 +73,7 @@ void ThreadPool::init() fStop = false; // fThreadCreated = new NoOp(); fNextFunctor = fWaitingFunctors.end(); + fNextHandle=1; } void ThreadPool::setQueueSize(size_t queueSize) @@ -115,10 +116,35 @@ void ThreadPool::wait() } } -void ThreadPool::invoke(const Functor_T &threadfunc) +void ThreadPool::join(uint64_t thrHandle) { boost::mutex::scoped_lock lock1(fMutex); + while (waitingFunctorsSize > 0) + { + Container_T::iterator iter; + Container_T::iterator end = fWaitingFunctors.end(); + bool foundit = false; + for (iter = fWaitingFunctors.begin(); iter != end; ++iter) + { + if (iter->first == thrHandle) + { + foundit = true; + break; + } + } + if (!foundit) + { + break; + } + fThreadAvailable.wait(lock1); + } +} + +int64_t ThreadPool::invoke(const Functor_T &threadfunc) +{ + boost::mutex::scoped_lock lock1(fMutex); + int64_t thrHandle=0; for(;;) { @@ -128,7 +154,7 @@ void ThreadPool::invoke(const Functor_T &threadfunc) { // Don't create a thread unless it's needed. There // is a thread available to service this request. - addFunctor(threadfunc); + thrHandle = addFunctor(threadfunc); lock1.unlock(); break; } @@ -138,7 +164,7 @@ void ThreadPool::invoke(const Functor_T &threadfunc) if ( waitingFunctorsSize < fQueueSize) { // Don't create a thread unless you have to - addFunctor(threadfunc); + thrHandle = addFunctor(threadfunc); bAdded = true; } @@ -175,6 +201,7 @@ void ThreadPool::invoke(const Functor_T &threadfunc) } fNeedThread.notify_one(); + return thrHandle; } void ThreadPool::beginThread() throw() @@ -218,7 +245,7 @@ void ThreadPool::beginThread() throw() for (i = 0; i < num; i++) { try { - (*todoList[i])(); + (*todoList[i]).second(); } catch(exception &e) { ++fFunctorErrors; @@ -290,24 +317,23 @@ void ThreadPool::beginThread() throw() catch(...) { } - } - } -void ThreadPool::addFunctor(const Functor_T &func) +int64_t ThreadPool::addFunctor(const Functor_T &func) { bool bAtEnd = false; if (fNextFunctor == fWaitingFunctors.end()) bAtEnd = true; - fWaitingFunctors.push_back(func); + fWaitingFunctors.push_back(make_pair(fNextHandle, func)); waitingFunctorsSize++; if (bAtEnd) { --fNextFunctor; } + return fNextHandle++; } void ThreadPool::dump() diff --git a/utils/threadpool/threadpool.h b/utils/threadpool/threadpool.h index 23ba5df2e..a21e19c0e 100644 --- a/utils/threadpool/threadpool.h +++ b/utils/threadpool/threadpool.h @@ -60,6 +60,7 @@ class ThreadPool { public: typedef boost::function0 Functor_T; + typedef pair PoolFunction_T; /********************************************* * ctor/dtor @@ -132,7 +133,7 @@ public: * queueSize tasks already waiting, invoke() will block until a slot in the * queue comes free. */ - EXPORT void invoke(const Functor_T &threadfunc); + EXPORT int64_t invoke(const Functor_T &threadfunc); /** @brief stop the threads */ @@ -142,7 +143,11 @@ public: */ EXPORT void wait(); - /** @brief for use in debugging + /** @brief Wait for a specific thread + */ + EXPORT void join(uint64_t thrHandle); + + /** @brief for use in debugging */ EXPORT void dump(); @@ -155,7 +160,7 @@ private: /** @brief add a functor to the list */ - void addFunctor(const Functor_T &func); + int64_t addFunctor(const Functor_T &func); /** @brief thread entry point */ @@ -191,7 +196,7 @@ private: size_t fMaxThreads; size_t fQueueSize; - typedef std::list Container_T; + typedef std::list Container_T; Container_T fWaitingFunctors; Container_T::iterator fNextFunctor; // Functor_T * fThreadCreated; @@ -206,6 +211,7 @@ private: long fGeneralErrors; long fFunctorErrors; uint32_t waitingFunctorsSize; + uint64_t fNextHandle; }; From b6321935fb7c03523fde69e7f7f674c86b21bee0 Mon Sep 17 00:00:00 2001 From: David Hall Date: Wed, 1 Feb 2017 17:22:15 -0600 Subject: [PATCH 05/35] MCOL-513 fix a couple bugs in threadpool join() Add a test program --- utils/threadpool/threadpool.cpp | 45 +++++- utils/threadpool/threadpool.h | 6 +- utils/threadpool/tp.cpp | 121 ++++++++++++++++ utils/threadpool/tp.vpj | 238 ++++++++++++++++++++++++++++++++ utils/threadpool/tp.vpw | 6 + 5 files changed, 412 insertions(+), 4 deletions(-) create mode 100644 utils/threadpool/tp.cpp create mode 100644 utils/threadpool/tp.vpj create mode 100644 utils/threadpool/tp.vpw diff --git a/utils/threadpool/threadpool.cpp b/utils/threadpool/threadpool.cpp index 14aa074f6..77a3c00e0 100644 --- a/utils/threadpool/threadpool.cpp +++ b/utils/threadpool/threadpool.cpp @@ -20,7 +20,7 @@ * * ***********************************************************************/ - +#define NOLOGGING #include using namespace std; @@ -127,6 +127,7 @@ void ThreadPool::join(uint64_t thrHandle) bool foundit = false; for (iter = fWaitingFunctors.begin(); iter != end; ++iter) { + foundit = false; if (iter->first == thrHandle) { foundit = true; @@ -141,6 +142,42 @@ void ThreadPool::join(uint64_t thrHandle) } } +void ThreadPool::join(std::vector thrHandle) +{ + boost::mutex::scoped_lock lock1(fMutex); + + while (waitingFunctorsSize > 0) + { + Container_T::iterator iter; + Container_T::iterator end = fWaitingFunctors.end(); + bool foundit = false; + for (iter = fWaitingFunctors.begin(); iter != end; ++iter) + { + foundit = false; + std::vector::iterator thrIter; + std::vector::iterator thrEnd = thrHandle.end(); + for (thrIter = thrHandle.begin(); thrIter != thrEnd; ++thrIter) + { + if (iter->first == *thrIter) + { + foundit = true; + break; + } + } + if (foundit == true) + { + break; + } + } + // If we didn't find any of the handles, then all are complete + if (!foundit) + { + break; + } + fThreadAvailable.wait(lock1); + } +} + int64_t ThreadPool::invoke(const Functor_T &threadfunc) { boost::mutex::scoped_lock lock1(fMutex); @@ -276,6 +313,7 @@ void ThreadPool::beginThread() throw() // Log the exception and exit this thread try { +#ifndef NOLOGGING logging::Message::Args args; logging::Message message(5); args.add("beginThread: Caught exception: "); @@ -287,7 +325,7 @@ void ThreadPool::beginThread() throw() logging::MessageLog ml(lid); ml.logErrorMessage( message ); - +#endif } catch(...) { @@ -302,6 +340,7 @@ void ThreadPool::beginThread() throw() // Log the exception and exit this thread try { +#ifndef NOLOGGING logging::Message::Args args; logging::Message message(6); args.add("beginThread: Caught unknown exception!"); @@ -312,7 +351,7 @@ void ThreadPool::beginThread() throw() logging::MessageLog ml(lid); ml.logErrorMessage( message ); - +#endif } catch(...) { diff --git a/utils/threadpool/threadpool.h b/utils/threadpool/threadpool.h index a21e19c0e..a14a6e4fb 100644 --- a/utils/threadpool/threadpool.h +++ b/utils/threadpool/threadpool.h @@ -147,7 +147,11 @@ public: */ EXPORT void join(uint64_t thrHandle); - /** @brief for use in debugging + /** @brief Wait for a specific thread + */ + EXPORT void join(std::vector thrHandle); + + /** @brief for use in debugging */ EXPORT void dump(); diff --git a/utils/threadpool/tp.cpp b/utils/threadpool/tp.cpp new file mode 100644 index 000000000..92eaeeae7 --- /dev/null +++ b/utils/threadpool/tp.cpp @@ -0,0 +1,121 @@ +/* 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. */ + + +#include +#include +#include +#include +using namespace std; +#include +#include +#include +#include +#include +#include +#include +#include "threadpool.h" + +int64_t thecount = 0; +boost::mutex mutex; + +const string timeNow() +{ + time_t outputTime = time(0); + struct tm ltm; + char buf[32]; //ctime(3) says at least 26 + size_t len = 0; +#ifdef _MSC_VER + asctime_s(buf, 32, localtime_r(&outputTime, <m)); +#else + asctime_r(localtime_r(&outputTime, <m), buf); +#endif + len = strlen(buf); + if (len > 0) --len; + if (buf[len] == '\n') buf[len] = 0; + return buf; +} + +// Functor class +struct foo +{ + int64_t fData; + int64_t fThd; + string start; + + void operator ()() + { + start = timeNow(); + + std::cout << "foo thd = " << fThd << " start " << start << std::endl; + for (int64_t i = 0; i < 1024*1024*fThd*128; i++) + // simulate some work + fData++; + + boost::mutex::scoped_lock lock(mutex); + std::cout << "foo thd = " << fThd << " start " << start << " fin " << timeNow() << std::endl; + } + + foo(int64_t i) : fThd(i), fData(i) {start=timeNow();} + + foo(const foo& copy) : fData(copy.fData), fThd(copy.fThd), start(copy.start) {std::cout << "new foo" << endl;} + + ~foo() {} +}; + + + +int main( int argc, char **argv) +{ + threadpool::ThreadPool pool( 20, 10 ); + std::vector hndl; + hndl.reserve(10); + int t1 = hndl.capacity(); + uint64_t testHndl; + uint64_t thdhndl=999; + for (int64_t y = 0; y < 20; y++) + { + foo bar(y); +// for (int64_t i = 0; i < 10; ++i) + { + thdhndl = pool.invoke(bar); + if (y<10) + { + hndl.push_back(thdhndl); + } + if (y == 0) + { + testHndl = thdhndl; + } + } + + boost::mutex::scoped_lock lock(mutex); + } + // Wait until all of the queued up and in-progress work has finished + std::cout << "Threads for join " << hndl.size() << std::endl; + pool.dump(); + std::cout << "*** JOIN 1 ***" << std::endl; + pool.join(testHndl); + pool.dump(); + std::cout << "*** JOIN 10 ***" << std::endl; + pool.join(hndl); + pool.dump(); + std::cout << "*** WAIT ***" << std::endl; + pool.wait(); + pool.dump(); + return 0; +} diff --git a/utils/threadpool/tp.vpj b/utils/threadpool/tp.vpj new file mode 100644 index 000000000..bffc57e50 --- /dev/null +++ b/utils/threadpool/tp.vpj @@ -0,0 +1,238 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/utils/threadpool/tp.vpw b/utils/threadpool/tp.vpw new file mode 100644 index 000000000..c15af49c7 --- /dev/null +++ b/utils/threadpool/tp.vpw @@ -0,0 +1,6 @@ + + + + + + From 94b9d8aed2ecd2373aeafa0ffe14ab6ff1fa8e74 Mon Sep 17 00:00:00 2001 From: David Hall Date: Thu, 2 Feb 2017 11:45:04 -0600 Subject: [PATCH 06/35] MCOL-513 Optimize by replacing make_pair with a struct --- utils/threadpool/threadpool.cpp | 13 ++++++++----- utils/threadpool/threadpool.h | 15 ++++++++++----- utils/threadpool/tp.cpp | 21 +++++++++++++++------ utils/threadpool/tp.vpj | 6 ++++-- 4 files changed, 37 insertions(+), 18 deletions(-) diff --git a/utils/threadpool/threadpool.cpp b/utils/threadpool/threadpool.cpp index 77a3c00e0..d4ea02565 100644 --- a/utils/threadpool/threadpool.cpp +++ b/utils/threadpool/threadpool.cpp @@ -20,7 +20,6 @@ * * ***********************************************************************/ -#define NOLOGGING #include using namespace std; @@ -128,7 +127,7 @@ void ThreadPool::join(uint64_t thrHandle) for (iter = fWaitingFunctors.begin(); iter != end; ++iter) { foundit = false; - if (iter->first == thrHandle) + if (iter->hndl == thrHandle) { foundit = true; break; @@ -158,7 +157,7 @@ void ThreadPool::join(std::vector thrHandle) std::vector::iterator thrEnd = thrHandle.end(); for (thrIter = thrHandle.begin(); thrIter != thrEnd; ++thrIter) { - if (iter->first == *thrIter) + if (iter->hndl == *thrIter) { foundit = true; break; @@ -282,7 +281,7 @@ void ThreadPool::beginThread() throw() for (i = 0; i < num; i++) { try { - (*todoList[i]).second(); + (*todoList[i]).functor(); } catch(exception &e) { ++fFunctorErrors; @@ -366,7 +365,11 @@ int64_t ThreadPool::addFunctor(const Functor_T &func) if (fNextFunctor == fWaitingFunctors.end()) bAtEnd = true; - fWaitingFunctors.push_back(make_pair(fNextHandle, func)); +// PoolFunction_T poolFunction(fNextHandle, func); + PoolFunction_T poolFunction; + poolFunction.hndl = fNextHandle; + poolFunction.functor = func; + fWaitingFunctors.push_back(poolFunction); waitingFunctorsSize++; if (bAtEnd) { diff --git a/utils/threadpool/threadpool.h b/utils/threadpool/threadpool.h index a14a6e4fb..dd5f13b56 100644 --- a/utils/threadpool/threadpool.h +++ b/utils/threadpool/threadpool.h @@ -55,12 +55,10 @@ namespace threadpool * executing tasks. It is responsible for creating threads and tracking which threads are "busy" * and which are idle. Idle threads are utilized as "work" is added to the system. */ - class ThreadPool { public: typedef boost::function0 Functor_T; - typedef pair PoolFunction_T; /********************************************* * ctor/dtor @@ -158,6 +156,13 @@ public: protected: private: + // Used internally to keep a handle associated with each functor for join() + struct PoolFunction_T + { + int64_t hndl; + Functor_T functor; + }; + /** @brief initialize data memebers */ void init(); @@ -193,8 +198,8 @@ private: struct NoOp { void operator () () const - {}} - ; + {} + }; size_t fThreadCount; size_t fMaxThreads; @@ -205,7 +210,7 @@ private: Container_T::iterator fNextFunctor; // Functor_T * fThreadCreated; - uint32_t issued; + uint32_t issued; boost::mutex fMutex; boost::condition fThreadAvailable; // triggered when a thread is available boost::condition fNeedThread; // triggered when a thread is needed diff --git a/utils/threadpool/tp.cpp b/utils/threadpool/tp.cpp index 92eaeeae7..ec128a28e 100644 --- a/utils/threadpool/tp.cpp +++ b/utils/threadpool/tp.cpp @@ -56,13 +56,14 @@ struct foo int64_t fData; int64_t fThd; string start; + bool running; void operator ()() { start = timeNow(); std::cout << "foo thd = " << fThd << " start " << start << std::endl; - for (int64_t i = 0; i < 1024*1024*fThd*128; i++) + for (int64_t i = 0; i < 1024*1024*(fThd+0)*128; i++) // simulate some work fData++; @@ -70,11 +71,11 @@ struct foo std::cout << "foo thd = " << fThd << " start " << start << " fin " << timeNow() << std::endl; } - foo(int64_t i) : fThd(i), fData(i) {start=timeNow();} + foo(int64_t i) : fThd(i), fData(i), running(true) {start=timeNow();} - foo(const foo& copy) : fData(copy.fData), fThd(copy.fThd), start(copy.start) {std::cout << "new foo" << endl;} + foo(const foo& copy) : fData(copy.fData), fThd(copy.fThd), start(copy.start), running(copy.running) {std::cout << "new foo " << fThd << endl;} - ~foo() {} + ~foo() {running=false;} }; @@ -87,11 +88,18 @@ int main( int argc, char **argv) int t1 = hndl.capacity(); uint64_t testHndl; uint64_t thdhndl=999; - for (int64_t y = 0; y < 20; y++) + int64_t thd = 1; + boost::function0 foofunc; + boost::function0 foofunc2; + for (int64_t y = 0; y < 1; y++) { foo bar(y); -// for (int64_t i = 0; i < 10; ++i) +// foofunc = bar; +// foofunc2 = foofunc; + std::cout << "Done with assign" << std::endl; + for (int64_t i = 0; i < 1; ++i) { + bar.fThd=thd++; thdhndl = pool.invoke(bar); if (y<10) { @@ -117,5 +125,6 @@ int main( int argc, char **argv) std::cout << "*** WAIT ***" << std::endl; pool.wait(); pool.dump(); + sleep(2); return 0; } diff --git a/utils/threadpool/tp.vpj b/utils/threadpool/tp.vpj index bffc57e50..a8f1497cb 100644 --- a/utils/threadpool/tp.vpj +++ b/utils/threadpool/tp.vpj @@ -11,7 +11,8 @@ DebugCallbackName="gdb" Version="1" OutputFile="%bdtp" - CompilerConfigName="Latest Version"> + CompilerConfigName="Latest Version" + Defines='"/DNOLOGGING"'> + CompilerConfigName="Latest Version" + Defines='"/DNOLOGGING"'> Date: Tue, 17 Jan 2017 14:52:06 +0000 Subject: [PATCH 07/35] MCOL-318 Use OS version of Snappy This patch strips out our old version of Snappy and uses the OS version instead. All our supported OSes have the latest version of Snappy in their base repositories. --- CMakeLists.txt | 5 + FindSnappy.cmake | 44 + utils/compress/CMakeLists.txt | 9 +- utils/compress/snappy-config-win.h | 125 --- utils/compress/snappy-config.h | 125 --- utils/compress/snappy-internal.h | 150 --- utils/compress/snappy-sinksource.cpp | 71 -- utils/compress/snappy-sinksource.h | 137 --- utils/compress/snappy-stubs-internal.cpp | 42 - utils/compress/snappy-stubs-internal.h | 494 -------- utils/compress/snappy-stubs-public.h | 98 -- utils/compress/snappy.cpp | 1306 ---------------------- utils/compress/snappy.h | 184 --- 13 files changed, 53 insertions(+), 2737 deletions(-) create mode 100644 FindSnappy.cmake delete mode 100644 utils/compress/snappy-config-win.h delete mode 100644 utils/compress/snappy-config.h delete mode 100644 utils/compress/snappy-internal.h delete mode 100644 utils/compress/snappy-sinksource.cpp delete mode 100644 utils/compress/snappy-sinksource.h delete mode 100644 utils/compress/snappy-stubs-internal.cpp delete mode 100644 utils/compress/snappy-stubs-internal.h delete mode 100644 utils/compress/snappy-stubs-public.h delete mode 100644 utils/compress/snappy.cpp delete mode 100644 utils/compress/snappy.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 2062f9aaf..e5e8a96cc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -91,6 +91,11 @@ if (NOT LIBXML2_FOUND) MESSAGE(FATAL_ERROR "Could not find a usable libxml2 development environment!") endif() +INCLUDE (FindSnappy.cmake) +if (NOT SNAPPY_FOUND) + MESSAGE(FATAL_ERROR "Snappy not found please install snappy-devel for CentOS/RedHat or libsnappy-dev for Ubuntu/Debian") +endif() + FIND_PROGRAM(AWK_EXECUTABLE awk DOC "path to the awk executable") if(NOT AWK_EXECUTABLE) message(FATAL_ERROR "awk not found!") diff --git a/FindSnappy.cmake b/FindSnappy.cmake new file mode 100644 index 000000000..7ac14a271 --- /dev/null +++ b/FindSnappy.cmake @@ -0,0 +1,44 @@ +# - Try to find snappy headers and libraries. +# +# Usage of this module as follows: +# +# find_package(Snappy) +# +# Variables used by this module, they can change the default behaviour and need +# to be set before calling find_package: +# +# SNAPPY_ROOT_DIR Set this variable to the root installation of +# jemalloc if the module has problems finding +# the proper installation path. +# +# Variables defined by this module: +# +# SNAPPY_FOUND System has snappy libs/headers +# SNAPPY_LIBRARIES The snappy library/libraries +# SNAPPY_INCLUDE_DIR The location of snappy headers + +find_path(SNAPPY_ROOT_DIR + NAMES include/snappy.h +) + +find_library(SNAPPY_LIBRARIES + NAMES snappy + HINTS ${SNAPPY_ROOT_DIR}/lib +) + +find_path(SNAPPY_INCLUDE_DIR + NAMES snappy.h + HINTS ${JEMALLOC_ROOT_DIR}/include +) + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(Snappy DEFAULT_MSG + SNAPPY_LIBRARIES + SNAPPY_INCLUDE_DIR +) + +mark_as_advanced( + SNAPPY_ROOT_DIR + SNAPPY_LIBRARIES + SNAPPY_INCLUDE_DIR +) diff --git a/utils/compress/CMakeLists.txt b/utils/compress/CMakeLists.txt index 543f6cff9..3d3e5be26 100644 --- a/utils/compress/CMakeLists.txt +++ b/utils/compress/CMakeLists.txt @@ -1,19 +1,18 @@ -include_directories( ${ENGINE_COMMON_INCLUDES} ) +include_directories( ${ENGINE_COMMON_INCLUDES} ${SNAPPY_INCLUDE_DIR} ) ########### next target ############### set(compress_LIB_SRCS idbcompress.cpp - snappy.cpp - snappy-sinksource.cpp - version1.cpp - snappy-stubs-internal.cpp) + version1.cpp) add_definitions(-DNDEBUG) add_library(compress SHARED ${compress_LIB_SRCS}) +target_link_libraries(compress ${SNAPPY_LIBRARIES}) + set_target_properties(compress PROPERTIES VERSION 1.0.0 SOVERSION 1) install(TARGETS compress DESTINATION ${ENGINE_LIBDIR} COMPONENT libs) diff --git a/utils/compress/snappy-config-win.h b/utils/compress/snappy-config-win.h deleted file mode 100644 index 34ed55051..000000000 --- a/utils/compress/snappy-config-win.h +++ /dev/null @@ -1,125 +0,0 @@ -/* config.h. Generated from config.h.in by configure. */ -/* config.h.in. Generated from configure.ac by autoheader. */ - -/* Define to 1 if the compiler supports __builtin_ctz and friends. */ -/* #undef HAVE_BUILTIN_CTZ 1 */ - -/* Define to 1 if the compiler supports __builtin_expect. */ -/* #define HAVE_BUILTIN_EXPECT 1 */ - -/* Define to 1 if you have the header file. */ -/* #undef HAVE_BYTESWAP_H 1 */ - -/* Define to 1 if you have the header file. */ -/* #undef HAVE_DLFCN_H 1 */ - -/* Use the gflags package for command-line parsing. */ -/* #undef HAVE_GFLAGS */ - -/* Defined when Google Test is available. */ -/* #undef HAVE_GTEST */ - -/* Define to 1 if you have the header file. */ -/* #undef HAVE_INTTYPES_H 1 */ - -/* Define to 1 if you have the `fastlz' library (-lfastlz). */ -/* #undef HAVE_LIBFASTLZ */ - -/* Define to 1 if you have the `lzf' library (-llzf). */ -/* #undef HAVE_LIBLZF */ - -/* Define to 1 if you have the `lzo2' library (-llzo2). */ -/* #undef HAVE_LIBLZO2 */ - -/* Define to 1 if you have the `quicklz' library (-lquicklz). */ -/* #undef HAVE_LIBQUICKLZ */ - -/* Define to 1 if you have the `z' library (-lz). */ -/* #undef HAVE_LIBZ 1 */ - -/* Define to 1 if you have the header file. */ -#define HAVE_MEMORY_H 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_STDDEF_H 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_STDINT_H 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_STDLIB_H 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_STRINGS_H 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_STRING_H 1 - -/* Define to 1 if you have the header file. */ -/* #undef HAVE_SYS_BYTESWAP_H */ - -/* Define to 1 if you have the header file. */ -/* #undef HAVE_SYS_ENDIAN_H */ - -/* Define to 1 if you have the header file. */ -/* #undef HAVE_SYS_MMAN_H 1 */ - -/* Define to 1 if you have the header file. */ -/* #undef HAVE_SYS_RESOURCE_H 1 */ - -/* Define to 1 if you have the header file. */ -#define HAVE_SYS_STAT_H 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_SYS_TIME_H 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_SYS_TYPES_H 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_UNISTD_H 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_WINDOWS_H - -/* Define to the sub-directory in which libtool stores uninstalled libraries. - */ -#define LT_OBJDIR ".libs/" - -/* Name of package */ -#define PACKAGE "snappy" - -/* Define to the address where bug reports for this package should be sent. */ -#define PACKAGE_BUGREPORT "" - -/* Define to the full name of this package. */ -#define PACKAGE_NAME "snappy" - -/* Define to the full name and version of this package. */ -#define PACKAGE_STRING "snappy 1.1.1" - -/* Define to the one symbol short name of this package. */ -#define PACKAGE_TARNAME "snappy" - -/* Define to the version of this package. */ -#define PACKAGE_VERSION "1.1.1" - -/* Define to 1 if you have the ANSI C header files. */ -#define STDC_HEADERS 1 - -/* Version number of package */ -#define VERSION "1.1.1" - -/* Define WORDS_BIGENDIAN to 1 if your processor stores words with the most - significant byte first (like Motorola and SPARC, unlike Intel and VAX). */ -#if defined __BIG_ENDIAN__ -# define WORDS_BIGENDIAN 1 -#elif ! defined __LITTLE_ENDIAN__ -/* # undef WORDS_BIGENDIAN */ -#endif - -/* Define to `unsigned int' if does not define. */ -/* #undef size_t */ - -/* Define to `int' if does not define. */ -/* #undef ssize_t */ diff --git a/utils/compress/snappy-config.h b/utils/compress/snappy-config.h deleted file mode 100644 index ff7ab82eb..000000000 --- a/utils/compress/snappy-config.h +++ /dev/null @@ -1,125 +0,0 @@ -/* config.h. Generated from config.h.in by configure. */ -/* config.h.in. Generated from configure.ac by autoheader. */ - -/* Define to 1 if the compiler supports __builtin_ctz and friends. */ -#define HAVE_BUILTIN_CTZ 1 - -/* Define to 1 if the compiler supports __builtin_expect. */ -#define HAVE_BUILTIN_EXPECT 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_BYTESWAP_H 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_DLFCN_H 1 - -/* Use the gflags package for command-line parsing. */ -/* #undef HAVE_GFLAGS */ - -/* Defined when Google Test is available. */ -/* #undef HAVE_GTEST */ - -/* Define to 1 if you have the header file. */ -#define HAVE_INTTYPES_H 1 - -/* Define to 1 if you have the `fastlz' library (-lfastlz). */ -/* #undef HAVE_LIBFASTLZ */ - -/* Define to 1 if you have the `lzf' library (-llzf). */ -/* #undef HAVE_LIBLZF */ - -/* Define to 1 if you have the `lzo2' library (-llzo2). */ -/* #undef HAVE_LIBLZO2 */ - -/* Define to 1 if you have the `quicklz' library (-lquicklz). */ -/* #undef HAVE_LIBQUICKLZ */ - -/* Define to 1 if you have the `z' library (-lz). */ -#define HAVE_LIBZ 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_MEMORY_H 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_STDDEF_H 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_STDINT_H 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_STDLIB_H 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_STRINGS_H 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_STRING_H 1 - -/* Define to 1 if you have the header file. */ -/* #undef HAVE_SYS_BYTESWAP_H */ - -/* Define to 1 if you have the header file. */ -/* #undef HAVE_SYS_ENDIAN_H */ - -/* Define to 1 if you have the header file. */ -#define HAVE_SYS_MMAN_H 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_SYS_RESOURCE_H 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_SYS_STAT_H 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_SYS_TIME_H 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_SYS_TYPES_H 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_UNISTD_H 1 - -/* Define to 1 if you have the header file. */ -/* #undef HAVE_WINDOWS_H */ - -/* Define to the sub-directory in which libtool stores uninstalled libraries. - */ -#define LT_OBJDIR ".libs/" - -/* Name of package */ -#define PACKAGE "snappy" - -/* Define to the address where bug reports for this package should be sent. */ -#define PACKAGE_BUGREPORT "" - -/* Define to the full name of this package. */ -#define PACKAGE_NAME "snappy" - -/* Define to the full name and version of this package. */ -#define PACKAGE_STRING "snappy 1.1.1" - -/* Define to the one symbol short name of this package. */ -#define PACKAGE_TARNAME "snappy" - -/* Define to the version of this package. */ -#define PACKAGE_VERSION "1.1.1" - -/* Define to 1 if you have the ANSI C header files. */ -#define STDC_HEADERS 1 - -/* Version number of package */ -#define VERSION "1.1.1" - -/* Define WORDS_BIGENDIAN to 1 if your processor stores words with the most - significant byte first (like Motorola and SPARC, unlike Intel and VAX). */ -#if defined __BIG_ENDIAN__ -# define WORDS_BIGENDIAN 1 -#elif ! defined __LITTLE_ENDIAN__ -/* # undef WORDS_BIGENDIAN */ -#endif - -/* Define to `unsigned int' if does not define. */ -/* #undef size_t */ - -/* Define to `int' if does not define. */ -/* #undef ssize_t */ diff --git a/utils/compress/snappy-internal.h b/utils/compress/snappy-internal.h deleted file mode 100644 index c99d33130..000000000 --- a/utils/compress/snappy-internal.h +++ /dev/null @@ -1,150 +0,0 @@ -// Copyright 2008 Google Inc. All Rights Reserved. -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -// -// Internals shared between the Snappy implementation and its unittest. - -#ifndef UTIL_SNAPPY_SNAPPY_INTERNAL_H_ -#define UTIL_SNAPPY_SNAPPY_INTERNAL_H_ - -#include "snappy-stubs-internal.h" - -namespace snappy { -namespace internal { - -class WorkingMemory { - public: - WorkingMemory() : large_table_(NULL) { } - ~WorkingMemory() { delete[] large_table_; } - - // Allocates and clears a hash table using memory in "*this", - // stores the number of buckets in "*table_size" and returns a pointer to - // the base of the hash table. - uint16* GetHashTable(size_t input_size, int* table_size); - - private: - uint16 small_table_[1<<10]; // 2KB - uint16* large_table_; // Allocated only when needed - - DISALLOW_COPY_AND_ASSIGN(WorkingMemory); -}; - -// Flat array compression that does not emit the "uncompressed length" -// prefix. Compresses "input" string to the "*op" buffer. -// -// REQUIRES: "input_length <= kBlockSize" -// REQUIRES: "op" points to an array of memory that is at least -// "MaxCompressedLength(input_length)" in size. -// REQUIRES: All elements in "table[0..table_size-1]" are initialized to zero. -// REQUIRES: "table_size" is a power of two -// -// Returns an "end" pointer into "op" buffer. -// "end - op" is the compressed size of "input". -char* CompressFragment(const char* input, - size_t input_length, - char* op, - uint16* table, - const int table_size); - -// Return the largest n such that -// -// s1[0,n-1] == s2[0,n-1] -// and n <= (s2_limit - s2). -// -// Does not read *s2_limit or beyond. -// Does not read *(s1 + (s2_limit - s2)) or beyond. -// Requires that s2_limit >= s2. -// -// Separate implementation for x86_64, for speed. Uses the fact that -// x86_64 is little endian. -#if defined(ARCH_K8) -static inline int FindMatchLength(const char* s1, - const char* s2, - const char* s2_limit) { - assert(s2_limit >= s2); - int matched = 0; - - // Find out how long the match is. We loop over the data 64 bits at a - // time until we find a 64-bit block that doesn't match; then we find - // the first non-matching bit and use that to calculate the total - // length of the match. - while (PREDICT_TRUE(s2 <= s2_limit - 8)) { - if (PREDICT_FALSE(UNALIGNED_LOAD64(s2) == UNALIGNED_LOAD64(s1 + matched))) { - s2 += 8; - matched += 8; - } else { - // On current (mid-2008) Opteron models there is a 3% more - // efficient code sequence to find the first non-matching byte. - // However, what follows is ~10% better on Intel Core 2 and newer, - // and we expect AMD's bsf instruction to improve. - uint64 x = UNALIGNED_LOAD64(s2) ^ UNALIGNED_LOAD64(s1 + matched); - int matching_bits = Bits::FindLSBSetNonZero64(x); - matched += matching_bits >> 3; - return matched; - } - } - while (PREDICT_TRUE(s2 < s2_limit)) { - if (PREDICT_TRUE(s1[matched] == *s2)) { - ++s2; - ++matched; - } else { - return matched; - } - } - return matched; -} -#else -static inline int FindMatchLength(const char* s1, - const char* s2, - const char* s2_limit) { - // Implementation based on the x86-64 version, above. - assert(s2_limit >= s2); - int matched = 0; - - while (s2 <= s2_limit - 4 && - UNALIGNED_LOAD32(s2) == UNALIGNED_LOAD32(s1 + matched)) { - s2 += 4; - matched += 4; - } - if (LittleEndian::IsLittleEndian() && s2 <= s2_limit - 4) { - uint32 x = UNALIGNED_LOAD32(s2) ^ UNALIGNED_LOAD32(s1 + matched); - int matching_bits = Bits::FindLSBSetNonZero(x); - matched += matching_bits >> 3; - } else { - while ((s2 < s2_limit) && (s1[matched] == *s2)) { - ++s2; - ++matched; - } - } - return matched; -} -#endif - -} // end namespace internal -} // end namespace snappy - -#endif // UTIL_SNAPPY_SNAPPY_INTERNAL_H_ diff --git a/utils/compress/snappy-sinksource.cpp b/utils/compress/snappy-sinksource.cpp deleted file mode 100644 index 5844552cb..000000000 --- a/utils/compress/snappy-sinksource.cpp +++ /dev/null @@ -1,71 +0,0 @@ -// Copyright 2011 Google Inc. All Rights Reserved. -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -#include - -#include "snappy-sinksource.h" - -namespace snappy { - -Source::~Source() { } - -Sink::~Sink() { } - -char* Sink::GetAppendBuffer(size_t length, char* scratch) { - return scratch; -} - -ByteArraySource::~ByteArraySource() { } - -size_t ByteArraySource::Available() const { return left_; } - -const char* ByteArraySource::Peek(size_t* len) { - *len = left_; - return ptr_; -} - -void ByteArraySource::Skip(size_t n) { - left_ -= n; - ptr_ += n; -} - -UncheckedByteArraySink::~UncheckedByteArraySink() { } - -void UncheckedByteArraySink::Append(const char* data, size_t n) { - // Do no copying if the caller filled in the result of GetAppendBuffer() - if (data != dest_) { - memcpy(dest_, data, n); - } - dest_ += n; -} - -char* UncheckedByteArraySink::GetAppendBuffer(size_t len, char* scratch) { - return dest_; -} - -} diff --git a/utils/compress/snappy-sinksource.h b/utils/compress/snappy-sinksource.h deleted file mode 100644 index faabfa1e6..000000000 --- a/utils/compress/snappy-sinksource.h +++ /dev/null @@ -1,137 +0,0 @@ -// Copyright 2011 Google Inc. All Rights Reserved. -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -#ifndef UTIL_SNAPPY_SNAPPY_SINKSOURCE_H_ -#define UTIL_SNAPPY_SNAPPY_SINKSOURCE_H_ - -#include - - -namespace snappy { - -// A Sink is an interface that consumes a sequence of bytes. -class Sink { - public: - Sink() { } - virtual ~Sink(); - - // Append "bytes[0,n-1]" to this. - virtual void Append(const char* bytes, size_t n) = 0; - - // Returns a writable buffer of the specified length for appending. - // May return a pointer to the caller-owned scratch buffer which - // must have at least the indicated length. The returned buffer is - // only valid until the next operation on this Sink. - // - // After writing at most "length" bytes, call Append() with the - // pointer returned from this function and the number of bytes - // written. Many Append() implementations will avoid copying - // bytes if this function returned an internal buffer. - // - // If a non-scratch buffer is returned, the caller may only pass a - // prefix of it to Append(). That is, it is not correct to pass an - // interior pointer of the returned array to Append(). - // - // The default implementation always returns the scratch buffer. - virtual char* GetAppendBuffer(size_t length, char* scratch); - - - private: - // No copying - Sink(const Sink&); - void operator=(const Sink&); -}; - -// A Source is an interface that yields a sequence of bytes -class Source { - public: - Source() { } - virtual ~Source(); - - // Return the number of bytes left to read from the source - virtual size_t Available() const = 0; - - // Peek at the next flat region of the source. Does not reposition - // the source. The returned region is empty iff Available()==0. - // - // Returns a pointer to the beginning of the region and store its - // length in *len. - // - // The returned region is valid until the next call to Skip() or - // until this object is destroyed, whichever occurs first. - // - // The returned region may be larger than Available() (for example - // if this ByteSource is a view on a substring of a larger source). - // The caller is responsible for ensuring that it only reads the - // Available() bytes. - virtual const char* Peek(size_t* len) = 0; - - // Skip the next n bytes. Invalidates any buffer returned by - // a previous call to Peek(). - // REQUIRES: Available() >= n - virtual void Skip(size_t n) = 0; - - private: - // No copying - Source(const Source&); - void operator=(const Source&); -}; - -// A Source implementation that yields the contents of a flat array -class ByteArraySource : public Source { - public: - ByteArraySource(const char* p, size_t n) : ptr_(p), left_(n) { } - virtual ~ByteArraySource(); - virtual size_t Available() const; - virtual const char* Peek(size_t* len); - virtual void Skip(size_t n); - private: - const char* ptr_; - size_t left_; -}; - -// A Sink implementation that writes to a flat array without any bound checks. -class UncheckedByteArraySink : public Sink { - public: - explicit UncheckedByteArraySink(char* dest) : dest_(dest) { } - virtual ~UncheckedByteArraySink(); - virtual void Append(const char* data, size_t n); - virtual char* GetAppendBuffer(size_t len, char* scratch); - - // Return the current output pointer so that a caller can see how - // many bytes were produced. - // Note: this is not a Sink method. - char* CurrentDestination() const { return dest_; } - private: - char* dest_; -}; - - -} - -#endif // UTIL_SNAPPY_SNAPPY_SINKSOURCE_H_ diff --git a/utils/compress/snappy-stubs-internal.cpp b/utils/compress/snappy-stubs-internal.cpp deleted file mode 100644 index 6ed334371..000000000 --- a/utils/compress/snappy-stubs-internal.cpp +++ /dev/null @@ -1,42 +0,0 @@ -// Copyright 2011 Google Inc. All Rights Reserved. -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -#include -#include - -#include "snappy-stubs-internal.h" - -namespace snappy { - -void Varint::Append32(string* s, uint32 value) { - char buf[Varint::kMax32]; - const char* p = Varint::Encode32(buf, value); - s->append(buf, p - buf); -} - -} // namespace snappy diff --git a/utils/compress/snappy-stubs-internal.h b/utils/compress/snappy-stubs-internal.h deleted file mode 100644 index 6d047d97c..000000000 --- a/utils/compress/snappy-stubs-internal.h +++ /dev/null @@ -1,494 +0,0 @@ -// Copyright 2011 Google Inc. All Rights Reserved. -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -// -// Various stubs for the open-source version of Snappy. - -#ifndef UTIL_SNAPPY_OPENSOURCE_SNAPPY_STUBS_INTERNAL_H_ -#define UTIL_SNAPPY_OPENSOURCE_SNAPPY_STUBS_INTERNAL_H_ - -#ifdef _MSC_VER -#include -#include "snappy-config-win.h" -#else -#include "snappy-config.h" -#endif - -#include - -#include -#include -#include - -#ifdef HAVE_SYS_MMAN_H -#include -#endif - -#include "snappy-stubs-public.h" - -#if defined(__x86_64__) - -// Enable 64-bit optimized versions of some routines. -#define ARCH_K8 1 - -#endif - -// Needed by OS X, among others. -#ifndef MAP_ANONYMOUS -#define MAP_ANONYMOUS MAP_ANON -#endif - -// Pull in std::min, std::ostream, and the likes. This is safe because this -// header file is never used from any public header files. -using namespace std; - -// The size of an array, if known at compile-time. -// Will give unexpected results if used on a pointer. -// We undefine it first, since some compilers already have a definition. -#ifdef ARRAYSIZE -#undef ARRAYSIZE -#endif -#define ARRAYSIZE(a) (sizeof(a) / sizeof(*(a))) - -// Static prediction hints. -#ifdef HAVE_BUILTIN_EXPECT -#define PREDICT_FALSE(x) (__builtin_expect(x, 0)) -#define PREDICT_TRUE(x) (__builtin_expect(!!(x), 1)) -#else -#define PREDICT_FALSE(x) x -#define PREDICT_TRUE(x) x -#endif - -// This is only used for recomputing the tag byte table used during -// decompression; for simplicity we just remove it from the open-source -// version (anyone who wants to regenerate it can just do the call -// themselves within main()). -#define DEFINE_bool(flag_name, default_value, description) \ - bool FLAGS_ ## flag_name = default_value -#define DECLARE_bool(flag_name) \ - extern bool FLAGS_ ## flag_name - -namespace snappy { - -static const uint32 kuint32max = static_cast(0xFFFFFFFF); -static const int64 kint64max = static_cast(0x7FFFFFFFFFFFFFFFLL); - -// Potentially unaligned loads and stores. - -// x86 and PowerPC can simply do these loads and stores native. - -#if defined(__i386__) || defined(__x86_64__) || defined(__powerpc__) - -#define UNALIGNED_LOAD16(_p) (*reinterpret_cast(_p)) -#define UNALIGNED_LOAD32(_p) (*reinterpret_cast(_p)) -#define UNALIGNED_LOAD64(_p) (*reinterpret_cast(_p)) - -#define UNALIGNED_STORE16(_p, _val) (*reinterpret_cast(_p) = (_val)) -#define UNALIGNED_STORE32(_p, _val) (*reinterpret_cast(_p) = (_val)) -#define UNALIGNED_STORE64(_p, _val) (*reinterpret_cast(_p) = (_val)) - -// ARMv7 and newer support native unaligned accesses, but only of 16-bit -// and 32-bit values (not 64-bit); older versions either raise a fatal signal, -// do an unaligned read and rotate the words around a bit, or do the reads very -// slowly (trip through kernel mode). There's no simple #define that says just -// “ARMv7 or higher”, so we have to filter away all ARMv5 and ARMv6 -// sub-architectures. -// -// This is a mess, but there's not much we can do about it. - -#elif defined(__arm__) && \ - !defined(__ARM_ARCH_4__) && \ - !defined(__ARM_ARCH_4T__) && \ - !defined(__ARM_ARCH_5__) && \ - !defined(__ARM_ARCH_5T__) && \ - !defined(__ARM_ARCH_5TE__) && \ - !defined(__ARM_ARCH_5TEJ__) && \ - !defined(__ARM_ARCH_6__) && \ - !defined(__ARM_ARCH_6J__) && \ - !defined(__ARM_ARCH_6K__) && \ - !defined(__ARM_ARCH_6Z__) && \ - !defined(__ARM_ARCH_6ZK__) && \ - !defined(__ARM_ARCH_6T2__) - -#define UNALIGNED_LOAD16(_p) (*reinterpret_cast(_p)) -#define UNALIGNED_LOAD32(_p) (*reinterpret_cast(_p)) - -#define UNALIGNED_STORE16(_p, _val) (*reinterpret_cast(_p) = (_val)) -#define UNALIGNED_STORE32(_p, _val) (*reinterpret_cast(_p) = (_val)) - -// TODO(user): NEON supports unaligned 64-bit loads and stores. -// See if that would be more efficient on platforms supporting it, -// at least for copies. - -inline uint64 UNALIGNED_LOAD64(const void *p) { - uint64 t; - memcpy(&t, p, sizeof t); - return t; -} - -inline void UNALIGNED_STORE64(void *p, uint64 v) { - memcpy(p, &v, sizeof v); -} - -#else - -// These functions are provided for architectures that don't support -// unaligned loads and stores. - -inline uint16 UNALIGNED_LOAD16(const void *p) { - uint16 t; - memcpy(&t, p, sizeof t); - return t; -} - -inline uint32 UNALIGNED_LOAD32(const void *p) { - uint32 t; - memcpy(&t, p, sizeof t); - return t; -} - -inline uint64 UNALIGNED_LOAD64(const void *p) { - uint64 t; - memcpy(&t, p, sizeof t); - return t; -} - -inline void UNALIGNED_STORE16(void *p, uint16 v) { - memcpy(p, &v, sizeof v); -} - -inline void UNALIGNED_STORE32(void *p, uint32 v) { - memcpy(p, &v, sizeof v); -} - -inline void UNALIGNED_STORE64(void *p, uint64 v) { - memcpy(p, &v, sizeof v); -} - -#endif - -// This can be more efficient than UNALIGNED_LOAD64 + UNALIGNED_STORE64 -// on some platforms, in particular ARM. -inline void UnalignedCopy64(const void *src, void *dst) { - if (sizeof(void *) == 8) { - UNALIGNED_STORE64(dst, UNALIGNED_LOAD64(src)); - } else { - const char *src_char = reinterpret_cast(src); - char *dst_char = reinterpret_cast(dst); - - UNALIGNED_STORE32(dst_char, UNALIGNED_LOAD32(src_char)); - UNALIGNED_STORE32(dst_char + 4, UNALIGNED_LOAD32(src_char + 4)); - } -} - -// The following guarantees declaration of the byte swap functions. -#ifdef WORDS_BIGENDIAN - -#ifdef HAVE_SYS_BYTEORDER_H -#include -#endif - -#ifdef HAVE_SYS_ENDIAN_H -#include -#endif - -#ifdef _MSC_VER -#include -#define bswap_16(x) _byteswap_ushort(x) -#define bswap_32(x) _byteswap_ulong(x) -#define bswap_64(x) _byteswap_uint64(x) - -#elif defined(__APPLE__) -// Mac OS X / Darwin features -#include -#define bswap_16(x) OSSwapInt16(x) -#define bswap_32(x) OSSwapInt32(x) -#define bswap_64(x) OSSwapInt64(x) - -#elif defined(HAVE_BYTESWAP_H) -#include - -#elif defined(bswap32) -// FreeBSD defines bswap{16,32,64} in (already #included). -#define bswap_16(x) bswap16(x) -#define bswap_32(x) bswap32(x) -#define bswap_64(x) bswap64(x) - -#elif defined(BSWAP_64) -// Solaris 10 defines BSWAP_{16,32,64} in (already #included). -#define bswap_16(x) BSWAP_16(x) -#define bswap_32(x) BSWAP_32(x) -#define bswap_64(x) BSWAP_64(x) - -#else - -inline uint16 bswap_16(uint16 x) { - return (x << 8) | (x >> 8); -} - -inline uint32 bswap_32(uint32 x) { - x = ((x & 0xff00ff00UL) >> 8) | ((x & 0x00ff00ffUL) << 8); - return (x >> 16) | (x << 16); -} - -inline uint64 bswap_64(uint64 x) { - x = ((x & 0xff00ff00ff00ff00ULL) >> 8) | ((x & 0x00ff00ff00ff00ffULL) << 8); - x = ((x & 0xffff0000ffff0000ULL) >> 16) | ((x & 0x0000ffff0000ffffULL) << 16); - return (x >> 32) | (x << 32); -} - -#endif - -#endif // WORDS_BIGENDIAN - -// Convert to little-endian storage, opposite of network format. -// Convert x from host to little endian: x = LittleEndian.FromHost(x); -// convert x from little endian to host: x = LittleEndian.ToHost(x); -// -// Store values into unaligned memory converting to little endian order: -// LittleEndian.Store16(p, x); -// -// Load unaligned values stored in little endian converting to host order: -// x = LittleEndian.Load16(p); -class LittleEndian { - public: - // Conversion functions. -#ifdef WORDS_BIGENDIAN - - static uint16 FromHost16(uint16 x) { return bswap_16(x); } - static uint16 ToHost16(uint16 x) { return bswap_16(x); } - - static uint32 FromHost32(uint32 x) { return bswap_32(x); } - static uint32 ToHost32(uint32 x) { return bswap_32(x); } - - static bool IsLittleEndian() { return false; } - -#else // !defined(WORDS_BIGENDIAN) - - static uint16 FromHost16(uint16 x) { return x; } - static uint16 ToHost16(uint16 x) { return x; } - - static uint32 FromHost32(uint32 x) { return x; } - static uint32 ToHost32(uint32 x) { return x; } - - static bool IsLittleEndian() { return true; } - -#endif // !defined(WORDS_BIGENDIAN) - - // Functions to do unaligned loads and stores in little-endian order. - static uint16 Load16(const void *p) { - return ToHost16(UNALIGNED_LOAD16(p)); - } - - static void Store16(void *p, uint16 v) { - UNALIGNED_STORE16(p, FromHost16(v)); - } - - static uint32 Load32(const void *p) { - return ToHost32(UNALIGNED_LOAD32(p)); - } - - static void Store32(void *p, uint32 v) { - UNALIGNED_STORE32(p, FromHost32(v)); - } -}; - -// Some bit-manipulation functions. -class Bits { - public: - // Return floor(log2(n)) for positive integer n. Returns -1 iff n == 0. - static int Log2Floor(uint32 n); - - // Return the first set least / most significant bit, 0-indexed. Returns an - // undefined value if n == 0. FindLSBSetNonZero() is similar to ffs() except - // that it's 0-indexed. - static int FindLSBSetNonZero(uint32 n); - static int FindLSBSetNonZero64(uint64 n); - - private: - DISALLOW_COPY_AND_ASSIGN(Bits); -}; - -#ifdef HAVE_BUILTIN_CTZ - -inline int Bits::Log2Floor(uint32 n) { - return n == 0 ? -1 : 31 ^ __builtin_clz(n); -} - -inline int Bits::FindLSBSetNonZero(uint32 n) { - return __builtin_ctz(n); -} - -inline int Bits::FindLSBSetNonZero64(uint64 n) { - return __builtin_ctzll(n); -} - -#else // Portable versions. - -inline int Bits::Log2Floor(uint32 n) { - if (n == 0) - return -1; - int log = 0; - uint32 value = n; - for (int i = 4; i >= 0; --i) { - int shift = (1 << i); - uint32 x = value >> shift; - if (x != 0) { - value = x; - log += shift; - } - } - assert(value == 1); - return log; -} - -inline int Bits::FindLSBSetNonZero(uint32 n) { - int rc = 31; - for (int i = 4, shift = 1 << 4; i >= 0; --i) { - const uint32 x = n << shift; - if (x != 0) { - n = x; - rc -= shift; - } - shift >>= 1; - } - return rc; -} - -// FindLSBSetNonZero64() is defined in terms of FindLSBSetNonZero(). -inline int Bits::FindLSBSetNonZero64(uint64 n) { - const uint32 bottombits = static_cast(n); - if (bottombits == 0) { - // Bottom bits are zero, so scan in top bits - return 32 + FindLSBSetNonZero(static_cast(n >> 32)); - } else { - return FindLSBSetNonZero(bottombits); - } -} - -#endif // End portable versions. - -// Variable-length integer encoding. -class Varint { - public: - // Maximum lengths of varint encoding of uint32. - static const int kMax32 = 5; - - // Attempts to parse a varint32 from a prefix of the bytes in [ptr,limit-1]. - // Never reads a character at or beyond limit. If a valid/terminated varint32 - // was found in the range, stores it in *OUTPUT and returns a pointer just - // past the last byte of the varint32. Else returns NULL. On success, - // "result <= limit". - static const char* Parse32WithLimit(const char* ptr, const char* limit, - uint32* OUTPUT); - - // REQUIRES "ptr" points to a buffer of length sufficient to hold "v". - // EFFECTS Encodes "v" into "ptr" and returns a pointer to the - // byte just past the last encoded byte. - static char* Encode32(char* ptr, uint32 v); - - // EFFECTS Appends the varint representation of "value" to "*s". - static void Append32(string* s, uint32 value); -}; - -inline const char* Varint::Parse32WithLimit(const char* p, - const char* l, - uint32* OUTPUT) { - const unsigned char* ptr = reinterpret_cast(p); - const unsigned char* limit = reinterpret_cast(l); - uint32 b, result; - if (ptr >= limit) return NULL; - b = *(ptr++); result = b & 127; if (b < 128) goto done; - if (ptr >= limit) return NULL; - b = *(ptr++); result |= (b & 127) << 7; if (b < 128) goto done; - if (ptr >= limit) return NULL; - b = *(ptr++); result |= (b & 127) << 14; if (b < 128) goto done; - if (ptr >= limit) return NULL; - b = *(ptr++); result |= (b & 127) << 21; if (b < 128) goto done; - if (ptr >= limit) return NULL; - b = *(ptr++); result |= (b & 127) << 28; if (b < 16) goto done; - return NULL; // Value is too long to be a varint32 - done: - *OUTPUT = result; - return reinterpret_cast(ptr); -} - -inline char* Varint::Encode32(char* sptr, uint32 v) { - // Operate on characters as unsigneds - unsigned char* ptr = reinterpret_cast(sptr); - static const int B = 128; - if (v < (1<<7)) { - *(ptr++) = v; - } else if (v < (1<<14)) { - *(ptr++) = v | B; - *(ptr++) = v>>7; - } else if (v < (1<<21)) { - *(ptr++) = v | B; - *(ptr++) = (v>>7) | B; - *(ptr++) = v>>14; - } else if (v < (1<<28)) { - *(ptr++) = v | B; - *(ptr++) = (v>>7) | B; - *(ptr++) = (v>>14) | B; - *(ptr++) = v>>21; - } else { - *(ptr++) = v | B; - *(ptr++) = (v>>7) | B; - *(ptr++) = (v>>14) | B; - *(ptr++) = (v>>21) | B; - *(ptr++) = v>>28; - } - return reinterpret_cast(ptr); -} - -// If you know the internal layout of the std::string in use, you can -// replace this function with one that resizes the string without -// filling the new space with zeros (if applicable) -- -// it will be non-portable but faster. -inline void STLStringResizeUninitialized(string* s, size_t new_size) { - s->resize(new_size); -} - -// Return a mutable char* pointing to a string's internal buffer, -// which may not be null-terminated. Writing through this pointer will -// modify the string. -// -// string_as_array(&str)[i] is valid for 0 <= i < str.size() until the -// next call to a string method that invalidates iterators. -// -// As of 2006-04, there is no standard-blessed way of getting a -// mutable reference to a string's internal buffer. However, issue 530 -// (http://www.open-std.org/JTC1/SC22/WG21/docs/lwg-defects.html#530) -// proposes this as the method. It will officially be part of the standard -// for C++0x. This should already work on all current implementations. -inline char* string_as_array(string* str) { - return str->empty() ? NULL : &*str->begin(); -} - -} // namespace snappy - -#endif // UTIL_SNAPPY_OPENSOURCE_SNAPPY_STUBS_INTERNAL_H_ diff --git a/utils/compress/snappy-stubs-public.h b/utils/compress/snappy-stubs-public.h deleted file mode 100644 index ecda43987..000000000 --- a/utils/compress/snappy-stubs-public.h +++ /dev/null @@ -1,98 +0,0 @@ -// Copyright 2011 Google Inc. All Rights Reserved. -// Author: sesse@google.com (Steinar H. Gunderson) -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -// -// Various type stubs for the open-source version of Snappy. -// -// This file cannot include config.h, as it is included from snappy.h, -// which is a public header. Instead, snappy-stubs-public.h is generated by -// from snappy-stubs-public.h.in at configure time. - -#ifndef UTIL_SNAPPY_OPENSOURCE_SNAPPY_STUBS_PUBLIC_H_ -#define UTIL_SNAPPY_OPENSOURCE_SNAPPY_STUBS_PUBLIC_H_ - -#if 1 -#include -#endif - -#if 1 -#include -#endif - -#if 0 -#include -#endif - -#define SNAPPY_MAJOR 1 -#define SNAPPY_MINOR 1 -#define SNAPPY_PATCHLEVEL 1 -#define SNAPPY_VERSION \ - ((SNAPPY_MAJOR << 16) | (SNAPPY_MINOR << 8) | SNAPPY_PATCHLEVEL) - -#include - -namespace snappy { - -#if 1 -typedef int8_t int8; -typedef uint8_t uint8; -typedef int16_t int16; -typedef uint16_t uint16; -typedef int32_t int32; -typedef uint32_t uint32; -typedef int64_t int64; -typedef uint64_t uint64; -#else -typedef signed char int8; -typedef unsigned char uint8; -typedef short int16; -typedef unsigned short uint16; -typedef int int32; -typedef unsigned int uint32; -typedef long long int64; -typedef unsigned long long uint64; -#endif - -typedef std::string string; - -#define DISALLOW_COPY_AND_ASSIGN(TypeName) \ - TypeName(const TypeName&); \ - void operator=(const TypeName&) - -#if !0 -// Windows does not have an iovec type, yet the concept is universally useful. -// It is simple to define it ourselves, so we put it inside our own namespace. -struct iovec { - void* iov_base; - size_t iov_len; -}; -#endif - -} // namespace snappy - -#endif // UTIL_SNAPPY_OPENSOURCE_SNAPPY_STUBS_PUBLIC_H_ diff --git a/utils/compress/snappy.cpp b/utils/compress/snappy.cpp deleted file mode 100644 index 1072f92dd..000000000 --- a/utils/compress/snappy.cpp +++ /dev/null @@ -1,1306 +0,0 @@ -// Copyright 2005 Google Inc. All Rights Reserved. -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -#include "snappy.h" -#include "snappy-internal.h" -#include "snappy-sinksource.h" - -#include - -#include -#include -#include - - -namespace snappy { - -// Any hash function will produce a valid compressed bitstream, but a good -// hash function reduces the number of collisions and thus yields better -// compression for compressible input, and more speed for incompressible -// input. Of course, it doesn't hurt if the hash function is reasonably fast -// either, as it gets called a lot. -static inline uint32 HashBytes(uint32 bytes, int shift) { - uint32 kMul = 0x1e35a7bd; - return (bytes * kMul) >> shift; -} -static inline uint32 Hash(const char* p, int shift) { - return HashBytes(UNALIGNED_LOAD32(p), shift); -} - -size_t MaxCompressedLength(size_t source_len) { - // Compressed data can be defined as: - // compressed := item* literal* - // item := literal* copy - // - // The trailing literal sequence has a space blowup of at most 62/60 - // since a literal of length 60 needs one tag byte + one extra byte - // for length information. - // - // Item blowup is trickier to measure. Suppose the "copy" op copies - // 4 bytes of data. Because of a special check in the encoding code, - // we produce a 4-byte copy only if the offset is < 65536. Therefore - // the copy op takes 3 bytes to encode, and this type of item leads - // to at most the 62/60 blowup for representing literals. - // - // Suppose the "copy" op copies 5 bytes of data. If the offset is big - // enough, it will take 5 bytes to encode the copy op. Therefore the - // worst case here is a one-byte literal followed by a five-byte copy. - // I.e., 6 bytes of input turn into 7 bytes of "compressed" data. - // - // This last factor dominates the blowup, so the final estimate is: - return 32 + source_len + source_len/6; -} - -enum { - LITERAL = 0, - COPY_1_BYTE_OFFSET = 1, // 3 bit length + 3 bits of offset in opcode - COPY_2_BYTE_OFFSET = 2, - COPY_4_BYTE_OFFSET = 3 -}; -static const int kMaximumTagLength = 5; // COPY_4_BYTE_OFFSET plus the actual offset. - -// Copy "len" bytes from "src" to "op", one byte at a time. Used for -// handling COPY operations where the input and output regions may -// overlap. For example, suppose: -// src == "ab" -// op == src + 2 -// len == 20 -// After IncrementalCopy(src, op, len), the result will have -// eleven copies of "ab" -// ababababababababababab -// Note that this does not match the semantics of either memcpy() -// or memmove(). -static inline void IncrementalCopy(const char* src, char* op, ssize_t len) { - assert(len > 0); - do { - *op++ = *src++; - } while (--len > 0); -} - -// Equivalent to IncrementalCopy except that it can write up to ten extra -// bytes after the end of the copy, and that it is faster. -// -// The main part of this loop is a simple copy of eight bytes at a time until -// we've copied (at least) the requested amount of bytes. However, if op and -// src are less than eight bytes apart (indicating a repeating pattern of -// length < 8), we first need to expand the pattern in order to get the correct -// results. For instance, if the buffer looks like this, with the eight-byte -// and patterns marked as intervals: -// -// abxxxxxxxxxxxx -// [------] src -// [------] op -// -// a single eight-byte copy from to will repeat the pattern once, -// after which we can move two bytes without moving : -// -// ababxxxxxxxxxx -// [------] src -// [------] op -// -// and repeat the exercise until the two no longer overlap. -// -// This allows us to do very well in the special case of one single byte -// repeated many times, without taking a big hit for more general cases. -// -// The worst case of extra writing past the end of the match occurs when -// op - src == 1 and len == 1; the last copy will read from byte positions -// [0..7] and write to [4..11], whereas it was only supposed to write to -// position 1. Thus, ten excess bytes. - -namespace { - -const int kMaxIncrementCopyOverflow = 10; - -inline void IncrementalCopyFastPath(const char* src, char* op, ssize_t len) { - while (op - src < 8) { - UnalignedCopy64(src, op); - len -= op - src; - op += op - src; - } - while (len > 0) { - UnalignedCopy64(src, op); - src += 8; - op += 8; - len -= 8; - } -} - -} // namespace - -static inline char* EmitLiteral(char* op, - const char* literal, - int len, - bool allow_fast_path) { - int n = len - 1; // Zero-length literals are disallowed - if (n < 60) { - // Fits in tag byte - *op++ = LITERAL | (n << 2); - - // The vast majority of copies are below 16 bytes, for which a - // call to memcpy is overkill. This fast path can sometimes - // copy up to 15 bytes too much, but that is okay in the - // main loop, since we have a bit to go on for both sides: - // - // - The input will always have kInputMarginBytes = 15 extra - // available bytes, as long as we're in the main loop, and - // if not, allow_fast_path = false. - // - The output will always have 32 spare bytes (see - // MaxCompressedLength). - if (allow_fast_path && len <= 16) { - UnalignedCopy64(literal, op); - UnalignedCopy64(literal + 8, op + 8); - return op + len; - } - } else { - // Encode in upcoming bytes - char* base = op; - int count = 0; - op++; - while (n > 0) { - *op++ = n & 0xff; - n >>= 8; - count++; - } - assert(count >= 1); - assert(count <= 4); - *base = LITERAL | ((59+count) << 2); - } - memcpy(op, literal, len); - return op + len; -} - -static inline char* EmitCopyLessThan64(char* op, size_t offset, int len) { - assert(len <= 64); - assert(len >= 4); - assert(offset < 65536); - - if ((len < 12) && (offset < 2048)) { - size_t len_minus_4 = len - 4; - assert(len_minus_4 < 8); // Must fit in 3 bits - *op++ = COPY_1_BYTE_OFFSET + ((len_minus_4) << 2) + ((offset >> 8) << 5); - *op++ = offset & 0xff; - } else { - *op++ = COPY_2_BYTE_OFFSET + ((len-1) << 2); - LittleEndian::Store16(op, offset); - op += 2; - } - return op; -} - -static inline char* EmitCopy(char* op, size_t offset, int len) { - // Emit 64 byte copies but make sure to keep at least four bytes reserved - while (len >= 68) { - op = EmitCopyLessThan64(op, offset, 64); - len -= 64; - } - - // Emit an extra 60 byte copy if have too much data to fit in one copy - if (len > 64) { - op = EmitCopyLessThan64(op, offset, 60); - len -= 60; - } - - // Emit remainder - op = EmitCopyLessThan64(op, offset, len); - return op; -} - - -bool GetUncompressedLength(const char* start, size_t n, size_t* result) { - uint32 v = 0; - const char* limit = start + n; - if (Varint::Parse32WithLimit(start, limit, &v) != NULL) { - *result = v; - return true; - } else { - return false; - } -} - -namespace internal { -uint16* WorkingMemory::GetHashTable(size_t input_size, int* table_size) { - // Use smaller hash table when input.size() is smaller, since we - // fill the table, incurring O(hash table size) overhead for - // compression, and if the input is short, we won't need that - // many hash table entries anyway. - assert(kMaxHashTableSize >= 256); - size_t htsize = 256; - while (htsize < kMaxHashTableSize && htsize < input_size) { - htsize <<= 1; - } - - uint16* table; - if (htsize <= ARRAYSIZE(small_table_)) { - table = small_table_; - } else { - if (large_table_ == NULL) { - large_table_ = new uint16[kMaxHashTableSize]; - } - table = large_table_; - } - - *table_size = htsize; - memset(table, 0, htsize * sizeof(*table)); - return table; -} -} // end namespace internal - -// For 0 <= offset <= 4, GetUint32AtOffset(GetEightBytesAt(p), offset) will -// equal UNALIGNED_LOAD32(p + offset). Motivation: On x86-64 hardware we have -// empirically found that overlapping loads such as -// UNALIGNED_LOAD32(p) ... UNALIGNED_LOAD32(p+1) ... UNALIGNED_LOAD32(p+2) -// are slower than UNALIGNED_LOAD64(p) followed by shifts and casts to uint32. -// -// We have different versions for 64- and 32-bit; ideally we would avoid the -// two functions and just inline the UNALIGNED_LOAD64 call into -// GetUint32AtOffset, but GCC (at least not as of 4.6) is seemingly not clever -// enough to avoid loading the value multiple times then. For 64-bit, the load -// is done when GetEightBytesAt() is called, whereas for 32-bit, the load is -// done at GetUint32AtOffset() time. - -#ifdef ARCH_K8 - -typedef uint64 EightBytesReference; - -static inline EightBytesReference GetEightBytesAt(const char* ptr) { - return UNALIGNED_LOAD64(ptr); -} - -static inline uint32 GetUint32AtOffset(uint64 v, int offset) { - assert(offset >= 0); - assert(offset <= 4); - return v >> (LittleEndian::IsLittleEndian() ? 8 * offset : 32 - 8 * offset); -} - -#else - -typedef const char* EightBytesReference; - -static inline EightBytesReference GetEightBytesAt(const char* ptr) { - return ptr; -} - -static inline uint32 GetUint32AtOffset(const char* v, int offset) { - assert(offset >= 0); - assert(offset <= 4); - return UNALIGNED_LOAD32(v + offset); -} - -#endif - -// Flat array compression that does not emit the "uncompressed length" -// prefix. Compresses "input" string to the "*op" buffer. -// -// REQUIRES: "input" is at most "kBlockSize" bytes long. -// REQUIRES: "op" points to an array of memory that is at least -// "MaxCompressedLength(input.size())" in size. -// REQUIRES: All elements in "table[0..table_size-1]" are initialized to zero. -// REQUIRES: "table_size" is a power of two -// -// Returns an "end" pointer into "op" buffer. -// "end - op" is the compressed size of "input". -namespace internal { -char* CompressFragment(const char* input, - size_t input_size, - char* op, - uint16* table, - const int table_size) { - // "ip" is the input pointer, and "op" is the output pointer. - const char* ip = input; - assert(input_size <= kBlockSize); - assert((table_size & (table_size - 1)) == 0); // table must be power of two - const int shift = 32 - Bits::Log2Floor(table_size); - assert(static_cast(kuint32max >> shift) == table_size - 1); - const char* ip_end = input + input_size; - const char* base_ip = ip; - // Bytes in [next_emit, ip) will be emitted as literal bytes. Or - // [next_emit, ip_end) after the main loop. - const char* next_emit = ip; - - const size_t kInputMarginBytes = 15; - if (PREDICT_TRUE(input_size >= kInputMarginBytes)) { - const char* ip_limit = input + input_size - kInputMarginBytes; - - for (uint32 next_hash = Hash(++ip, shift); ; ) { - assert(next_emit < ip); - // The body of this loop calls EmitLiteral once and then EmitCopy one or - // more times. (The exception is that when we're close to exhausting - // the input we goto emit_remainder.) - // - // In the first iteration of this loop we're just starting, so - // there's nothing to copy, so calling EmitLiteral once is - // necessary. And we only start a new iteration when the - // current iteration has determined that a call to EmitLiteral will - // precede the next call to EmitCopy (if any). - // - // Step 1: Scan forward in the input looking for a 4-byte-long match. - // If we get close to exhausting the input then goto emit_remainder. - // - // Heuristic match skipping: If 32 bytes are scanned with no matches - // found, start looking only at every other byte. If 32 more bytes are - // scanned, look at every third byte, etc.. When a match is found, - // immediately go back to looking at every byte. This is a small loss - // (~5% performance, ~0.1% density) for compressible data due to more - // bookkeeping, but for non-compressible data (such as JPEG) it's a huge - // win since the compressor quickly "realizes" the data is incompressible - // and doesn't bother looking for matches everywhere. - // - // The "skip" variable keeps track of how many bytes there are since the - // last match; dividing it by 32 (ie. right-shifting by five) gives the - // number of bytes to move ahead for each iteration. - uint32 skip = 32; - - const char* next_ip = ip; - const char* candidate; - do { - ip = next_ip; - uint32 hash = next_hash; - assert(hash == Hash(ip, shift)); - uint32 bytes_between_hash_lookups = skip++ >> 5; - next_ip = ip + bytes_between_hash_lookups; - if (PREDICT_FALSE(next_ip > ip_limit)) { - goto emit_remainder; - } - next_hash = Hash(next_ip, shift); - candidate = base_ip + table[hash]; - assert(candidate >= base_ip); - assert(candidate < ip); - - table[hash] = ip - base_ip; - } while (PREDICT_TRUE(UNALIGNED_LOAD32(ip) != - UNALIGNED_LOAD32(candidate))); - - // Step 2: A 4-byte match has been found. We'll later see if more - // than 4 bytes match. But, prior to the match, input - // bytes [next_emit, ip) are unmatched. Emit them as "literal bytes." - assert(next_emit + 16 <= ip_end); - op = EmitLiteral(op, next_emit, ip - next_emit, true); - - // Step 3: Call EmitCopy, and then see if another EmitCopy could - // be our next move. Repeat until we find no match for the - // input immediately after what was consumed by the last EmitCopy call. - // - // If we exit this loop normally then we need to call EmitLiteral next, - // though we don't yet know how big the literal will be. We handle that - // by proceeding to the next iteration of the main loop. We also can exit - // this loop via goto if we get close to exhausting the input. - EightBytesReference input_bytes; - uint32 candidate_bytes = 0; - - do { - // We have a 4-byte match at ip, and no need to emit any - // "literal bytes" prior to ip. - const char* base = ip; - int matched = 4 + FindMatchLength(candidate + 4, ip + 4, ip_end); - ip += matched; - size_t offset = base - candidate; - assert(0 == memcmp(base, candidate, matched)); - op = EmitCopy(op, offset, matched); - // We could immediately start working at ip now, but to improve - // compression we first update table[Hash(ip - 1, ...)]. - const char* insert_tail = ip - 1; - next_emit = ip; - if (PREDICT_FALSE(ip >= ip_limit)) { - goto emit_remainder; - } - input_bytes = GetEightBytesAt(insert_tail); - uint32 prev_hash = HashBytes(GetUint32AtOffset(input_bytes, 0), shift); - table[prev_hash] = ip - base_ip - 1; - uint32 cur_hash = HashBytes(GetUint32AtOffset(input_bytes, 1), shift); - candidate = base_ip + table[cur_hash]; - candidate_bytes = UNALIGNED_LOAD32(candidate); - table[cur_hash] = ip - base_ip; - } while (GetUint32AtOffset(input_bytes, 1) == candidate_bytes); - - next_hash = HashBytes(GetUint32AtOffset(input_bytes, 2), shift); - ++ip; - } - } - - emit_remainder: - // Emit the remaining bytes as a literal - if (next_emit < ip_end) { - op = EmitLiteral(op, next_emit, ip_end - next_emit, false); - } - - return op; -} -} // end namespace internal - -// Signature of output types needed by decompression code. -// The decompression code is templatized on a type that obeys this -// signature so that we do not pay virtual function call overhead in -// the middle of a tight decompression loop. -// -// class DecompressionWriter { -// public: -// // Called before decompression -// void SetExpectedLength(size_t length); -// -// // Called after decompression -// bool CheckLength() const; -// -// // Called repeatedly during decompression -// bool Append(const char* ip, size_t length); -// bool AppendFromSelf(uint32 offset, size_t length); -// -// // The rules for how TryFastAppend differs from Append are somewhat -// // convoluted: -// // -// // - TryFastAppend is allowed to decline (return false) at any -// // time, for any reason -- just "return false" would be -// // a perfectly legal implementation of TryFastAppend. -// // The intention is for TryFastAppend to allow a fast path -// // in the common case of a small append. -// // - TryFastAppend is allowed to read up to bytes -// // from the input buffer, whereas Append is allowed to read -// // . However, if it returns true, it must leave -// // at least five (kMaximumTagLength) bytes in the input buffer -// // afterwards, so that there is always enough space to read the -// // next tag without checking for a refill. -// // - TryFastAppend must always return decline (return false) -// // if is 61 or more, as in this case the literal length is not -// // decoded fully. In practice, this should not be a big problem, -// // as it is unlikely that one would implement a fast path accepting -// // this much data. -// // -// bool TryFastAppend(const char* ip, size_t available, size_t length); -// }; - -// ----------------------------------------------------------------------- -// Lookup table for decompression code. Generated by ComputeTable() below. -// ----------------------------------------------------------------------- - -// Mapping from i in range [0,4] to a mask to extract the bottom 8*i bits -static const uint32 wordmask[] = { - 0u, 0xffu, 0xffffu, 0xffffffu, 0xffffffffu -}; - -// Data stored per entry in lookup table: -// Range Bits-used Description -// ------------------------------------ -// 1..64 0..7 Literal/copy length encoded in opcode byte -// 0..7 8..10 Copy offset encoded in opcode byte / 256 -// 0..4 11..13 Extra bytes after opcode -// -// We use eight bits for the length even though 7 would have sufficed -// because of efficiency reasons: -// (1) Extracting a byte is faster than a bit-field -// (2) It properly aligns copy offset so we do not need a <<8 -static const uint16 char_table[256] = { - 0x0001, 0x0804, 0x1001, 0x2001, 0x0002, 0x0805, 0x1002, 0x2002, - 0x0003, 0x0806, 0x1003, 0x2003, 0x0004, 0x0807, 0x1004, 0x2004, - 0x0005, 0x0808, 0x1005, 0x2005, 0x0006, 0x0809, 0x1006, 0x2006, - 0x0007, 0x080a, 0x1007, 0x2007, 0x0008, 0x080b, 0x1008, 0x2008, - 0x0009, 0x0904, 0x1009, 0x2009, 0x000a, 0x0905, 0x100a, 0x200a, - 0x000b, 0x0906, 0x100b, 0x200b, 0x000c, 0x0907, 0x100c, 0x200c, - 0x000d, 0x0908, 0x100d, 0x200d, 0x000e, 0x0909, 0x100e, 0x200e, - 0x000f, 0x090a, 0x100f, 0x200f, 0x0010, 0x090b, 0x1010, 0x2010, - 0x0011, 0x0a04, 0x1011, 0x2011, 0x0012, 0x0a05, 0x1012, 0x2012, - 0x0013, 0x0a06, 0x1013, 0x2013, 0x0014, 0x0a07, 0x1014, 0x2014, - 0x0015, 0x0a08, 0x1015, 0x2015, 0x0016, 0x0a09, 0x1016, 0x2016, - 0x0017, 0x0a0a, 0x1017, 0x2017, 0x0018, 0x0a0b, 0x1018, 0x2018, - 0x0019, 0x0b04, 0x1019, 0x2019, 0x001a, 0x0b05, 0x101a, 0x201a, - 0x001b, 0x0b06, 0x101b, 0x201b, 0x001c, 0x0b07, 0x101c, 0x201c, - 0x001d, 0x0b08, 0x101d, 0x201d, 0x001e, 0x0b09, 0x101e, 0x201e, - 0x001f, 0x0b0a, 0x101f, 0x201f, 0x0020, 0x0b0b, 0x1020, 0x2020, - 0x0021, 0x0c04, 0x1021, 0x2021, 0x0022, 0x0c05, 0x1022, 0x2022, - 0x0023, 0x0c06, 0x1023, 0x2023, 0x0024, 0x0c07, 0x1024, 0x2024, - 0x0025, 0x0c08, 0x1025, 0x2025, 0x0026, 0x0c09, 0x1026, 0x2026, - 0x0027, 0x0c0a, 0x1027, 0x2027, 0x0028, 0x0c0b, 0x1028, 0x2028, - 0x0029, 0x0d04, 0x1029, 0x2029, 0x002a, 0x0d05, 0x102a, 0x202a, - 0x002b, 0x0d06, 0x102b, 0x202b, 0x002c, 0x0d07, 0x102c, 0x202c, - 0x002d, 0x0d08, 0x102d, 0x202d, 0x002e, 0x0d09, 0x102e, 0x202e, - 0x002f, 0x0d0a, 0x102f, 0x202f, 0x0030, 0x0d0b, 0x1030, 0x2030, - 0x0031, 0x0e04, 0x1031, 0x2031, 0x0032, 0x0e05, 0x1032, 0x2032, - 0x0033, 0x0e06, 0x1033, 0x2033, 0x0034, 0x0e07, 0x1034, 0x2034, - 0x0035, 0x0e08, 0x1035, 0x2035, 0x0036, 0x0e09, 0x1036, 0x2036, - 0x0037, 0x0e0a, 0x1037, 0x2037, 0x0038, 0x0e0b, 0x1038, 0x2038, - 0x0039, 0x0f04, 0x1039, 0x2039, 0x003a, 0x0f05, 0x103a, 0x203a, - 0x003b, 0x0f06, 0x103b, 0x203b, 0x003c, 0x0f07, 0x103c, 0x203c, - 0x0801, 0x0f08, 0x103d, 0x203d, 0x1001, 0x0f09, 0x103e, 0x203e, - 0x1801, 0x0f0a, 0x103f, 0x203f, 0x2001, 0x0f0b, 0x1040, 0x2040 -}; - -// In debug mode, allow optional computation of the table at startup. -// Also, check that the decompression table is correct. -#ifndef NDEBUG -DEFINE_bool(snappy_dump_decompression_table, false, - "If true, we print the decompression table at startup."); - -static uint16 MakeEntry(unsigned int extra, - unsigned int len, - unsigned int copy_offset) { - // Check that all of the fields fit within the allocated space - assert(extra == (extra & 0x7)); // At most 3 bits - assert(copy_offset == (copy_offset & 0x7)); // At most 3 bits - assert(len == (len & 0x7f)); // At most 7 bits - return len | (copy_offset << 8) | (extra << 11); -} - -static void ComputeTable() { - uint16 dst[256]; - - // Place invalid entries in all places to detect missing initialization - int assigned = 0; - for (int i = 0; i < 256; i++) { - dst[i] = 0xffff; - } - - // Small LITERAL entries. We store (len-1) in the top 6 bits. - for (unsigned int len = 1; len <= 60; len++) { - dst[LITERAL | ((len-1) << 2)] = MakeEntry(0, len, 0); - assigned++; - } - - // Large LITERAL entries. We use 60..63 in the high 6 bits to - // encode the number of bytes of length info that follow the opcode. - for (unsigned int extra_bytes = 1; extra_bytes <= 4; extra_bytes++) { - // We set the length field in the lookup table to 1 because extra - // bytes encode len-1. - dst[LITERAL | ((extra_bytes+59) << 2)] = MakeEntry(extra_bytes, 1, 0); - assigned++; - } - - // COPY_1_BYTE_OFFSET. - // - // The tag byte in the compressed data stores len-4 in 3 bits, and - // offset/256 in 5 bits. offset%256 is stored in the next byte. - // - // This format is used for length in range [4..11] and offset in - // range [0..2047] - for (unsigned int len = 4; len < 12; len++) { - for (unsigned int offset = 0; offset < 2048; offset += 256) { - dst[COPY_1_BYTE_OFFSET | ((len-4)<<2) | ((offset>>8)<<5)] = - MakeEntry(1, len, offset>>8); - assigned++; - } - } - - // COPY_2_BYTE_OFFSET. - // Tag contains len-1 in top 6 bits, and offset in next two bytes. - for (unsigned int len = 1; len <= 64; len++) { - dst[COPY_2_BYTE_OFFSET | ((len-1)<<2)] = MakeEntry(2, len, 0); - assigned++; - } - - // COPY_4_BYTE_OFFSET. - // Tag contents len-1 in top 6 bits, and offset in next four bytes. - for (unsigned int len = 1; len <= 64; len++) { - dst[COPY_4_BYTE_OFFSET | ((len-1)<<2)] = MakeEntry(4, len, 0); - assigned++; - } - - // Check that each entry was initialized exactly once. - if (assigned != 256) { - fprintf(stderr, "ComputeTable: assigned only %d of 256\n", assigned); - abort(); - } - for (int i = 0; i < 256; i++) { - if (dst[i] == 0xffff) { - fprintf(stderr, "ComputeTable: did not assign byte %d\n", i); - abort(); - } - } - - if (FLAGS_snappy_dump_decompression_table) { - printf("static const uint16 char_table[256] = {\n "); - for (int i = 0; i < 256; i++) { - printf("0x%04x%s", - dst[i], - ((i == 255) ? "\n" : (((i%8) == 7) ? ",\n " : ", "))); - } - printf("};\n"); - } - - // Check that computed table matched recorded table - for (int i = 0; i < 256; i++) { - if (dst[i] != char_table[i]) { - fprintf(stderr, "ComputeTable: byte %d: computed (%x), expect (%x)\n", - i, static_cast(dst[i]), static_cast(char_table[i])); - abort(); - } - } -} -#endif /* !NDEBUG */ - -// Helper class for decompression -class SnappyDecompressor { - private: - Source* reader_; // Underlying source of bytes to decompress - const char* ip_; // Points to next buffered byte - const char* ip_limit_; // Points just past buffered bytes - uint32 peeked_; // Bytes peeked from reader (need to skip) - bool eof_; // Hit end of input without an error? - char scratch_[kMaximumTagLength]; // See RefillTag(). - - // Ensure that all of the tag metadata for the next tag is available - // in [ip_..ip_limit_-1]. Also ensures that [ip,ip+4] is readable even - // if (ip_limit_ - ip_ < 5). - // - // Returns true on success, false on error or end of input. - bool RefillTag(); - - public: - explicit SnappyDecompressor(Source* reader) - : reader_(reader), - ip_(NULL), - ip_limit_(NULL), - peeked_(0), - eof_(false) { - } - - ~SnappyDecompressor() { - // Advance past any bytes we peeked at from the reader - reader_->Skip(peeked_); - } - - // Returns true iff we have hit the end of the input without an error. - bool eof() const { - return eof_; - } - - // Read the uncompressed length stored at the start of the compressed data. - // On succcess, stores the length in *result and returns true. - // On failure, returns false. - bool ReadUncompressedLength(uint32* result) { - assert(ip_ == NULL); // Must not have read anything yet - // Length is encoded in 1..5 bytes - *result = 0; - uint32 shift = 0; - while (true) { - if (shift >= 32) return false; - size_t n; - const char* ip = reader_->Peek(&n); - if (n == 0) return false; - const unsigned char c = *(reinterpret_cast(ip)); - reader_->Skip(1); - *result |= static_cast(c & 0x7f) << shift; - if (c < 128) { - break; - } - shift += 7; - } - return true; - } - - // Process the next item found in the input. - // Returns true if successful, false on error or end of input. - template - void DecompressAllTags(Writer* writer) { - const char* ip = ip_; - - // We could have put this refill fragment only at the beginning of the loop. - // However, duplicating it at the end of each branch gives the compiler more - // scope to optimize the expression based on the local - // context, which overall increases speed. - #define MAYBE_REFILL() \ - if (ip_limit_ - ip < kMaximumTagLength) { \ - ip_ = ip; \ - if (!RefillTag()) return; \ - ip = ip_; \ - } - - MAYBE_REFILL(); - for ( ;; ) { - const unsigned char c = *(reinterpret_cast(ip++)); - - if ((c & 0x3) == LITERAL) { - size_t literal_length = (c >> 2) + 1u; - if (writer->TryFastAppend(ip, ip_limit_ - ip, literal_length)) { - assert(literal_length < 61); - ip += literal_length; - // NOTE(user): There is no MAYBE_REFILL() here, as TryFastAppend() - // will not return true unless there's already at least five spare - // bytes in addition to the literal. - continue; - } - if (PREDICT_FALSE(literal_length >= 61)) { - // Long literal. - const size_t literal_length_length = literal_length - 60; - literal_length = - (LittleEndian::Load32(ip) & wordmask[literal_length_length]) + 1; - ip += literal_length_length; - } - - size_t avail = ip_limit_ - ip; - while (avail < literal_length) { - if (!writer->Append(ip, avail)) return; - literal_length -= avail; - reader_->Skip(peeked_); - size_t n; - ip = reader_->Peek(&n); - avail = n; - peeked_ = avail; - if (avail == 0) return; // Premature end of input - ip_limit_ = ip + avail; - } - if (!writer->Append(ip, literal_length)) { - return; - } - ip += literal_length; - MAYBE_REFILL(); - } else { - const uint32 entry = char_table[c]; - const uint32 trailer = LittleEndian::Load32(ip) & wordmask[entry >> 11]; - const uint32 length = entry & 0xff; - ip += entry >> 11; - - // copy_offset/256 is encoded in bits 8..10. By just fetching - // those bits, we get copy_offset (since the bit-field starts at - // bit 8). - const uint32 copy_offset = entry & 0x700; - if (!writer->AppendFromSelf(copy_offset + trailer, length)) { - return; - } - MAYBE_REFILL(); - } - } - -#undef MAYBE_REFILL - } -}; - -bool SnappyDecompressor::RefillTag() { - const char* ip = ip_; - if (ip == ip_limit_) { - // Fetch a new fragment from the reader - reader_->Skip(peeked_); // All peeked bytes are used up - size_t n; - ip = reader_->Peek(&n); - peeked_ = n; - if (n == 0) { - eof_ = true; - return false; - } - ip_limit_ = ip + n; - } - - // Read the tag character - assert(ip < ip_limit_); - const unsigned char c = *(reinterpret_cast(ip)); - const uint32 entry = char_table[c]; - const uint32 needed = (entry >> 11) + 1; // +1 byte for 'c' - assert(needed <= sizeof(scratch_)); - - // Read more bytes from reader if needed - uint32 nbuf = ip_limit_ - ip; - if (nbuf < needed) { - // Stitch together bytes from ip and reader to form the word - // contents. We store the needed bytes in "scratch_". They - // will be consumed immediately by the caller since we do not - // read more than we need. - memmove(scratch_, ip, nbuf); - reader_->Skip(peeked_); // All peeked bytes are used up - peeked_ = 0; - while (nbuf < needed) { - size_t length; - const char* src = reader_->Peek(&length); - if (length == 0) return false; - uint32 to_add = min(needed - nbuf, length); - memcpy(scratch_ + nbuf, src, to_add); - nbuf += to_add; - reader_->Skip(to_add); - } - assert(nbuf == needed); - ip_ = scratch_; - ip_limit_ = scratch_ + needed; - } else if ((signed)nbuf < kMaximumTagLength) { - // Have enough bytes, but move into scratch_ so that we do not - // read past end of input - memmove(scratch_, ip, nbuf); - reader_->Skip(peeked_); // All peeked bytes are used up - peeked_ = 0; - ip_ = scratch_; - ip_limit_ = scratch_ + nbuf; - } else { - // Pass pointer to buffer returned by reader_. - ip_ = ip; - } - return true; -} - -template -static bool InternalUncompress(Source* r, Writer* writer) { - // Read the uncompressed length from the front of the compressed input - SnappyDecompressor decompressor(r); - uint32 uncompressed_len = 0; - if (!decompressor.ReadUncompressedLength(&uncompressed_len)) return false; - return InternalUncompressAllTags(&decompressor, writer, uncompressed_len); -} - -template -static bool InternalUncompressAllTags(SnappyDecompressor* decompressor, - Writer* writer, - uint32 uncompressed_len) { - writer->SetExpectedLength(uncompressed_len); - - // Process the entire input - decompressor->DecompressAllTags(writer); - return (decompressor->eof() && writer->CheckLength()); -} - -bool GetUncompressedLength(Source* source, uint32* result) { - SnappyDecompressor decompressor(source); - return decompressor.ReadUncompressedLength(result); -} - -size_t Compress(Source* reader, Sink* writer) { - size_t written = 0; - size_t N = reader->Available(); - char ulength[Varint::kMax32]; - char* p = Varint::Encode32(ulength, N); - writer->Append(ulength, p-ulength); - written += (p - ulength); - - internal::WorkingMemory wmem; - char* scratch = NULL; - char* scratch_output = NULL; - - while (N > 0) { - // Get next block to compress (without copying if possible) - size_t fragment_size; - const char* fragment = reader->Peek(&fragment_size); - assert(fragment_size != 0); // premature end of input - const size_t num_to_read = min(N, kBlockSize); - size_t bytes_read = fragment_size; - - size_t pending_advance = 0; - if (bytes_read >= num_to_read) { - // Buffer returned by reader is large enough - pending_advance = num_to_read; - fragment_size = num_to_read; - } else { - // Read into scratch buffer - if (scratch == NULL) { - // If this is the last iteration, we want to allocate N bytes - // of space, otherwise the max possible kBlockSize space. - // num_to_read contains exactly the correct value - scratch = new char[num_to_read]; - } - memcpy(scratch, fragment, bytes_read); - reader->Skip(bytes_read); - - while (bytes_read < num_to_read) { - fragment = reader->Peek(&fragment_size); - size_t n = min(fragment_size, num_to_read - bytes_read); - memcpy(scratch + bytes_read, fragment, n); - bytes_read += n; - reader->Skip(n); - } - assert(bytes_read == num_to_read); - fragment = scratch; - fragment_size = num_to_read; - } - assert(fragment_size == num_to_read); - - // Get encoding table for compression - int table_size; - uint16* table = wmem.GetHashTable(num_to_read, &table_size); - - // Compress input_fragment and append to dest - const int max_output = MaxCompressedLength(num_to_read); - - // Need a scratch buffer for the output, in case the byte sink doesn't - // have room for us directly. - if (scratch_output == NULL) { - scratch_output = new char[max_output]; - } else { - // Since we encode kBlockSize regions followed by a region - // which is <= kBlockSize in length, a previously allocated - // scratch_output[] region is big enough for this iteration. - } - char* dest = writer->GetAppendBuffer(max_output, scratch_output); - char* end = internal::CompressFragment(fragment, fragment_size, - dest, table, table_size); - writer->Append(dest, end - dest); - written += (end - dest); - - N -= num_to_read; - reader->Skip(pending_advance); - } - - delete[] scratch; - delete[] scratch_output; - - return written; -} - -// ----------------------------------------------------------------------- -// IOVec interfaces -// ----------------------------------------------------------------------- - -// A type that writes to an iovec. -// Note that this is not a "ByteSink", but a type that matches the -// Writer template argument to SnappyDecompressor::DecompressAllTags(). -class SnappyIOVecWriter { - private: - const struct iovec* output_iov_; - const size_t output_iov_count_; - - // We are currently writing into output_iov_[curr_iov_index_]. - int curr_iov_index_; - - // Bytes written to output_iov_[curr_iov_index_] so far. - size_t curr_iov_written_; - - // Total bytes decompressed into output_iov_ so far. - size_t total_written_; - - // Maximum number of bytes that will be decompressed into output_iov_. - size_t output_limit_; - - inline char* GetIOVecPointer(int index, size_t offset) { - return reinterpret_cast(output_iov_[index].iov_base) + - offset; - } - - public: - // Does not take ownership of iov. iov must be valid during the - // entire lifetime of the SnappyIOVecWriter. - inline SnappyIOVecWriter(const struct iovec* iov, size_t iov_count) - : output_iov_(iov), - output_iov_count_(iov_count), - curr_iov_index_(0), - curr_iov_written_(0), - total_written_(0), - output_limit_(-1) { - } - - inline void SetExpectedLength(size_t len) { - output_limit_ = len; - } - - inline bool CheckLength() const { - return total_written_ == output_limit_; - } - - inline bool Append(const char* ip, size_t len) { - if (total_written_ + len > output_limit_) { - return false; - } - - while (len > 0) { - assert(curr_iov_written_ <= output_iov_[curr_iov_index_].iov_len); - if (curr_iov_written_ >= output_iov_[curr_iov_index_].iov_len) { - // This iovec is full. Go to the next one. - if ((unsigned)curr_iov_index_ + 1 >= output_iov_count_) { - return false; - } - curr_iov_written_ = 0; - ++curr_iov_index_; - } - - const size_t to_write = std::min( - len, output_iov_[curr_iov_index_].iov_len - curr_iov_written_); - memcpy(GetIOVecPointer(curr_iov_index_, curr_iov_written_), - ip, - to_write); - curr_iov_written_ += to_write; - total_written_ += to_write; - ip += to_write; - len -= to_write; - } - - return true; - } - - inline bool TryFastAppend(const char* ip, size_t available, size_t len) { - const size_t space_left = output_limit_ - total_written_; - if (len <= 16 && available >= 16 + kMaximumTagLength && space_left >= 16 && - output_iov_[curr_iov_index_].iov_len - curr_iov_written_ >= 16) { - // Fast path, used for the majority (about 95%) of invocations. - char* ptr = GetIOVecPointer(curr_iov_index_, curr_iov_written_); - UnalignedCopy64(ip, ptr); - UnalignedCopy64(ip + 8, ptr + 8); - curr_iov_written_ += len; - total_written_ += len; - return true; - } - - return false; - } - - inline bool AppendFromSelf(size_t offset, size_t len) { - if (offset > total_written_ || offset == 0) { - return false; - } - const size_t space_left = output_limit_ - total_written_; - if (len > space_left) { - return false; - } - - // Locate the iovec from which we need to start the copy. - int from_iov_index = curr_iov_index_; - size_t from_iov_offset = curr_iov_written_; - while (offset > 0) { - if (from_iov_offset >= offset) { - from_iov_offset -= offset; - break; - } - - offset -= from_iov_offset; - --from_iov_index; - assert(from_iov_index >= 0); - from_iov_offset = output_iov_[from_iov_index].iov_len; - } - - // Copy bytes starting from the iovec pointed to by from_iov_index to - // the current iovec. - while (len > 0) { - assert(from_iov_index <= curr_iov_index_); - if (from_iov_index != curr_iov_index_) { - const size_t to_copy = std::min( - output_iov_[from_iov_index].iov_len - from_iov_offset, - len); - Append(GetIOVecPointer(from_iov_index, from_iov_offset), to_copy); - len -= to_copy; - if (len > 0) { - ++from_iov_index; - from_iov_offset = 0; - } - } else { - assert(curr_iov_written_ <= output_iov_[curr_iov_index_].iov_len); - size_t to_copy = std::min(output_iov_[curr_iov_index_].iov_len - - curr_iov_written_, - len); - if (to_copy == 0) { - // This iovec is full. Go to the next one. - if ((unsigned)curr_iov_index_ + 1 >= output_iov_count_) { - return false; - } - ++curr_iov_index_; - curr_iov_written_ = 0; - continue; - } - if (to_copy > len) { - to_copy = len; - } - IncrementalCopy(GetIOVecPointer(from_iov_index, from_iov_offset), - GetIOVecPointer(curr_iov_index_, curr_iov_written_), - to_copy); - curr_iov_written_ += to_copy; - from_iov_offset += to_copy; - total_written_ += to_copy; - len -= to_copy; - } - } - - return true; - } - -}; - -bool RawUncompressToIOVec(const char* compressed, size_t compressed_length, - const struct iovec* iov, size_t iov_cnt) { - ByteArraySource reader(compressed, compressed_length); - return RawUncompressToIOVec(&reader, iov, iov_cnt); -} - -bool RawUncompressToIOVec(Source* compressed, const struct iovec* iov, - size_t iov_cnt) { - SnappyIOVecWriter output(iov, iov_cnt); - return InternalUncompress(compressed, &output); -} - -// ----------------------------------------------------------------------- -// Flat array interfaces -// ----------------------------------------------------------------------- - -// A type that writes to a flat array. -// Note that this is not a "ByteSink", but a type that matches the -// Writer template argument to SnappyDecompressor::DecompressAllTags(). -class SnappyArrayWriter { - private: - char* base_; - char* op_; - char* op_limit_; - - public: - inline explicit SnappyArrayWriter(char* dst) - : base_(dst), - op_(dst) { - } - - inline void SetExpectedLength(size_t len) { - op_limit_ = op_ + len; - } - - inline bool CheckLength() const { - return op_ == op_limit_; - } - - inline bool Append(const char* ip, size_t len) { - char* op = op_; - const size_t space_left = op_limit_ - op; - if (space_left < len) { - return false; - } - memcpy(op, ip, len); - op_ = op + len; - return true; - } - - inline bool TryFastAppend(const char* ip, size_t available, size_t len) { - char* op = op_; - const size_t space_left = op_limit_ - op; - if (len <= 16 && available >= 16 + kMaximumTagLength && space_left >= 16) { - // Fast path, used for the majority (about 95%) of invocations. - UnalignedCopy64(ip, op); - UnalignedCopy64(ip + 8, op + 8); - op_ = op + len; - return true; - } else { - return false; - } - } - - inline bool AppendFromSelf(size_t offset, size_t len) { - char* op = op_; - const size_t space_left = op_limit_ - op; - - // Check if we try to append from before the start of the buffer. - // Normally this would just be a check for "produced < offset", - // but "produced <= offset - 1u" is equivalent for every case - // except the one where offset==0, where the right side will wrap around - // to a very big number. This is convenient, as offset==0 is another - // invalid case that we also want to catch, so that we do not go - // into an infinite loop. - assert(op >= base_); - size_t produced = op - base_; - if (produced <= offset - 1u) { - return false; - } - if (len <= 16 && offset >= 8 && space_left >= 16) { - // Fast path, used for the majority (70-80%) of dynamic invocations. - UnalignedCopy64(op - offset, op); - UnalignedCopy64(op - offset + 8, op + 8); - } else { - if (space_left >= len + kMaxIncrementCopyOverflow) { - IncrementalCopyFastPath(op - offset, op, len); - } else { - if (space_left < len) { - return false; - } - IncrementalCopy(op - offset, op, len); - } - } - - op_ = op + len; - return true; - } -}; - -bool RawUncompress(const char* compressed, size_t n, char* uncompressed) { - ByteArraySource reader(compressed, n); - return RawUncompress(&reader, uncompressed); -} - -bool RawUncompress(Source* compressed, char* uncompressed) { - SnappyArrayWriter output(uncompressed); - return InternalUncompress(compressed, &output); -} - -bool Uncompress(const char* compressed, size_t n, string* uncompressed) { - size_t ulength; - if (!GetUncompressedLength(compressed, n, &ulength)) { - return false; - } - // On 32-bit builds: max_size() < kuint32max. Check for that instead - // of crashing (e.g., consider externally specified compressed data). - if (ulength > uncompressed->max_size()) { - return false; - } - STLStringResizeUninitialized(uncompressed, ulength); - return RawUncompress(compressed, n, string_as_array(uncompressed)); -} - - -// A Writer that drops everything on the floor and just does validation -class SnappyDecompressionValidator { - private: - size_t expected_; - size_t produced_; - - public: - inline SnappyDecompressionValidator() : produced_(0) { } - inline void SetExpectedLength(size_t len) { - expected_ = len; - } - inline bool CheckLength() const { - return expected_ == produced_; - } - inline bool Append(const char* ip, size_t len) { - produced_ += len; - return produced_ <= expected_; - } - inline bool TryFastAppend(const char* ip, size_t available, size_t length) { - return false; - } - inline bool AppendFromSelf(size_t offset, size_t len) { - // See SnappyArrayWriter::AppendFromSelf for an explanation of - // the "offset - 1u" trick. - if (produced_ <= offset - 1u) return false; - produced_ += len; - return produced_ <= expected_; - } -}; - -bool IsValidCompressedBuffer(const char* compressed, size_t n) { - ByteArraySource reader(compressed, n); - SnappyDecompressionValidator writer; - return InternalUncompress(&reader, &writer); -} - -void RawCompress(const char* input, - size_t input_length, - char* compressed, - size_t* compressed_length) { - ByteArraySource reader(input, input_length); - UncheckedByteArraySink writer(compressed); - Compress(&reader, &writer); - - // Compute how many bytes were added - *compressed_length = (writer.CurrentDestination() - compressed); -} - -size_t Compress(const char* input, size_t input_length, string* compressed) { - // Pre-grow the buffer to the max length of the compressed output - compressed->resize(MaxCompressedLength(input_length)); - - size_t compressed_length; - RawCompress(input, input_length, string_as_array(compressed), - &compressed_length); - compressed->resize(compressed_length); - return compressed_length; -} - - -} // end namespace snappy - diff --git a/utils/compress/snappy.h b/utils/compress/snappy.h deleted file mode 100644 index e879e7949..000000000 --- a/utils/compress/snappy.h +++ /dev/null @@ -1,184 +0,0 @@ -// Copyright 2005 and onwards Google Inc. -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -// -// A light-weight compression algorithm. It is designed for speed of -// compression and decompression, rather than for the utmost in space -// savings. -// -// For getting better compression ratios when you are compressing data -// with long repeated sequences or compressing data that is similar to -// other data, while still compressing fast, you might look at first -// using BMDiff and then compressing the output of BMDiff with -// Snappy. - -#ifndef UTIL_SNAPPY_SNAPPY_H__ -#define UTIL_SNAPPY_SNAPPY_H__ - -#include -#include - -#include "snappy-stubs-public.h" - -namespace snappy { - class Source; - class Sink; - - // ------------------------------------------------------------------------ - // Generic compression/decompression routines. - // ------------------------------------------------------------------------ - - // Compress the bytes read from "*source" and append to "*sink". Return the - // number of bytes written. - size_t Compress(Source* source, Sink* sink); - - // Find the uncompressed length of the given stream, as given by the header. - // Note that the true length could deviate from this; the stream could e.g. - // be truncated. - // - // Also note that this leaves "*source" in a state that is unsuitable for - // further operations, such as RawUncompress(). You will need to rewind - // or recreate the source yourself before attempting any further calls. - bool GetUncompressedLength(Source* source, uint32* result); - - // ------------------------------------------------------------------------ - // Higher-level string based routines (should be sufficient for most users) - // ------------------------------------------------------------------------ - - // Sets "*output" to the compressed version of "input[0,input_length-1]". - // Original contents of *output are lost. - // - // REQUIRES: "input[]" is not an alias of "*output". - size_t Compress(const char* input, size_t input_length, string* output); - - // Decompresses "compressed[0,compressed_length-1]" to "*uncompressed". - // Original contents of "*uncompressed" are lost. - // - // REQUIRES: "compressed[]" is not an alias of "*uncompressed". - // - // returns false if the message is corrupted and could not be decompressed - bool Uncompress(const char* compressed, size_t compressed_length, - string* uncompressed); - - - // ------------------------------------------------------------------------ - // Lower-level character array based routines. May be useful for - // efficiency reasons in certain circumstances. - // ------------------------------------------------------------------------ - - // REQUIRES: "compressed" must point to an area of memory that is at - // least "MaxCompressedLength(input_length)" bytes in length. - // - // Takes the data stored in "input[0..input_length]" and stores - // it in the array pointed to by "compressed". - // - // "*compressed_length" is set to the length of the compressed output. - // - // Example: - // char* output = new char[snappy::MaxCompressedLength(input_length)]; - // size_t output_length; - // RawCompress(input, input_length, output, &output_length); - // ... Process(output, output_length) ... - // delete [] output; - void RawCompress(const char* input, - size_t input_length, - char* compressed, - size_t* compressed_length); - - // Given data in "compressed[0..compressed_length-1]" generated by - // calling the Snappy::Compress routine, this routine - // stores the uncompressed data to - // uncompressed[0..GetUncompressedLength(compressed)-1] - // returns false if the message is corrupted and could not be decrypted - bool RawUncompress(const char* compressed, size_t compressed_length, - char* uncompressed); - - // Given data from the byte source 'compressed' generated by calling - // the Snappy::Compress routine, this routine stores the uncompressed - // data to - // uncompressed[0..GetUncompressedLength(compressed,compressed_length)-1] - // returns false if the message is corrupted and could not be decrypted - bool RawUncompress(Source* compressed, char* uncompressed); - - // Given data in "compressed[0..compressed_length-1]" generated by - // calling the Snappy::Compress routine, this routine - // stores the uncompressed data to the iovec "iov". The number of physical - // buffers in "iov" is given by iov_cnt and their cumulative size - // must be at least GetUncompressedLength(compressed). The individual buffers - // in "iov" must not overlap with each other. - // - // returns false if the message is corrupted and could not be decrypted - bool RawUncompressToIOVec(const char* compressed, size_t compressed_length, - const struct iovec* iov, size_t iov_cnt); - - // Given data from the byte source 'compressed' generated by calling - // the Snappy::Compress routine, this routine stores the uncompressed - // data to the iovec "iov". The number of physical - // buffers in "iov" is given by iov_cnt and their cumulative size - // must be at least GetUncompressedLength(compressed). The individual buffers - // in "iov" must not overlap with each other. - // - // returns false if the message is corrupted and could not be decrypted - bool RawUncompressToIOVec(Source* compressed, const struct iovec* iov, - size_t iov_cnt); - - // Returns the maximal size of the compressed representation of - // input data that is "source_bytes" bytes in length; - size_t MaxCompressedLength(size_t source_bytes); - - // REQUIRES: "compressed[]" was produced by RawCompress() or Compress() - // Returns true and stores the length of the uncompressed data in - // *result normally. Returns false on parsing error. - // This operation takes O(1) time. - bool GetUncompressedLength(const char* compressed, size_t compressed_length, - size_t* result); - - // Returns true iff the contents of "compressed[]" can be uncompressed - // successfully. Does not return the uncompressed data. Takes - // time proportional to compressed_length, but is usually at least - // a factor of four faster than actual decompression. - bool IsValidCompressedBuffer(const char* compressed, - size_t compressed_length); - - // The size of a compression block. Note that many parts of the compression - // code assumes that kBlockSize <= 65536; in particular, the hash table - // can only store 16-bit offsets, and EmitCopy() also assumes the offset - // is 65535 bytes or less. Note also that if you change this, it will - // affect the framing format (see framing_format.txt). - // - // Note that there might be older data around that is compressed with larger - // block sizes, so the decompression code should not rely on the - // non-existence of long backreferences. - static const int kBlockLog = 16; - static const size_t kBlockSize = 1 << kBlockLog; - - static const int kMaxHashTableBits = 14; - static const size_t kMaxHashTableSize = 1 << kMaxHashTableBits; -} // end namespace snappy - - -#endif // UTIL_SNAPPY_SNAPPY_H__ From 12af41ebe57cdfc178a48efb58316e4aa24856a7 Mon Sep 17 00:00:00 2001 From: Andrew Hutchings Date: Tue, 17 Jan 2017 16:15:14 +0000 Subject: [PATCH 08/35] Fix RPM/DEB dependencies --- cpackEngineDEB.cmake | 2 +- cpackEngineRPM.cmake | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/cpackEngineDEB.cmake b/cpackEngineDEB.cmake index 3c80e3ccd..47bf96c5c 100644 --- a/cpackEngineDEB.cmake +++ b/cpackEngineDEB.cmake @@ -58,7 +58,7 @@ SET(CPACK_DEBIAN_LIBS_PACKAGE_PROVIDES "mariadb-columnstore-libs") SET(CPACK_DEBIAN_PLATFORM_PACKAGE_PROVIDES "mariadb-columnstore-platform") SET(CPACK_DEBIAN_STORAGE-ENGINE_PACKAGE_PROVIDES "mariadb-columnstore-storage-engine") -SET(CPACK_DEBIAN_PLATFORM_PACKAGE_DEPENDS "expect, libboost-all-dev, mariadb-columnstore-libs") +SET(CPACK_DEBIAN_PLATFORM_PACKAGE_DEPENDS "expect, libboost-all-dev, mariadb-columnstore-libs libsnappy1v5") SET(CPACK_DEBIAN_STORAGE-ENGINE_PACKAGE_DEPENDS "mariadb-columnstore-libs") diff --git a/cpackEngineRPM.cmake b/cpackEngineRPM.cmake index 32552e855..6df8f1a21 100644 --- a/cpackEngineRPM.cmake +++ b/cpackEngineRPM.cmake @@ -85,7 +85,7 @@ if (${REDHAT_VERSION_NUMBER} EQUAL 6) # Disable auto require as this will also try to pull Boost via RPM SET(CPACK_RPM_PACKAGE_AUTOREQPROV " no") else () - SETA(CPACK_RPM_platform_PACKAGE_REQUIRES "expect" "boost >= 1.53.0" "mariadb-columnstore-libs") + SETA(CPACK_RPM_platform_PACKAGE_REQUIRES "expect" "boost >= 1.53.0" "mariadb-columnstore-libs" "snappy") endif() SETA(CPACK_RPM_storage-engine_PACKAGE_REQUIRES "mariadb-columnstore-libs") From 61648c50eae563d46fa436586e04322878206169 Mon Sep 17 00:00:00 2001 From: David Hall Date: Thu, 19 Jan 2017 17:21:50 -0600 Subject: [PATCH 09/35] MCOL-1 use getSystemSuspended() rather than is ReadWrite() to determine if system writes are suspended. Add REMOVE documentation to help file. --- oam/etc/ConsoleCmds.xml | 5 +++-- oamapps/mcsadmin/mcsadmin.cpp | 4 ++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/oam/etc/ConsoleCmds.xml b/oam/etc/ConsoleCmds.xml index 1373a211c..114144d0a 100644 --- a/oam/etc/ConsoleCmds.xml +++ b/oam/etc/ConsoleCmds.xml @@ -29,8 +29,9 @@ redistributeData Redistribute table data accross all dbroots to balance disk usage START to begin a redistribution - STOP to stop redistribution before completion - STATUS to to view statistics and progress + START REMOVE [dbroots] to redistribute to all but the enumerated dbroots, leaving those empty + STOP to stop redistribution before completion + STATUS to to view statistics and progress findObjectFile diff --git a/oamapps/mcsadmin/mcsadmin.cpp b/oamapps/mcsadmin/mcsadmin.cpp index af556ec47..cb5998eb3 100644 --- a/oamapps/mcsadmin/mcsadmin.cpp +++ b/oamapps/mcsadmin/mcsadmin.cpp @@ -804,7 +804,7 @@ int processCommand(string* arguments) BRM::DBRM dbrm; // Ready to start the redistribute. The system must SuspendDataBaseWrites for the duration. - if (dbrm.isReadWrite() == BRM::ERR_OK) + if (dbrm.getSystemSuspended() == BRM::ERR_OK) { cout << "The system must be in read only mode for redistribeData to work" << endl; cout << "You must run suspendDatabaseWrites before running redistributeData" << endl; @@ -813,7 +813,7 @@ int processCommand(string* arguments) } #if 0 // This can be used when redistributeData doesn't return until complete. - if (dbrm.isReadWrite() == ERR_OK) + if (dbrm.getSystemSuspended() == ERR_OK) { // System not in suspenddatabasewrites // If there are bulkloads, ddl or dml happening, refuse the request From 8cf3a0046573dfe6a2bd8b6b87dd2f4e4fe4f217 Mon Sep 17 00:00:00 2001 From: David Hall Date: Fri, 20 Jan 2017 10:53:26 -0600 Subject: [PATCH 10/35] MCOL-1 whitespace fix --- oam/etc/ConsoleCmds.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/oam/etc/ConsoleCmds.xml b/oam/etc/ConsoleCmds.xml index 114144d0a..b5ee9b85d 100644 --- a/oam/etc/ConsoleCmds.xml +++ b/oam/etc/ConsoleCmds.xml @@ -30,7 +30,7 @@ Redistribute table data accross all dbroots to balance disk usage START to begin a redistribution START REMOVE [dbroots] to redistribute to all but the enumerated dbroots, leaving those empty - STOP to stop redistribution before completion + STOP to stop redistribution before completion STATUS to to view statistics and progress From d50c7c7caba37d2155e9875305b8a317bf8253e1 Mon Sep 17 00:00:00 2001 From: david hill Date: Tue, 24 Jan 2017 09:15:01 -0600 Subject: [PATCH 11/35] commit from develop, MCOL-455, MCOL-527, AND MCOL-528 --- oam/oamcpp/liboamcpp.cpp | 2 +- oamapps/postConfigure/postConfigure.cpp | 127 +++++++++++++----------- procmon/processmonitor.cpp | 86 +++++++++++++++- 3 files changed, 151 insertions(+), 64 deletions(-) diff --git a/oam/oamcpp/liboamcpp.cpp b/oam/oamcpp/liboamcpp.cpp index 3d35f35b7..810aac264 100644 --- a/oam/oamcpp/liboamcpp.cpp +++ b/oam/oamcpp/liboamcpp.cpp @@ -5987,7 +5987,7 @@ namespace oam } //attach and format volumes - device = "/dev/sdf"; + device = "/dev/xvdf"; string localInstance = getEC2LocalInstance(); diff --git a/oamapps/postConfigure/postConfigure.cpp b/oamapps/postConfigure/postConfigure.cpp index 1679a07d1..1facf1a7c 100644 --- a/oamapps/postConfigure/postConfigure.cpp +++ b/oamapps/postConfigure/postConfigure.cpp @@ -666,64 +666,6 @@ int main(int argc, char *argv[]) exit(1); } - cout << "NOTE: The MariaDB ColumnStore Schema Sync feature will replicate all of the" << endl; - cout << " schemas and InnoDB tables across the User Module nodes. This feature can be enabled" << endl; - cout << " or disabled, for example, if you wish to configure your own replication post installation." << endl << endl; - - try { - MySQLRep = sysConfig->getConfig(InstallSection, "MySQLRep"); - } - catch(...) - {} - - if ( MySQLRep == "y" ) - mysqlRep = true; - - string answer = "y"; - - while(true) { - if ( mysqlRep ) - prompt = "MariaDB ColumnStore Schema Sync feature is Enabled, do you want to leave enabled? [y,n] (y) > "; - else - prompt = "MariaDB ColumnStore Schema Sync feature, do you want to enable? [y,n] (y) > "; - - pcommand = callReadline(prompt.c_str()); - if (pcommand) { - if (strlen(pcommand) > 0) answer = pcommand; - callFree(pcommand); - } - - if ( answer == "y" || answer == "n" ) { - cout << endl; - break; - } - else - cout << "Invalid Entry, please enter 'y' for yes or 'n' for no" << endl; - if ( noPrompting ) - exit(1); - } - - if ( answer == "y" ) { - mysqlRep = true; - MySQLRep = "y"; - } - else - { - mysqlRep = false; - MySQLRep = "n"; - } - - try { - sysConfig->setConfig(InstallSection, "MySQLRep", MySQLRep); - } - catch(...) - {} - - if ( !writeConfig(sysConfig) ) { - cout << "ERROR: Failed trying to update MariaDB ColumnStore System Configuration file" << endl; - exit(1); - } - switch ( IserverTypeInstall ) { case (oam::INSTALL_COMBINE_DM_UM_PM): // combined #1 - dm/um/pm on a single server { @@ -813,6 +755,75 @@ int main(int argc, char *argv[]) break; } + // check for Schema Schema is Local Query wasnt selected + if (!pmwithum) + { + cout << "NOTE: The MariaDB ColumnStore Schema Sync feature will replicate all of the" << endl; + cout << " schemas and InnoDB tables across the User Module nodes. This feature can be enabled" << endl; + cout << " or disabled, for example, if you wish to configure your own replication post installation." << endl << endl; + + try { + MySQLRep = sysConfig->getConfig(InstallSection, "MySQLRep"); + } + catch(...) + {} + + if ( MySQLRep == "y" ) + mysqlRep = true; + + string answer = "y"; + + while(true) { + if ( mysqlRep ) + prompt = "MariaDB ColumnStore Schema Sync feature is Enabled, do you want to leave enabled? [y,n] (y) > "; + else + prompt = "MariaDB ColumnStore Schema Sync feature, do you want to enable? [y,n] (y) > "; + + pcommand = callReadline(prompt.c_str()); + if (pcommand) { + if (strlen(pcommand) > 0) answer = pcommand; + callFree(pcommand); + } + + if ( answer == "y" || answer == "n" ) { + cout << endl; + break; + } + else + cout << "Invalid Entry, please enter 'y' for yes or 'n' for no" << endl; + + if ( noPrompting ) + exit(1); + } + + if ( answer == "y" ) { + mysqlRep = true; + MySQLRep = "y"; + } + else + { + mysqlRep = false; + MySQLRep = "n"; + } + + try { + sysConfig->setConfig(InstallSection, "MySQLRep", MySQLRep); + } + catch(...) + {} + } + else + { //Schema Sync is default as on when Local Query is Selected + mysqlRep = true; + MySQLRep = "y"; + + try { + sysConfig->setConfig(InstallSection, "MySQLRep", MySQLRep); + } + catch(...) + {} + } + if ( !writeConfig(sysConfig) ) { cout << "ERROR: Failed trying to update MariaDB ColumnStore System Configuration file" << endl; exit(1); diff --git a/procmon/processmonitor.cpp b/procmon/processmonitor.cpp index 56fa5ac33..e474c69d5 100644 --- a/procmon/processmonitor.cpp +++ b/procmon/processmonitor.cpp @@ -5271,6 +5271,8 @@ int ProcessMonitor::runMasterDist(std::string& password, std::string& slaveModul string cmd = startup::StartUp::installDir() + "/bin/rsync.sh " + ipAddr + " " + password + " " + startup::StartUp::installDir() + " 1 > /tmp/master-dist_" + slaveModule + ".log"; system(cmd.c_str()); + + log.writeLog(__LINE__, "cmd = " + cmd, LOG_TYPE_DEBUG); string logFile = "/tmp/master-dist_" + slaveModule + ".log"; if (!oam.checkLogStatus(logFile, "FAILED")) @@ -5501,12 +5503,49 @@ bool ProcessMonitor::amazonVolumeCheck(int dbrootID) string status = oam.getEC2VolumeStatus(volumeName); if ( status == "attached" ) { - string cmd = "mount " + deviceName + " " + startup::StartUp::installDir() + "/mysql/db -t ext2 -o defaults > /dev/null"; + string cmd; + if ( rootUser) + cmd = "mount " + deviceName + " " + startup::StartUp::installDir() + "/mysql/db -t ext2 -o noatime,nodiratime,noauto > /tmp/um_mount.log"; + else + cmd = "sudo mount " + deviceName + " " + startup::StartUp::installDir() + "/mysql/db -t ext2 -o noatime,nodiratime,noauto,user > /tmp/um_mount.log"; + system(cmd.c_str()); log.writeLog(__LINE__, "mount cmd: " + cmd, LOG_TYPE_DEBUG); - cmd = "chown mysql:mysql -R " + startup::StartUp::installDir() + "/mysql/db"; + if ( rootUser) + cmd = "chown -R mysql:mysql " + startup::StartUp::installDir() + "/mysql/db"; + else + cmd = "sudo chown -R " + USER + ":" + USER + " " + startup::StartUp::installDir() + "/mysql/db"; + system(cmd.c_str()); + log.writeLog(__LINE__, "chown cmd: " + cmd, LOG_TYPE_DEBUG); + + //check for setup files in mysq/db, if not, create them for a new install + string file = startup::StartUp::installDir() + "/mysql/db/mysql"; + ifstream new_file (file.c_str()); + if (!new_file) { + string cmd; + cmd = startup::StartUp::installDir() + "/bin/post-mysqld-install --installdir=" + startup::StartUp::installDir() + " > /tmp/post-mysqld-install.log 2>&1"; + log.writeLog(__LINE__, "cmd: " + cmd, LOG_TYPE_DEBUG); + + int rtnCode = system(cmd.c_str()); + if (WEXITSTATUS(rtnCode) != 0) { + log.writeLog(__LINE__, "amazonVolumeCheck function failed, post-mysqld-install error" , LOG_TYPE_ERROR); + return false; + } + else + log.writeLog(__LINE__, "amazonVolumeCheck function, post-mysqld-install passed" , LOG_TYPE_DEBUG); + + cmd = startup::StartUp::installDir() + "/bin/post-mysql-install --installdir=" + startup::StartUp::installDir() + " > /tmp/post-mysql-install.log";; + log.writeLog(__LINE__, "cmd: " + cmd, LOG_TYPE_DEBUG); + rtnCode = system(cmd.c_str()); + if (WEXITSTATUS(rtnCode) != 0) { + log.writeLog(__LINE__, "amazonVolumeCheck function failed, post-mysql-install error" , LOG_TYPE_ERROR); + return false; + } + else + log.writeLog(__LINE__, "amazonVolumeCheck function, post-mysql-install passed" , LOG_TYPE_DEBUG); + } log.writeLog(__LINE__, "amazonVolumeCheck function successfully completed, volume attached: " + volumeName, LOG_TYPE_DEBUG); return true; @@ -5531,12 +5570,49 @@ bool ProcessMonitor::amazonVolumeCheck(int dbrootID) {} if (oam.attachEC2Volume(volumeName, deviceName, instanceName)) { - string cmd = "mount " + deviceName + " " + startup::StartUp::installDir() + "/mysql/db -t ext2 -o defaults > /dev/null"; + string cmd; + if ( rootUser) + cmd = "mount " + deviceName + " " + startup::StartUp::installDir() + "/mysql/db -t ext2 -o noatime,nodiratime,noauto > /tmp/um_mount.log"; + else + cmd = "sudo mount " + deviceName + " " + startup::StartUp::installDir() + "/mysql/db -t ext2 -o noatime,nodiratime,noauto,user > /tmp/um_mount.log"; + system(cmd.c_str()); log.writeLog(__LINE__, "mount cmd: " + cmd, LOG_TYPE_DEBUG); - cmd = "chown mysql:mysql -R " + startup::StartUp::installDir() + "/mysql/db"; + if ( rootUser) + cmd = "chown -R mysql:mysql " + startup::StartUp::installDir() + "/mysql/db"; + else + cmd = "sudo chown -R " + USER + ":" + USER + " " + startup::StartUp::installDir() + "/mysql/db"; + system(cmd.c_str()); + log.writeLog(__LINE__, "chown cmd: " + cmd, LOG_TYPE_DEBUG); + + //check for setup files in mysq/db, if not, create them for a new install + string file = startup::StartUp::installDir() + "/mysql/db/mysql"; + ifstream new_file (file.c_str()); + if (!new_file) { + string cmd; + cmd = startup::StartUp::installDir() + "/bin/post-mysqld-install --installdir=" + startup::StartUp::installDir() + " > /tmp/post-mysqld-install.log 2>&1"; + log.writeLog(__LINE__, "cmd: " + cmd, LOG_TYPE_DEBUG); + int rtnCode = system(cmd.c_str()); + if (WEXITSTATUS(rtnCode) != 0) { + log.writeLog(__LINE__, "amazonVolumeCheck function failed, post-mysqld-install error" , LOG_TYPE_ERROR); + return false; + } + else + log.writeLog(__LINE__, "amazonVolumeCheck function, post-mysqld-install passed" , LOG_TYPE_DEBUG); + + cmd = startup::StartUp::installDir() + "/bin/post-mysql-install --installdir=" + startup::StartUp::installDir() + " > /tmp/post-mysql-install.log";; + log.writeLog(__LINE__, "cmd: " + cmd, LOG_TYPE_DEBUG); + + rtnCode = system(cmd.c_str()); + if (WEXITSTATUS(rtnCode) != 0) { + log.writeLog(__LINE__, "amazonVolumeCheck function failed, post-mysql-install error" , LOG_TYPE_ERROR); + return false; + } + else + log.writeLog(__LINE__, "amazonVolumeCheck function, post-mysql-install passed" , LOG_TYPE_DEBUG); + } return true; } @@ -5809,7 +5885,7 @@ int ProcessMonitor::checkDataMount() string fileName = dbroot + "/OAMdbrootCheck"; ofstream fout(fileName.c_str()); if (!fout) { - log.writeLog(__LINE__, "ERROR: Failed test write to DBRoot: " + dbroot + " " + strerror(errno), LOG_TYPE_ERROR); + log.writeLog(__LINE__, "ERROR: Failed test write to DBRoot: " + dbroot, LOG_TYPE_ERROR); return API_FAILURE; } From 55d006de1a868c29695057186db6963d4971bcfb Mon Sep 17 00:00:00 2001 From: David Hall Date: Fri, 3 Feb 2017 15:22:07 -0600 Subject: [PATCH 12/35] MCOL-513 use thread pool for jobsteps --- dbcon/joblist/crossenginestep.cpp | 5 ++-- dbcon/joblist/crossenginestep.h | 2 +- dbcon/joblist/diskjoinstep.cpp | 28 ++++++++++++--------- dbcon/joblist/diskjoinstep.h | 7 +----- dbcon/joblist/joblist.cpp | 29 ++++++++++++++++++++++ dbcon/joblist/joblist.vpj | 2 ++ dbcon/joblist/jobstep.cpp | 3 +++ dbcon/joblist/jobstep.h | 4 ++- dbcon/joblist/pdictionaryscan.cpp | 10 +++++--- dbcon/joblist/primitivestep.h | 18 ++++++-------- dbcon/joblist/subquerystep.cpp | 5 ++-- dbcon/joblist/subquerystep.h | 2 +- dbcon/joblist/tuple-bps.cpp | 23 ++++++++--------- dbcon/joblist/tupleaggregatestep.cpp | 37 ++++++++++++---------------- dbcon/joblist/tupleaggregatestep.h | 4 +-- dbcon/joblist/tupleannexstep.cpp | 5 ++-- dbcon/joblist/tupleannexstep.h | 2 +- dbcon/joblist/tupleconstantstep.cpp | 5 ++-- dbcon/joblist/tupleconstantstep.h | 2 +- dbcon/joblist/tuplehashjoin.cpp | 30 +++++++++++----------- dbcon/joblist/tuplehashjoin.h | 10 ++++---- dbcon/joblist/tuplehavingstep.cpp | 5 ++-- dbcon/joblist/tuplehavingstep.h | 2 +- dbcon/joblist/tupleunion.cpp | 7 +++--- dbcon/joblist/tupleunion.h | 2 +- dbcon/joblist/windowfunctionstep.cpp | 15 +++++------ dbcon/joblist/windowfunctionstep.h | 4 +-- exemgr/main.cpp | 3 ++- utils/threadpool/threadpool.cpp | 37 +++++++++++++++++++++++++--- utils/threadpool/threadpool.h | 9 ++++--- 30 files changed, 192 insertions(+), 125 deletions(-) diff --git a/dbcon/joblist/crossenginestep.cpp b/dbcon/joblist/crossenginestep.cpp index e310d3d14..0b8b276a9 100644 --- a/dbcon/joblist/crossenginestep.cpp +++ b/dbcon/joblist/crossenginestep.cpp @@ -154,6 +154,7 @@ CrossEngineStep::CrossEngineStep( fRowsPerGroup(256), fOutputDL(NULL), fOutputIterator(0), + fRunner(0), fEndOfResult(false), fSchema(schema), fTable(table), @@ -439,14 +440,14 @@ void CrossEngineStep::run() fOutputIterator = fOutputDL->getIterator(); } - fRunner.reset(new boost::thread(Runner(this))); + fRunner = jobstepThreadPool.invoke(Runner(this)); } void CrossEngineStep::join() { if (fRunner) - fRunner->join(); + jobstepThreadPool.join(fRunner); } diff --git a/dbcon/joblist/crossenginestep.h b/dbcon/joblist/crossenginestep.h index a0f21cc50..1d4772165 100644 --- a/dbcon/joblist/crossenginestep.h +++ b/dbcon/joblist/crossenginestep.h @@ -181,7 +181,7 @@ protected: CrossEngineStep* fStep; }; - boost::scoped_ptr fRunner; + uint64_t fRunner; // thread pool handle OIDVector fOIDVector; bool fEndOfResult; bool fRunExecuted; diff --git a/dbcon/joblist/diskjoinstep.cpp b/dbcon/joblist/diskjoinstep.cpp index 856440ddf..ab125c904 100644 --- a/dbcon/joblist/diskjoinstep.cpp +++ b/dbcon/joblist/diskjoinstep.cpp @@ -58,7 +58,7 @@ namespace joblist { DiskJoinStep::DiskJoinStep() { } DiskJoinStep::DiskJoinStep(TupleHashJoinStep *t, int djsIndex, int joinIndex, bool lastOne) : JobStep(*t), thjs(t), - joinerIndex(joinIndex), closedOutput(false) + mainThread(0), joinerIndex(joinIndex), closedOutput(false) { /* grab all relevant vars from THJS @@ -130,9 +130,10 @@ DiskJoinStep::DiskJoinStep(TupleHashJoinStep *t, int djsIndex, int joinIndex, bo DiskJoinStep::~DiskJoinStep() { abort(); - if (mainThread) { - mainThread->join(); - mainThread.reset(); + if (mainThread) + { + jobstepThreadPool.join(mainThread); + mainThread = 0; } if (jp) atomicops::atomicSub(smallUsage.get(), jp->getSmallSideDiskUsage()); @@ -151,13 +152,16 @@ void DiskJoinStep::loadExistingData(vector &data) void DiskJoinStep::run() { - mainThread.reset(new boost::thread(Runner(this))); + mainThread = jobstepThreadPool.invoke(Runner(this)); } void DiskJoinStep::join() { if (mainThread) - mainThread->join(); + { + jobstepThreadPool.join(mainThread); + mainThread = 0; + } if (jp) { atomicops::atomicSub(smallUsage.get(), jp->getSmallSideDiskUsage()); //int64_t memUsage; @@ -479,12 +483,12 @@ void DiskJoinStep::mainRunner() loadFIFO.reset(new FIFO >(1, 1)); // double buffering should be good enough buildFIFO.reset(new FIFO >(1, 1)); - loadThread.reset(new boost::thread(Loader(this))); - buildThread.reset(new boost::thread(Builder(this))); - joinThread.reset(new boost::thread(Joiner(this))); - loadThread->join(); - buildThread->join(); - joinThread->join(); + std::vector thrds; + thrds.reserve(3); + thrds.push_back(jobstepThreadPool.invoke(Loader(this))); + thrds.push_back(jobstepThreadPool.invoke(Builder(this))); + thrds.push_back(jobstepThreadPool.invoke(Joiner(this))); + jobstepThreadPool.join(thrds); } } CATCH_AND_LOG; diff --git a/dbcon/joblist/diskjoinstep.h b/dbcon/joblist/diskjoinstep.h index a0524e805..7b8786bc7 100644 --- a/dbcon/joblist/diskjoinstep.h +++ b/dbcon/joblist/diskjoinstep.h @@ -49,7 +49,6 @@ class DiskJoinStep : public JobStep boost::shared_array LOMapping, SOMapping, SjoinFEMapping, LjoinFEMapping; TupleHashJoinStep *thjs; - boost::shared_ptr runner; boost::shared_ptr fe; bool typeless; JoinType joinType; @@ -69,7 +68,7 @@ class DiskJoinStep : public JobStep bool lastLargeIteration; uint32_t largeIterationCount; - boost::shared_ptr mainThread; + uint64_t mainThread; // thread handle from thread pool /* Loader structs */ struct LoaderOutput { @@ -86,8 +85,6 @@ class DiskJoinStep : public JobStep }; void loadFcn(); - boost::shared_ptr loadThread; - /* Builder structs */ struct BuilderOutput { boost::shared_ptr tupleJoiner; @@ -104,7 +101,6 @@ class DiskJoinStep : public JobStep DiskJoinStep *djs; }; void buildFcn(); - boost::shared_ptr buildThread; /* Joining structs */ struct Joiner { @@ -113,7 +109,6 @@ class DiskJoinStep : public JobStep DiskJoinStep *djs; }; void joinFcn(); - boost::shared_ptr joinThread; // limits & usage boost::shared_ptr smallUsage; diff --git a/dbcon/joblist/joblist.cpp b/dbcon/joblist/joblist.cpp index e4da0e568..d82689b06 100644 --- a/dbcon/joblist/joblist.cpp +++ b/dbcon/joblist/joblist.cpp @@ -108,6 +108,35 @@ JobList::~JobList() joiners[i]->join(); delete joiners[i]; } +#if 0 + // Stop all the query steps + end = fQuery.end(); + for (iter = fQuery.begin(); iter != end; ++iter) + { + (*iter)->abort(); + } + + // Stop all the projection steps + end = fProject.end(); + for (iter = fProject.begin(); iter != end; ++iter) + { + (*iter)->abort(); + } + + // Wait for all the query steps to end + end = fQuery.end(); + for (iter = fQuery.begin(); iter != end; ++iter) + { + (*iter)->join(); + } + + // Wait for all the projection steps to end + end = fProject.end(); + for (iter = fProject.begin(); iter != end; ++iter) + { + (*iter)->join(); + } +#endif } } catch (exception& ex) diff --git a/dbcon/joblist/joblist.vpj b/dbcon/joblist/joblist.vpj index 20b1d6278..cbf9aa13a 100644 --- a/dbcon/joblist/joblist.vpj +++ b/dbcon/joblist/joblist.vpj @@ -248,6 +248,7 @@ + + toString(); @@ -100,6 +102,7 @@ JobStep::JobStep(const JobInfo& j) : fQtc.serverParms(tsp); //fStepUuid = bu::random_generator()(); fStepUuid = QueryTeleClient::genUUID(); + jobstepThreadPool.setDebug(true); } //------------------------------------------------------------------------------ diff --git a/dbcon/joblist/jobstep.h b/dbcon/joblist/jobstep.h index 7dccd30d3..899a131d7 100644 --- a/dbcon/joblist/jobstep.h +++ b/dbcon/joblist/jobstep.h @@ -42,7 +42,7 @@ #include "timestamp.h" #include "rowgroup.h" #include "querytele.h" - +#include "threadpool.h" #include "atomicops.h" #include "branchpred.h" @@ -53,6 +53,7 @@ # endif #endif +using namespace threadpool; namespace joblist { @@ -234,6 +235,7 @@ public: void onClauseFilter(bool b) { fOnClauseFilter = b; } protected: + static ThreadPool jobstepThreadPool; //@bug6088, for telemetry posting static const int64_t STEP_TELE_INTERVAL = 5000; // now, this is the browser refresh rate diff --git a/dbcon/joblist/pdictionaryscan.cpp b/dbcon/joblist/pdictionaryscan.cpp index f2e09eac2..960458585 100644 --- a/dbcon/joblist/pdictionaryscan.cpp +++ b/dbcon/joblist/pdictionaryscan.cpp @@ -134,6 +134,8 @@ pDictionaryScan::pDictionaryScan( sendWaiting(false), ridCount(0), ridList(0), + pThread(0), + cThread(0), colType(ct), fScanLbidReqLimit(jobInfo.rm->getJlScanLbidReqLimit()), fScanLbidReqThreshold(jobInfo.rm->getJlScanLbidReqThreshold()), @@ -214,12 +216,12 @@ void pDictionaryScan::initializeConfigParms() void pDictionaryScan::startPrimitiveThread() { - pThread.reset(new boost::thread(pDictionaryScanPrimitive(this))); + pThread = jobstepThreadPool.invoke(pDictionaryScanPrimitive(this)); } void pDictionaryScan::startAggregationThread() { - cThread.reset(new boost::thread(pDictionaryScanAggregator(this))); + cThread = jobstepThreadPool.invoke(pDictionaryScanAggregator(this)); } void pDictionaryScan::run() @@ -243,8 +245,8 @@ void pDictionaryScan::run() void pDictionaryScan::join() { - pThread->join(); - cThread->join(); + jobstepThreadPool.join(pThread); + jobstepThreadPool.join(cThread); if (isEquality && fDec) { destroyEqualityFilter(); isEquality = false; diff --git a/dbcon/joblist/primitivestep.h b/dbcon/joblist/primitivestep.h index c1594b73a..5e1006e2c 100644 --- a/dbcon/joblist/primitivestep.h +++ b/dbcon/joblist/primitivestep.h @@ -321,8 +321,8 @@ private: BRM::DBRM dbrm; - boost::shared_ptr cThread; //consumer thread - boost::shared_ptr pThread; //producer thread + // boost::shared_ptr cThread; //consumer thread + // boost::shared_ptr pThread; //producer thread boost::mutex mutex; boost::condition condvar; boost::condition flushed; @@ -772,8 +772,8 @@ private: DataList *ridList; messageqcpp::ByteStream fFilterString; execplan::CalpontSystemCatalog::ColType colType; - boost::shared_ptr pThread; //producer thread - boost::shared_ptr cThread; //producer thread + uint64_t pThread; //producer thread. thread pool handle + uint64_t cThread; //consumer thread. thread pool handle DataList_t* requestList; //StringDataList* stringList; boost::mutex mutex; @@ -1036,8 +1036,6 @@ protected: private: void formatMiniStats(); - typedef boost::shared_ptr SPTHD; - typedef boost::shared_array SATHD; void startPrimitiveThread(); void startAggregationThread(); void initializeConfigParms(); @@ -1060,7 +1058,7 @@ private: uint32_t fNumThreads; PrimitiveStepType ffirstStepType; bool isFilterFeeder; - SATHD fProducerThread; + std::vector fProducerThreads; // thread pool handles messageqcpp::ByteStream fFilterString; uint32_t fFilterCount; execplan::CalpontSystemCatalog::ColType fColType; @@ -1097,8 +1095,8 @@ private: uint64_t fMsgBytesOut; // total byte count for outcoming messages uint64_t fBlockTouched; // total blocks touched uint32_t fExtentsPerSegFile;//config num of Extents Per Segment File - boost::shared_ptr cThread; //consumer thread - boost::shared_ptr pThread; //producer thread + // uint64_t cThread; //consumer thread. thread handle from thread pool + uint64_t pThread; //producer thread. thread handle from thread pool boost::mutex tplMutex; boost::mutex dlMutex; boost::mutex cpMutex; @@ -1251,7 +1249,7 @@ private: execplan::CalpontSystemCatalog::OID fTableOID; execplan::CalpontSystemCatalog::ColType fColType; int8_t fBOP; - boost::shared_ptr runner; // @bug 686 + // int64_t runner; // thread handle from thread pool // @bug 687 Add data and friend declarations for concurrent filter steps. std::vector fSortedA; // used to internally sort input data diff --git a/dbcon/joblist/subquerystep.cpp b/dbcon/joblist/subquerystep.cpp index fa3c6bfc1..3d227d05d 100644 --- a/dbcon/joblist/subquerystep.cpp +++ b/dbcon/joblist/subquerystep.cpp @@ -150,6 +150,7 @@ SubAdapterStep::SubAdapterStep(SJSTEP& s, const JobInfo& jobInfo) , fEndOfResult(false) , fInputIterator(0) , fOutputIterator(0) + , fRunner(0) { fAlias = s->alias(); fView = s->view(); @@ -191,14 +192,14 @@ void SubAdapterStep::run() if (fDelivery) fOutputIterator = fOutputDL->getIterator(); - fRunner.reset(new boost::thread(Runner(this))); + fRunner = jobstepThreadPool.invoke(Runner(this)); } void SubAdapterStep::join() { if (fRunner) - fRunner->join(); + jobstepThreadPool.join(fRunner); } diff --git a/dbcon/joblist/subquerystep.h b/dbcon/joblist/subquerystep.h index 4455e5915..f97cd501a 100644 --- a/dbcon/joblist/subquerystep.h +++ b/dbcon/joblist/subquerystep.h @@ -230,7 +230,7 @@ protected: SubAdapterStep* fStep; }; - boost::scoped_ptr fRunner; + uint64_t fRunner; // thread pool handle boost::scoped_ptr fExpression; }; diff --git a/dbcon/joblist/tuple-bps.cpp b/dbcon/joblist/tuple-bps.cpp index 166842595..ad5e90b82 100644 --- a/dbcon/joblist/tuple-bps.cpp +++ b/dbcon/joblist/tuple-bps.cpp @@ -180,14 +180,13 @@ void TupleBPS::initializeConfigParms() else fMaxNumThreads = 1; - fProducerThread.reset(new SPTHD[fMaxNumThreads]); - // Make maxnum thread objects even if they don't get used to make join() safe. - for (uint32_t i = 0; i < fMaxNumThreads; i++) - fProducerThread[i].reset(new thread()); + // Reserve the max number of thread space. A bit of an optimization. + fProducerThreads.clear(); + fProducerThreads.reserve(fMaxNumThreads); } TupleBPS::TupleBPS(const pColStep& rhs, const JobInfo& jobInfo) : - BatchPrimitive(jobInfo), fRm(jobInfo.rm) + BatchPrimitive(jobInfo), pThread(0), fRm(jobInfo.rm) { fInputJobStepAssociation = rhs.inputAssociation(); fOutputJobStepAssociation = rhs.outputAssociation(); @@ -800,7 +799,7 @@ void TupleBPS::storeCasualPartitionInfo(const bool estimateRowCounts) void TupleBPS::startPrimitiveThread() { - pThread.reset(new boost::thread(TupleBPSPrimitive(this))); + pThread = jobstepThreadPool.invoke(TupleBPSPrimitive(this)); } void TupleBPS::startAggregationThread() @@ -809,13 +808,13 @@ void TupleBPS::startAggregationThread() // fMaxNumThreads = 1; // fNumThreads = fMaxNumThreads; // for (uint32_t i = 0; i < fMaxNumThreads; i++) -// fProducerThread[i].reset(new boost::thread(TupleBPSAggregators(this, i))); +// fProducerThreads.push_back(jobstepThreadPool.invoke(TupleBPSAggregators(this, i))); // This block of code starts one thread at a time if (fNumThreads >= fMaxNumThreads) return; fNumThreads++; - fProducerThread[fNumThreads-1].reset(new boost::thread(TupleBPSAggregators(this, fNumThreads-1))); + fProducerThreads.push_back(jobstepThreadPool.invoke(TupleBPSAggregators(this, fNumThreads-1))); } //#include "boost/date_time/posix_time/posix_time.hpp" @@ -1117,6 +1116,8 @@ void TupleBPS::run() serializeJoiner(); prepCasualPartitioning(); startPrimitiveThread(); + fProducerThreads.clear(); + fProducerThreads.reserve(fMaxNumThreads); startAggregationThread(); } catch (const std::exception& e) @@ -1153,10 +1154,10 @@ void TupleBPS::join() } if (pThread) - pThread->join(); + jobstepThreadPool.join(pThread); + + jobstepThreadPool.join(fProducerThreads); - for (uint32_t i = 0; i < fMaxNumThreads; i++) - fProducerThread[i]->join(); if (BPPIsAllocated) { ByteStream bs; fDec->removeDECEventListener(this); diff --git a/dbcon/joblist/tupleaggregatestep.cpp b/dbcon/joblist/tupleaggregatestep.cpp index 5c4bdba0b..8f57d5e95 100644 --- a/dbcon/joblist/tupleaggregatestep.cpp +++ b/dbcon/joblist/tupleaggregatestep.cpp @@ -182,6 +182,7 @@ TupleAggregateStep::TupleAggregateStep( fAggregator(agg), fRowGroupOut(rgOut), fRowGroupIn(rgIn), + fRunner(0), fUmOnly(false), fRm(jobInfo.rm), fBucketNum(0), @@ -252,7 +253,7 @@ void TupleAggregateStep::run() { if (fDelivery == false) { - fRunner.reset(new thread(Aggregator(this))); + fRunner = jobstepThreadPool.invoke(Aggregator(this)); } } @@ -260,7 +261,7 @@ void TupleAggregateStep::run() void TupleAggregateStep::join() { if (fRunner) - fRunner->join(); + jobstepThreadPool.join(fRunner); } @@ -4210,8 +4211,7 @@ void TupleAggregateStep::threadedAggregateRowGroups(uint32_t threadID) // maximum number is reached. if (threadID == 0 && fFirstPhaseThreadCount < fNumOfThreads && dlIn->more(fInputIter)) { - fFirstPhaseRunners[fFirstPhaseThreadCount].reset - (new boost::thread(ThreadedAggregator(this, fFirstPhaseThreadCount))); + fFirstPhaseRunners.push_back(jobstepThreadPool.invoke(ThreadedAggregator(this, fFirstPhaseThreadCount))); fFirstPhaseThreadCount++; } @@ -4482,24 +4482,21 @@ uint64_t TupleAggregateStep::doThreadedAggregate(ByteStream& bs, RowGroupDL* dlp fFirstPhaseThreadCount = fNumOfThreads; boost::shared_ptr runner; for (i = 0; i < fNumOfThreads; i++) - { - runner.reset(new boost::thread(ThreadedAggregator(this, i))); - fFirstPhaseRunners.push_back(runner); + { + fFirstPhaseRunners.push_back(jobstepThreadPool.invoke(ThreadedAggregator(this, i))) } */ // This block of code starts one thread, relies on doThreadedAggregation() // to start more as needed - fFirstPhaseRunners.resize(fNumOfThreads); // to prevent a resize during use + fFirstPhaseRunners.clear(); + fFirstPhaseRunners.reserve(fNumOfThreads); // to prevent a resize during use fFirstPhaseThreadCount = 1; - for (i = 1; i < fNumOfThreads; i++) - // fill with valid thread objects to make joining work - fFirstPhaseRunners[i].reset(new boost::thread()); - fFirstPhaseRunners[0].reset(new boost::thread(ThreadedAggregator(this, 0))); + fFirstPhaseRunners.push_back(jobstepThreadPool.invoke(ThreadedAggregator(this, 0))); - for (i = 0; i < fNumOfThreads; i++) - fFirstPhaseRunners[i]->join(); - fFirstPhaseRunners.clear(); + // Now wait for that thread plus all the threads it may have spawned + jobstepThreadPool.join(fFirstPhaseRunners); + fFirstPhaseRunners.clear(); } if (dynamic_cast(fAggregator.get()) && fAggregator->aggMapKeyLength() > 0) @@ -4509,8 +4506,7 @@ uint64_t TupleAggregateStep::doThreadedAggregate(ByteStream& bs, RowGroupDL* dlp { if (!fDoneAggregate) { - vector > runners; - boost::shared_ptr runner; + vector runners; // thread pool handles fRowGroupsDeliveredData.resize(fNumOfBuckets); uint32_t bucketsPerThread = fNumOfBuckets/fNumOfThreads; @@ -4519,13 +4515,12 @@ uint64_t TupleAggregateStep::doThreadedAggregate(ByteStream& bs, RowGroupDL* dlp //uint32_t bucketsPerThread = 1; //uint32_t numThreads = fNumOfBuckets; + runners.reserve(numThreads); for (i = 0; i < numThreads; i++) { - runner.reset(new boost::thread(ThreadedSecondPhaseAggregator(this, i*bucketsPerThread, bucketsPerThread))); - runners.push_back(runner); + runners.push_back(jobstepThreadPool.invoke(ThreadedSecondPhaseAggregator(this, i*bucketsPerThread, bucketsPerThread))); } - for (i = 0; i < numThreads; i++) - runners[i]->join(); + jobstepThreadPool.join(runners); } fDoneAggregate = true; diff --git a/dbcon/joblist/tupleaggregatestep.h b/dbcon/joblist/tupleaggregatestep.h index c586b4646..0839e8263 100644 --- a/dbcon/joblist/tupleaggregatestep.h +++ b/dbcon/joblist/tupleaggregatestep.h @@ -166,7 +166,7 @@ private: uint32_t bucketCount; }; - boost::scoped_ptr fRunner; + uint64_t fRunner; // thread pool handle bool fUmOnly; ResourceManager *fRm; @@ -186,7 +186,7 @@ private: bool fIsMultiThread; int fInputIter; // iterator boost::scoped_array fMemUsage; - vector > fFirstPhaseRunners; + std::vector fFirstPhaseRunners; // thread pool handles uint32_t fFirstPhaseThreadCount; boost::shared_ptr fSessionMemLimit; diff --git a/dbcon/joblist/tupleannexstep.cpp b/dbcon/joblist/tupleannexstep.cpp index ea889a14f..7eead22a8 100644 --- a/dbcon/joblist/tupleannexstep.cpp +++ b/dbcon/joblist/tupleannexstep.cpp @@ -106,6 +106,7 @@ TupleAnnexStep::TupleAnnexStep(const JobInfo& jobInfo) : fOutputDL(NULL), fInputIterator(0), fOutputIterator(0), + fRunner(0), fRowsProcessed(0), fRowsReturned(0), fLimitStart(0), @@ -205,14 +206,14 @@ void TupleAnnexStep::run() fOutputIterator = fOutputDL->getIterator(); } - fRunner.reset(new boost::thread(Runner(this))); + fRunner = jobstepThreadPool.invoke(Runner(this)); } void TupleAnnexStep::join() { if (fRunner) - fRunner->join(); + jobstepThreadPool.join(fRunner); } diff --git a/dbcon/joblist/tupleannexstep.h b/dbcon/joblist/tupleannexstep.h index 69a16734c..2f548f179 100644 --- a/dbcon/joblist/tupleannexstep.h +++ b/dbcon/joblist/tupleannexstep.h @@ -111,7 +111,7 @@ protected: TupleAnnexStep* fStep; }; - boost::scoped_ptr fRunner; + uint64_t fRunner; // thread pool handle uint64_t fRowsProcessed; uint64_t fRowsReturned; diff --git a/dbcon/joblist/tupleconstantstep.cpp b/dbcon/joblist/tupleconstantstep.cpp index 327fd5e77..1b96cd83f 100644 --- a/dbcon/joblist/tupleconstantstep.cpp +++ b/dbcon/joblist/tupleconstantstep.cpp @@ -81,6 +81,7 @@ TupleConstantStep::TupleConstantStep(const JobInfo& jobInfo) : fInputDL(NULL), fOutputDL(NULL), fInputIterator(0), + fRunner(0), fEndOfResult(false) { fExtendedInfo = "TCS: "; @@ -290,7 +291,7 @@ void TupleConstantStep::run() if (fOutputDL == NULL) throw logic_error("Output is not a RowGroup data list."); - fRunner.reset(new boost::thread(Runner(this))); + fRunner = jobstepThreadPool.invoke(Runner(this)); } } @@ -298,7 +299,7 @@ void TupleConstantStep::run() void TupleConstantStep::join() { if (fRunner) - fRunner->join(); + jobstepThreadPool.join(fRunner); } diff --git a/dbcon/joblist/tupleconstantstep.h b/dbcon/joblist/tupleconstantstep.h index 994e63b05..85472aeca 100644 --- a/dbcon/joblist/tupleconstantstep.h +++ b/dbcon/joblist/tupleconstantstep.h @@ -101,7 +101,7 @@ protected: TupleConstantStep* fStep; }; - boost::scoped_ptr fRunner; + uint64_t fRunner; // thread pool handle bool fEndOfResult; }; diff --git a/dbcon/joblist/tuplehashjoin.cpp b/dbcon/joblist/tuplehashjoin.cpp index ef8bb388b..b1b9f8153 100644 --- a/dbcon/joblist/tuplehashjoin.cpp +++ b/dbcon/joblist/tuplehashjoin.cpp @@ -166,7 +166,7 @@ void TupleHashJoinStep::run() } joiners.resize(smallDLs.size()); - mainRunner.reset(new boost::thread(HJRunner(this))); + mainRunner = jobstepThreadPool.invoke(HJRunner(this)); } void TupleHashJoinStep::join() @@ -175,12 +175,12 @@ void TupleHashJoinStep::join() if (joinRan) return; joinRan = true; - mainRunner->join(); + jobstepThreadPool.join(mainRunner); if (djs) { for (int i = 0; i < (int) djsJoiners.size(); i++) djs[i].join(); - djsReader.join(); - djsRelay.join(); + jobstepThreadPool.join(djsReader); + jobstepThreadPool.join(djsRelay); //cout << "THJS: joined all DJS threads, shared usage = " << *djsSmallUsage << endl; } } @@ -544,9 +544,10 @@ void TupleHashJoinStep::hjRunner() } } + smallRunners.clear(); + smallRunners.reserve(smallDLs.size()); for (i = 0; i < smallDLs.size(); i++) - smallRunners.push_back(boost::shared_ptr - (new boost::thread(SmallRunner(this, i)))); + smallRunners.push_back(jobstepThreadPool.invoke(SmallRunner(this, i))); } catch (thread_resource_error&) { string emsg = "TupleHashJoin caught a thread resource error, aborting...\n"; @@ -557,8 +558,7 @@ void TupleHashJoinStep::hjRunner() deliverMutex.unlock(); } - for (i = 0; i < smallRunners.size(); i++) - smallRunners[i]->join(); + jobstepThreadPool.join(smallRunners); smallRunners.clear(); for (i = 0; i < feIndexes.size() && joiners.size() > 0; i++) @@ -629,9 +629,9 @@ void TupleHashJoinStep::hjRunner() /* If an error happened loading the existing data, these threads are necessary to finish the abort */ try { - djsRelay = boost::thread(DJSRelay(this)); + djsRelay = jobstepThreadPool.invoke(DJSRelay(this)); relay = true; - djsReader = boost::thread(DJSReader(this, smallSideCount)); + djsReader = jobstepThreadPool.invoke(DJSReader(this, smallSideCount)); reader = true; for (i = 0; i < smallSideCount; i++) djs[i].run(); @@ -1091,7 +1091,7 @@ void TupleHashJoinStep::startJoinThreads() bool more = true; RGData oneRG; - if (joinRunners) + if (joinRunners.size() > 0) return; //@bug4836, in error case, stop process, and unblock the next step. @@ -1142,13 +1142,11 @@ void TupleHashJoinStep::startJoinThreads() makeDupList(fe2 ? fe2Output : outputRG); /* Start join runners */ - joinRunners.reset(new boost::shared_ptr[joinThreadCount]); + joinRunners.reserve(joinThreadCount); for (i = 0; i < joinThreadCount; i++) - joinRunners[i].reset(new boost::thread(JoinRunner(this, i))); - + joinRunners.push_back(jobstepThreadPool.invoke(JoinRunner(this, i))); /* Join them and call endOfInput */ - for (i = 0; i < joinThreadCount; i++) - joinRunners[i]->join(); + jobstepThreadPool.join(joinRunners); if (lastSmallOuterJoiner != (uint32_t) -1) finishSmallOuterJoin(); diff --git a/dbcon/joblist/tuplehashjoin.h b/dbcon/joblist/tuplehashjoin.h index d56ad8441..833751396 100644 --- a/dbcon/joblist/tuplehashjoin.h +++ b/dbcon/joblist/tuplehashjoin.h @@ -276,8 +276,8 @@ private: uint32_t index; }; - boost::shared_ptr mainRunner; - std::vector > smallRunners; + int64_t mainRunner; // thread handle from thread pool + std::vector smallRunners; // thread handles from thread pool // for notify TupleAggregateStep PM hashjoin // Ideally, hashjoin and delivery communicate with RowGroupDL, @@ -347,7 +347,7 @@ private: void processDupList(uint32_t threadID, rowgroup::RowGroup &ingrp, std::vector *rowData); - boost::scoped_array > joinRunners; + std::vector joinRunners; // thread handles from thread pool boost::mutex inputDLLock, outputDLLock; boost::shared_array > columnMappings, fergMappings; boost::shared_array fe2Mapping; @@ -375,7 +375,7 @@ private: boost::scoped_array djs; boost::scoped_array > fifos; void djsReaderFcn(int index); - boost::thread djsReader; + uint64_t djsReader; // thread handle from thread pool struct DJSReader { DJSReader(TupleHashJoinStep *hj, uint32_t i) : HJ(hj), index(i) { } void operator()() { HJ->djsReaderFcn(index); } @@ -383,7 +383,7 @@ private: uint32_t index; }; - boost::thread djsRelay; + uint64_t djsRelay; // thread handle from thread pool void djsRelayFcn(); struct DJSRelay { DJSRelay(TupleHashJoinStep *hj) : HJ(hj) { } diff --git a/dbcon/joblist/tuplehavingstep.cpp b/dbcon/joblist/tuplehavingstep.cpp index d7196ef85..51e9cf88d 100644 --- a/dbcon/joblist/tuplehavingstep.cpp +++ b/dbcon/joblist/tuplehavingstep.cpp @@ -63,6 +63,7 @@ TupleHavingStep::TupleHavingStep(const JobInfo& jobInfo) : fInputDL(NULL), fOutputDL(NULL), fInputIterator(0), + fRunner(0), fRowsReturned(0), fEndOfResult(false), fFeInstance(funcexp::FuncExp::instance()) @@ -151,7 +152,7 @@ void TupleHavingStep::run() if (fOutputDL == NULL) throw logic_error("Output is not a RowGroup data list."); - fRunner.reset(new boost::thread(Runner(this))); + fRunner = jobstepThreadPool.invoke(Runner(this)); } } @@ -159,7 +160,7 @@ void TupleHavingStep::run() void TupleHavingStep::join() { if (fRunner) - fRunner->join(); + jobstepThreadPool.join(fRunner); } diff --git a/dbcon/joblist/tuplehavingstep.h b/dbcon/joblist/tuplehavingstep.h index 1e3467b61..e76ca7898 100644 --- a/dbcon/joblist/tuplehavingstep.h +++ b/dbcon/joblist/tuplehavingstep.h @@ -97,7 +97,7 @@ protected: TupleHavingStep* fStep; }; - boost::scoped_ptr fRunner; + uint64_t fRunner; // thread pool handle uint64_t fRowsReturned; bool fEndOfResult; diff --git a/dbcon/joblist/tupleunion.cpp b/dbcon/joblist/tupleunion.cpp index 370f09d6e..1a2e37d93 100644 --- a/dbcon/joblist/tupleunion.cpp +++ b/dbcon/joblist/tupleunion.cpp @@ -767,9 +767,9 @@ void TupleUnion::run() } } + runners.reserve(inputs.size()); for (i = 0; i < inputs.size(); i++) { - boost::shared_ptr th(new boost::thread(Runner(this, i))); - runners.push_back(th); + runners.push_back(jobstepThreadPool.invoke(Runner(this, i))); } } @@ -784,8 +784,7 @@ void TupleUnion::join() joinRan = true; lk.unlock(); - for (i = 0; i < runners.size(); i++) - runners[i]->join(); + jobstepThreadPool.join(runners); runners.clear(); uniquer->clear(); rowMemory.clear(); diff --git a/dbcon/joblist/tupleunion.h b/dbcon/joblist/tupleunion.h index 3f4440d11..17498a305 100644 --- a/dbcon/joblist/tupleunion.h +++ b/dbcon/joblist/tupleunion.h @@ -118,7 +118,7 @@ private: Runner(TupleUnion *t, uint32_t in) : tu(t), index(in) { } void operator()() { tu->readInput(index); } }; - std::vector > runners; + std::vector runners; //thread pool handles struct Hasher { TupleUnion *ts; diff --git a/dbcon/joblist/windowfunctionstep.cpp b/dbcon/joblist/windowfunctionstep.cpp index ec37573d8..7f3a8c29d 100644 --- a/dbcon/joblist/windowfunctionstep.cpp +++ b/dbcon/joblist/windowfunctionstep.cpp @@ -140,6 +140,7 @@ namespace joblist WindowFunctionStep::WindowFunctionStep(const JobInfo& jobInfo) : JobStep(jobInfo), + fRunner(0), fCatalog(jobInfo.csc), fRowsReturned(0), fEndOfResult(false), @@ -192,14 +193,14 @@ void WindowFunctionStep::run() fOutputIterator = fOutputDL->getIterator(); } - fRunner.reset(new boost::thread(Runner(this))); + fRunner = jobstepThreadPool.invoke(Runner(this)); } void WindowFunctionStep::join() { if (fRunner) - fRunner->join(); + jobstepThreadPool.join(fRunner); } @@ -855,13 +856,13 @@ void WindowFunctionStep::execute() if (fTotalThreads > fFunctionCount) fTotalThreads = fFunctionCount; + fFunctionThreads.clear(); + fFunctionThreads.reserve(fTotalThreads); for (uint64_t i = 0; i < fTotalThreads && !cancelled(); i++) - fFunctionThreads.push_back( - boost::shared_ptr(new boost::thread(WFunction(this)))); + fFunctionThreads.push_back(jobstepThreadPool.invoke(WFunction(this))); - // If cancelled, not all thread is started. - for (uint64_t i = 0; i < fFunctionThreads.size(); i++) - fFunctionThreads[i]->join(); + // If cancelled, not all threads are started. + jobstepThreadPool.join(fFunctionThreads); } if (!(cancelled())) diff --git a/dbcon/joblist/windowfunctionstep.h b/dbcon/joblist/windowfunctionstep.h index 027b6eae3..73d47bacd 100644 --- a/dbcon/joblist/windowfunctionstep.h +++ b/dbcon/joblist/windowfunctionstep.h @@ -153,7 +153,7 @@ private: WindowFunctionStep* fStep; }; - boost::scoped_ptr fRunner; + uint64_t fRunner; // thread pool handle boost::shared_ptr fCatalog; uint64_t fRowsReturned; @@ -188,7 +188,7 @@ private: WindowFunctionStep* fStep; }; - std::vector > fFunctionThreads; + std::vector fFunctionThreads; std::vector fRows; std::vector > fFunctions; diff --git a/exemgr/main.cpp b/exemgr/main.cpp index 8ccebcba5..2f6a6d431 100644 --- a/exemgr/main.cpp +++ b/exemgr/main.cpp @@ -1438,7 +1438,8 @@ int main(int argc, char* argv[]) { IOSocket ios; ios = mqs->accept(); - exeMgrThreadPool.invoke(SessionThread(ios, ec, rm)); + boost::thread thd(SessionThread(ios, ec, rm)); + //exeMgrThreadPool.invoke(SessionThread(ios, ec, rm)); } exeMgrThreadPool.wait(); diff --git a/utils/threadpool/threadpool.cpp b/utils/threadpool/threadpool.cpp index d4ea02565..644e9d098 100644 --- a/utils/threadpool/threadpool.cpp +++ b/utils/threadpool/threadpool.cpp @@ -177,10 +177,10 @@ void ThreadPool::join(std::vector thrHandle) } } -int64_t ThreadPool::invoke(const Functor_T &threadfunc) +uint64_t ThreadPool::invoke(const Functor_T &threadfunc) { boost::mutex::scoped_lock lock1(fMutex); - int64_t thrHandle=0; + uint64_t thrHandle=0; for(;;) { @@ -210,6 +210,22 @@ int64_t ThreadPool::invoke(const Functor_T &threadfunc) lock1.unlock(); fThreads.create_thread(beginThreadFunc(*this)); + + if (fDebug) + { + logging::Message::Args args; + logging::Message message(5); + args.add("invoke: Starting thread "); + args.add(fThreadCount); + args.add(" max "); + args.add(fMaxThreads); + args.add(" queue "); + args.add(fQueueSize); + message.format( args ); + logging::LoggingID lid(22); + logging::MessageLog ml(lid); + ml.logWarningMessage( message ); + } if (bAdded) break; @@ -227,7 +243,20 @@ int64_t ThreadPool::invoke(const Functor_T &threadfunc) break; } - fThreadAvailable.wait(lock1); + if (fDebug) + { + logging::Message::Args args; + logging::Message message(5); + args.add("invoke: Blocked waiting for thread. Count "); + args.add(fThreadCount); + args.add("max "); + args.add(fMaxThreads); + message.format( args ); + logging::LoggingID lid(22); + logging::MessageLog ml(lid); + ml.logWarningMessage( message ); + fThreadAvailable.wait(lock1); + } } catch(...) { @@ -358,7 +387,7 @@ void ThreadPool::beginThread() throw() } } -int64_t ThreadPool::addFunctor(const Functor_T &func) +uint64_t ThreadPool::addFunctor(const Functor_T &func) { bool bAtEnd = false; diff --git a/utils/threadpool/threadpool.h b/utils/threadpool/threadpool.h index dd5f13b56..7616090fe 100644 --- a/utils/threadpool/threadpool.h +++ b/utils/threadpool/threadpool.h @@ -131,7 +131,7 @@ public: * queueSize tasks already waiting, invoke() will block until a slot in the * queue comes free. */ - EXPORT int64_t invoke(const Functor_T &threadfunc); + EXPORT uint64_t invoke(const Functor_T &threadfunc); /** @brief stop the threads */ @@ -153,13 +153,15 @@ public: */ EXPORT void dump(); + EXPORT void setDebug(bool d) {fDebug = d;} + protected: private: // Used internally to keep a handle associated with each functor for join() struct PoolFunction_T { - int64_t hndl; + uint64_t hndl; Functor_T functor; }; @@ -169,7 +171,7 @@ private: /** @brief add a functor to the list */ - int64_t addFunctor(const Functor_T &func); + uint64_t addFunctor(const Functor_T &func); /** @brief thread entry point */ @@ -222,6 +224,7 @@ private: uint32_t waitingFunctorsSize; uint64_t fNextHandle; + bool fDebug; }; } // namespace threadpool From babaac81723f3596cfd07d4a19ce7acb132af425 Mon Sep 17 00:00:00 2001 From: Andrew Hutchings Date: Thu, 12 Jan 2017 17:12:39 +0000 Subject: [PATCH 13/35] MCOL-317 Remove libdrizzle This switches to MariaDB's client library instead of libdrizzle for Cross Engine and query stats. It also switches to unbuffered result sets. --- CMakeLists.txt | 9 +- dbcon/joblist/CMakeLists.txt | 2 +- dbcon/joblist/crossenginestep.cpp | 100 +- dbcon/joblist/crossenginestep.h | 29 +- dbcon/joblist/jlf_graphics.cpp | 3 +- dbcon/joblist/jlf_tuplejoblist.cpp | 4 +- dbcon/joblist/joblist.cpp | 4 +- dbcon/joblist/tupleaggregatestep.cpp | 4 +- utils/CMakeLists.txt | 1 - utils/mysqlcl_idb/CMakeLists.txt | 27 - utils/mysqlcl_idb/Makefile.am | 54 - utils/mysqlcl_idb/column.cc | 1208 ------------ utils/mysqlcl_idb/command.cc | 254 --- utils/mysqlcl_idb/conn.cc | 1733 ----------------- utils/mysqlcl_idb/conn_uds.cc | 79 - utils/mysqlcl_idb/drizzle.cc | 761 -------- utils/mysqlcl_idb/field.cc | 396 ---- utils/mysqlcl_idb/handshake.cc | 612 ------ utils/mysqlcl_idb/libdrizzle-2.0/column.h | 176 -- .../libdrizzle-2.0/column_client.h | 125 -- .../libdrizzle-2.0/column_server.h | 149 -- utils/mysqlcl_idb/libdrizzle-2.0/command.h | 102 - .../libdrizzle-2.0/command_client.h | 61 - .../libdrizzle-2.0/command_server.h | 60 - utils/mysqlcl_idb/libdrizzle-2.0/common.h | 94 - utils/mysqlcl_idb/libdrizzle-2.0/conn.h | 436 ----- .../mysqlcl_idb/libdrizzle-2.0/conn_client.h | 192 -- utils/mysqlcl_idb/libdrizzle-2.0/conn_local.h | 118 -- .../mysqlcl_idb/libdrizzle-2.0/conn_server.h | 224 --- utils/mysqlcl_idb/libdrizzle-2.0/constants.h | 474 ----- .../libdrizzle-2.0/deprecated_enum.h | 67 - utils/mysqlcl_idb/libdrizzle-2.0/drizzle.h | 397 ---- .../libdrizzle-2.0/drizzle_client.h | 113 -- .../libdrizzle-2.0/drizzle_local.h | 163 -- .../libdrizzle-2.0/drizzle_server.h | 127 -- .../mysqlcl_idb/libdrizzle-2.0/field_client.h | 85 - .../mysqlcl_idb/libdrizzle-2.0/field_server.h | 65 - .../libdrizzle-2.0/handshake_client.h | 82 - .../libdrizzle-2.0/handshake_server.h | 80 - utils/mysqlcl_idb/libdrizzle-2.0/libdrizzle.h | 36 - .../mysqlcl_idb/libdrizzle-2.0/libdrizzle.hpp | 385 ---- utils/mysqlcl_idb/libdrizzle-2.0/limits.h | 56 - utils/mysqlcl_idb/libdrizzle-2.0/pack.h | 93 - utils/mysqlcl_idb/libdrizzle-2.0/query.h | 239 --- utils/mysqlcl_idb/libdrizzle-2.0/result.h | 155 -- .../libdrizzle-2.0/result_client.h | 80 - .../libdrizzle-2.0/result_server.h | 141 -- utils/mysqlcl_idb/libdrizzle-2.0/return.h | 78 - utils/mysqlcl_idb/libdrizzle-2.0/row_client.h | 130 -- utils/mysqlcl_idb/libdrizzle-2.0/row_server.h | 66 - utils/mysqlcl_idb/libdrizzle-2.0/sha1.h | 44 - utils/mysqlcl_idb/libdrizzle-2.0/state.h | 108 - utils/mysqlcl_idb/libdrizzle-2.0/structs.h | 403 ---- utils/mysqlcl_idb/libdrizzle-2.0/verbose.h | 58 - utils/mysqlcl_idb/libdrizzle-2.0/visibility.h | 78 - utils/mysqlcl_idb/libmysqlcl_idb.vcxproj | 235 --- .../libmysqlcl_idb.vcxproj.filters | 171 -- utils/mysqlcl_idb/mysqlcl_idb.vpj | 153 -- utils/mysqlcl_idb/pack.cc | 336 ---- utils/mysqlcl_idb/query.cc | 545 ------ utils/mysqlcl_idb/result.cc | 803 -------- utils/mysqlcl_idb/row.cc | 272 --- utils/mysqlcl_idb/sha1.cc | 179 -- utils/mysqlcl_idb/state.cc | 100 - utils/mysqlcl_idb/tdriver-works.cpp | 122 -- utils/mysqlcl_idb/tdriver.cpp | 114 -- utils/mysqlcl_idb/tdriver1.cpp | 53 - utils/querystats/CMakeLists.txt | 2 + utils/querystats/querystats.cpp | 91 +- 69 files changed, 112 insertions(+), 13884 deletions(-) delete mode 100644 utils/mysqlcl_idb/CMakeLists.txt delete mode 100644 utils/mysqlcl_idb/Makefile.am delete mode 100644 utils/mysqlcl_idb/column.cc delete mode 100644 utils/mysqlcl_idb/command.cc delete mode 100644 utils/mysqlcl_idb/conn.cc delete mode 100644 utils/mysqlcl_idb/conn_uds.cc delete mode 100644 utils/mysqlcl_idb/drizzle.cc delete mode 100644 utils/mysqlcl_idb/field.cc delete mode 100644 utils/mysqlcl_idb/handshake.cc delete mode 100644 utils/mysqlcl_idb/libdrizzle-2.0/column.h delete mode 100644 utils/mysqlcl_idb/libdrizzle-2.0/column_client.h delete mode 100644 utils/mysqlcl_idb/libdrizzle-2.0/column_server.h delete mode 100644 utils/mysqlcl_idb/libdrizzle-2.0/command.h delete mode 100644 utils/mysqlcl_idb/libdrizzle-2.0/command_client.h delete mode 100644 utils/mysqlcl_idb/libdrizzle-2.0/command_server.h delete mode 100644 utils/mysqlcl_idb/libdrizzle-2.0/common.h delete mode 100644 utils/mysqlcl_idb/libdrizzle-2.0/conn.h delete mode 100644 utils/mysqlcl_idb/libdrizzle-2.0/conn_client.h delete mode 100644 utils/mysqlcl_idb/libdrizzle-2.0/conn_local.h delete mode 100644 utils/mysqlcl_idb/libdrizzle-2.0/conn_server.h delete mode 100644 utils/mysqlcl_idb/libdrizzle-2.0/constants.h delete mode 100644 utils/mysqlcl_idb/libdrizzle-2.0/deprecated_enum.h delete mode 100644 utils/mysqlcl_idb/libdrizzle-2.0/drizzle.h delete mode 100644 utils/mysqlcl_idb/libdrizzle-2.0/drizzle_client.h delete mode 100644 utils/mysqlcl_idb/libdrizzle-2.0/drizzle_local.h delete mode 100644 utils/mysqlcl_idb/libdrizzle-2.0/drizzle_server.h delete mode 100644 utils/mysqlcl_idb/libdrizzle-2.0/field_client.h delete mode 100644 utils/mysqlcl_idb/libdrizzle-2.0/field_server.h delete mode 100644 utils/mysqlcl_idb/libdrizzle-2.0/handshake_client.h delete mode 100644 utils/mysqlcl_idb/libdrizzle-2.0/handshake_server.h delete mode 100644 utils/mysqlcl_idb/libdrizzle-2.0/libdrizzle.h delete mode 100644 utils/mysqlcl_idb/libdrizzle-2.0/libdrizzle.hpp delete mode 100644 utils/mysqlcl_idb/libdrizzle-2.0/limits.h delete mode 100644 utils/mysqlcl_idb/libdrizzle-2.0/pack.h delete mode 100644 utils/mysqlcl_idb/libdrizzle-2.0/query.h delete mode 100644 utils/mysqlcl_idb/libdrizzle-2.0/result.h delete mode 100644 utils/mysqlcl_idb/libdrizzle-2.0/result_client.h delete mode 100644 utils/mysqlcl_idb/libdrizzle-2.0/result_server.h delete mode 100644 utils/mysqlcl_idb/libdrizzle-2.0/return.h delete mode 100644 utils/mysqlcl_idb/libdrizzle-2.0/row_client.h delete mode 100644 utils/mysqlcl_idb/libdrizzle-2.0/row_server.h delete mode 100644 utils/mysqlcl_idb/libdrizzle-2.0/sha1.h delete mode 100644 utils/mysqlcl_idb/libdrizzle-2.0/state.h delete mode 100644 utils/mysqlcl_idb/libdrizzle-2.0/structs.h delete mode 100644 utils/mysqlcl_idb/libdrizzle-2.0/verbose.h delete mode 100644 utils/mysqlcl_idb/libdrizzle-2.0/visibility.h delete mode 100644 utils/mysqlcl_idb/libmysqlcl_idb.vcxproj delete mode 100644 utils/mysqlcl_idb/libmysqlcl_idb.vcxproj.filters delete mode 100644 utils/mysqlcl_idb/mysqlcl_idb.vpj delete mode 100644 utils/mysqlcl_idb/pack.cc delete mode 100644 utils/mysqlcl_idb/query.cc delete mode 100644 utils/mysqlcl_idb/result.cc delete mode 100644 utils/mysqlcl_idb/row.cc delete mode 100644 utils/mysqlcl_idb/sha1.cc delete mode 100644 utils/mysqlcl_idb/state.cc delete mode 100644 utils/mysqlcl_idb/tdriver-works.cpp delete mode 100644 utils/mysqlcl_idb/tdriver.cpp delete mode 100644 utils/mysqlcl_idb/tdriver1.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index e5e8a96cc..2af81bead 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -57,7 +57,7 @@ SET(CMAKE_SKIP_BUILD_RPATH FALSE) # (but later on when installing) SET(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE) -SET(CMAKE_INSTALL_RPATH "${INSTALL_ENGINE}/lib") +SET(CMAKE_INSTALL_RPATH "${INSTALL_ENGINE}/lib;${INSTALL_ENGINE}/mysql/lib") # add the automatically determined parts of the RPATH # which point to directories outside the build tree to the install RPATH @@ -69,6 +69,11 @@ IF("${isSystemDir}" STREQUAL "-1") SET(CMAKE_INSTALL_RPATH "${INSTALL_ENGINE}/lib") ENDIF("${isSystemDir}" STREQUAL "-1") +LIST(FIND CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES "${SERVER_SOURCE_ROOT_DIR}/libmysql/" isSystemDir) +IF("${isSystemDir}" STREQUAL "-1") + SET(CMAKE_INSTALL_RPATH "${INSTALL_ENGINE}/mysql/lib") +ENDIF("${isSystemDir}" STREQUAL "-1") + INCLUDE (configureEngine.cmake) CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/build/releasenum.in ${CMAKE_CURRENT_BINARY_DIR}/build/releasenum @ONLY IMMEDIATE) @@ -130,7 +135,7 @@ SET (ENGINE_TOOLSDIR "${INSTALL_ENGINE}/tools") SET (ENGINE_COMMON_LIBS messageqcpp loggingcpp configcpp idbboot ${Boost_LIBRARIES} xml2 pthread rt) SET (ENGINE_OAM_LIBS oamcpp alarmmanager) SET (ENGINE_BRM_LIBS brm idbdatafile cacheutils rwlock ${ENGINE_OAM_LIBS} ${ENGINE_COMMON_LIBS}) -SET (ENGINE_EXEC_LIBS joblist execplan windowfunction joiner rowgroup funcexp udfsdk dataconvert common compress mysqlcl_idb querystats querytele thrift threadpool ${ENGINE_BRM_LIBS}) +SET (ENGINE_EXEC_LIBS joblist execplan windowfunction joiner rowgroup funcexp udfsdk dataconvert common compress querystats querytele thrift threadpool ${ENGINE_BRM_LIBS}) SET (ENGINE_WRITE_LIBS ddlpackageproc ddlpackage dmlpackageproc dmlpackage writeengine writeengineclient idbdatafile cacheutils ${ENGINE_EXEC_LIBS}) SET (ENGINE_COMMON_LDFLAGS "") diff --git a/dbcon/joblist/CMakeLists.txt b/dbcon/joblist/CMakeLists.txt index 989c3b798..bebe6584a 100644 --- a/dbcon/joblist/CMakeLists.txt +++ b/dbcon/joblist/CMakeLists.txt @@ -61,7 +61,7 @@ set(joblist_LIB_SRCS add_library(joblist SHARED ${joblist_LIB_SRCS}) -target_link_libraries(joblist ${NETSNMP_LIBRARIES}) +target_link_libraries(joblist ${NETSNMP_LIBRARIES} -L${SERVER_SOURCE_ROOT_DIR}/libmysql/ libmysqlclient_r.so) set_target_properties(joblist PROPERTIES VERSION 1.0.0 SOVERSION 1) diff --git a/dbcon/joblist/crossenginestep.cpp b/dbcon/joblist/crossenginestep.cpp index 0b8b276a9..1b498c7b2 100644 --- a/dbcon/joblist/crossenginestep.cpp +++ b/dbcon/joblist/crossenginestep.cpp @@ -17,6 +17,7 @@ // $Id: crossenginestep.cpp 9709 2013-07-20 06:08:46Z xlou $ +#include "crossenginestep.h" #include //#define NDEBUG #include @@ -55,89 +56,68 @@ using namespace querytele; #include "jobstep.h" #include "jlf_common.h" -#include "crossenginestep.h" - -#include "libdrizzle-2.0/drizzle.h" -#include "libdrizzle-2.0/drizzle_client.h" namespace joblist { -DrizzleMySQL::DrizzleMySQL() : fDrzp(NULL), fDrzcp(NULL), fDrzrp(NULL) +LibMySQL::LibMySQL() : fCon(NULL), fRes(NULL) { } -DrizzleMySQL::~DrizzleMySQL() +LibMySQL::~LibMySQL() { - if (fDrzrp) + if (fRes) { - drizzle_result_free(fDrzrp); + mysql_free_result(fRes); } - fDrzrp = NULL; + fRes = NULL; - if (fDrzcp) + if (fCon) { - drizzle_con_close(fDrzcp); - drizzle_con_free(fDrzcp); + mysql_close(fCon); } - fDrzcp = NULL; - - if (fDrzp) - { - drizzle_free(fDrzp); - } - fDrzp = NULL; + fCon = NULL; } -int DrizzleMySQL::init(const char* h, unsigned int p, const char* u, const char* w, const char* d) +int LibMySQL::init(const char* h, unsigned int p, const char* u, const char* w, const char* d) { - int ret = -1; + int ret = 0; - fDrzp = drizzle_create(); - if (fDrzp != NULL) + fCon = mysql_init(NULL); + if (fCon != NULL) { - fDrzcp = drizzle_con_add_tcp(fDrzp, h, p, u, w, d, DRIZZLE_CON_MYSQL); - if (fDrzcp != NULL) + if (mysql_real_connect(fCon, h, u, w, d, p, NULL, 0) == NULL) { - ret = drizzle_con_connect(fDrzcp); - if (ret != 0) - fErrStr = "fatal error in drizzle_con_connect()"; - } - else - { - fErrStr = "fatal error in drizzle_con_add_tcp()"; + fErrStr = "fatal error in mysql_real_connect()"; + ret = mysql_errno(fCon); } } else { - fErrStr = "fatal error in drizzle_create()"; + fErrStr = "fatal error in mysql_init()"; + ret = -1; } return ret; } -int DrizzleMySQL::run(const char* query) +int LibMySQL::run(const char* query) { int ret = 0; - drizzle_return_t drzret; - fDrzrp = drizzle_query_str(fDrzcp, fDrzrp, query, &drzret); - if (drzret == 0 && fDrzrp != NULL) + if (mysql_query(fCon, query) != 0) { - ret = drzret = drizzle_result_buffer(fDrzrp); - if (drzret != 0) - fErrStr = "fatal error reading result from crossengine client lib"; - } - else - { - fErrStr = "fatal error executing query in crossengine client lib"; - if (drzret != 0) - ret = drzret; - else - ret = -1; + fErrStr = "fatal error reading result from crossengine client lib"; + ret = -1; } + fRes = mysql_use_result(fCon); + if (fRes == NULL) + { + fErrStr = "fatal error reading result from crossengine client lib"; + ret = -1; + } return ret; } @@ -165,13 +145,13 @@ CrossEngineStep::CrossEngineStep( fExtendedInfo = "CES: "; getMysqldInfo(jobInfo); fQtc.stepParms().stepType = StepTeleStats::T_CES; - drizzle = new DrizzleMySQL(); + mysql = new LibMySQL(); } CrossEngineStep::~CrossEngineStep() { - delete drizzle; + delete mysql; } @@ -464,20 +444,20 @@ void CrossEngineStep::execute() sts.total_units_of_work = 1; postStepStartTele(sts); - ret = drizzle->init(fHost.c_str(), fPort, fUser.c_str(), fPasswd.c_str(), fSchema.c_str()); + ret = mysql->init(fHost.c_str(), fPort, fUser.c_str(), fPasswd.c_str(), fSchema.c_str()); if (ret != 0) - handleMySqlError(drizzle->getError().c_str(), ret); + handleMySqlError(mysql->getError().c_str(), ret); string query(makeQuery()); fLogger->logMessage(logging::LOG_TYPE_INFO, "QUERY to foreign engine: " + query); if (traceOn()) cout << "QUERY: " << query << endl; - ret = drizzle->run(query.c_str()); + ret = mysql->run(query.c_str()); if (ret != 0) - handleMySqlError(drizzle->getError().c_str(), ret); + handleMySqlError(mysql->getError().c_str(), ret); - int num_fields = drizzle->getFieldCount(); + int num_fields = mysql->getFieldCount(); char** rowIn; // input //shared_array rgDataDelivered; // output @@ -498,7 +478,7 @@ void CrossEngineStep::execute() bool doFE3 = (fFeSelects.size() > 0); if (!doFE1 && !doFE3) { - while ((rowIn = drizzle->nextRow()) && !cancelled()) + while ((rowIn = mysql->nextRow()) && !cancelled()) { for(int i = 0; i < num_fields; i++) setField(i, rowIn[i], fRowDelivered); @@ -515,7 +495,7 @@ void CrossEngineStep::execute() rgDataFe1.reset(new uint8_t[rowFe1.getSize()]); rowFe1.setData(rgDataFe1.get()); - while ((rowIn = drizzle->nextRow()) && !cancelled()) + while ((rowIn = mysql->nextRow()) && !cancelled()) { // Parse the columns used in FE1 first, the other column may not need be parsed. for(int i = 0; i < num_fields; i++) @@ -550,7 +530,7 @@ void CrossEngineStep::execute() rgDataFe3.reset(new uint8_t[rowFe3.getSize()]); rowFe3.setData(rgDataFe3.get()); - while ((rowIn = drizzle->nextRow()) && !cancelled()) + while ((rowIn = mysql->nextRow()) && !cancelled()) { for(int i = 0; i < num_fields; i++) setField(i, rowIn[i], rowFe3); @@ -578,7 +558,7 @@ void CrossEngineStep::execute() rgDataFe3.reset(new uint8_t[rowFe3.getSize()]); rowFe3.setData(rgDataFe3.get()); - while ((rowIn = drizzle->nextRow()) && !cancelled()) + while ((rowIn = mysql->nextRow()) && !cancelled()) { // Parse the columns used in FE1 first, the other column may not need be parsed. for(int i = 0; i < num_fields; i++) @@ -610,7 +590,7 @@ void CrossEngineStep::execute() //INSERT_ADAPTER(fOutputDL, rgDataDelivered); fOutputDL->insert(rgDataDelivered); - fRowsRetrieved = drizzle->getRowCount(); + fRowsRetrieved = mysql->getRowCount(); } catch (IDBExcept& iex) { diff --git a/dbcon/joblist/crossenginestep.h b/dbcon/joblist/crossenginestep.h index 1d4772165..bdbba656b 100644 --- a/dbcon/joblist/crossenginestep.h +++ b/dbcon/joblist/crossenginestep.h @@ -21,13 +21,15 @@ #ifndef JOBLIST_CROSSENGINESTEP_H #define JOBLIST_CROSSENGINESTEP_H +#include +#include + #include #include "jobstep.h" #include "primitivestep.h" -#include "libdrizzle-2.0/drizzle.h" -#include "libdrizzle-2.0/drizzle_client.h" +using namespace std; // forward reference namespace execplan @@ -44,11 +46,11 @@ class FuncExp; namespace joblist { -class DrizzleMySQL +class LibMySQL { public: - DrizzleMySQL(); - ~DrizzleMySQL(); + LibMySQL(); + ~LibMySQL(); // init: host port username passwd db int init(const char*, unsigned int, const char*, const char*, const char*); @@ -56,16 +58,15 @@ public: // run the query int run(const char* q); - int getFieldCount() { return drizzle_result_column_count(fDrzrp); } - int getRowCount() { return drizzle_result_row_count(fDrzrp); } - char** nextRow() { return drizzle_row_next(fDrzrp); } - const string& getError() { return fErrStr; } + int getFieldCount() { return mysql_num_fields(fRes); } + int getRowCount() { return mysql_num_rows(fRes); } + char** nextRow() { return mysql_fetch_row(fRes); } + const std::string& getError() { return fErrStr; } private: - drizzle_st* fDrzp; - drizzle_con_st* fDrzcp; - drizzle_result_st* fDrzrp; - string fErrStr; + MYSQL* fCon; + MYSQL_RES* fRes; + std::string fErrStr; }; /** @brief class CrossEngineStep @@ -212,7 +213,7 @@ protected: rowgroup::RowGroup fRowGroupFe3; funcexp::FuncExp* fFeInstance; - DrizzleMySQL* drizzle; + LibMySQL* mysql; }; diff --git a/dbcon/joblist/jlf_graphics.cpp b/dbcon/joblist/jlf_graphics.cpp index c81898ee3..59837069f 100644 --- a/dbcon/joblist/jlf_graphics.cpp +++ b/dbcon/joblist/jlf_graphics.cpp @@ -17,12 +17,13 @@ // $Id: jlf_graphics.cpp 9550 2013-05-17 23:58:07Z xlou $ +// Cross engine at the top due to MySQL includes +#include "crossenginestep.h" #include using namespace std; #include "joblist.h" #include "primitivestep.h" -#include "crossenginestep.h" #include "subquerystep.h" #include "windowfunctionstep.h" #include "tupleaggregatestep.h" diff --git a/dbcon/joblist/jlf_tuplejoblist.cpp b/dbcon/joblist/jlf_tuplejoblist.cpp index ed9bacc99..efac6ea8f 100644 --- a/dbcon/joblist/jlf_tuplejoblist.cpp +++ b/dbcon/joblist/jlf_tuplejoblist.cpp @@ -17,7 +17,8 @@ // $Id: jlf_tuplejoblist.cpp 9728 2013-07-26 22:08:20Z xlou $ - +// Cross engine needs to be at the top due to MySQL includes +#include "crossenginestep.h" #include #include #include @@ -55,7 +56,6 @@ using namespace dataconvert; #include "limitedorderby.h" #include "jobstep.h" #include "primitivestep.h" -#include "crossenginestep.h" #include "expressionstep.h" #include "subquerystep.h" #include "tupleaggregatestep.h" diff --git a/dbcon/joblist/joblist.cpp b/dbcon/joblist/joblist.cpp index d82689b06..833c4447d 100644 --- a/dbcon/joblist/joblist.cpp +++ b/dbcon/joblist/joblist.cpp @@ -18,7 +18,8 @@ // $Id: joblist.cpp 9655 2013-06-25 23:08:13Z xlou $ - +// Cross engine needs to be at the top due to MySQL includes +#include "crossenginestep.h" #include "errorcodes.h" #include #include @@ -34,7 +35,6 @@ using namespace execplan; #include "errorids.h" #include "jobstep.h" #include "primitivestep.h" -#include "crossenginestep.h" #include "subquerystep.h" #include "tupleaggregatestep.h" #include "tupleannexstep.h" diff --git a/dbcon/joblist/tupleaggregatestep.cpp b/dbcon/joblist/tupleaggregatestep.cpp index 8f57d5e95..ced92856d 100644 --- a/dbcon/joblist/tupleaggregatestep.cpp +++ b/dbcon/joblist/tupleaggregatestep.cpp @@ -19,6 +19,9 @@ //#define NDEBUG +// Cross engine needs to be at top due to MySQL includes +#include "crossenginestep.h" + #include #include #include @@ -61,7 +64,6 @@ using namespace querytele; #include "primitivestep.h" #include "subquerystep.h" #include "tuplehashjoin.h" -#include "crossenginestep.h" #include "tupleaggregatestep.h" //#include "stopwatch.cpp" diff --git a/utils/CMakeLists.txt b/utils/CMakeLists.txt index 744f6b40e..d12f37864 100644 --- a/utils/CMakeLists.txt +++ b/utils/CMakeLists.txt @@ -16,7 +16,6 @@ add_subdirectory(udfsdk) add_subdirectory(compress) add_subdirectory(batchloader) add_subdirectory(ddlcleanup) -add_subdirectory(mysqlcl_idb) add_subdirectory(querystats) add_subdirectory(windowfunction) add_subdirectory(idbdatafile) diff --git a/utils/mysqlcl_idb/CMakeLists.txt b/utils/mysqlcl_idb/CMakeLists.txt deleted file mode 100644 index 0ef0b5f97..000000000 --- a/utils/mysqlcl_idb/CMakeLists.txt +++ /dev/null @@ -1,27 +0,0 @@ - -include_directories( /usr/include/libxml2 ${ENGINE_COMMON_INCLUDES} ) - - -########### next target ############### - -set(mysqlcl_idb_LIB_SRCS - column.cc - command.cc - conn.cc - conn_uds.cc - drizzle.cc - field.cc - handshake.cc - pack.cc - query.cc - result.cc - row.cc - sha1.cc - state.cc) - -add_library(mysqlcl_idb SHARED ${mysqlcl_idb_LIB_SRCS}) - -set_target_properties(mysqlcl_idb PROPERTIES VERSION 1.0.0 SOVERSION 1) - -install(TARGETS mysqlcl_idb DESTINATION ${ENGINE_LIBDIR} COMPONENT libs) - diff --git a/utils/mysqlcl_idb/Makefile.am b/utils/mysqlcl_idb/Makefile.am deleted file mode 100644 index d3e0231a0..000000000 --- a/utils/mysqlcl_idb/Makefile.am +++ /dev/null @@ -1,54 +0,0 @@ -# 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$ -## Process this file with automake to produce Makefile.in - -AM_CPPFLAGS = $(idb_common_includes) $(idb_cppflags) -AM_CFLAGS = $(idb_cflags) -AM_CXXFLAGS = $(idb_cxxflags) -AM_LDFLAGS = -version-info 1:0:0 $(idb_ldflags) -lib_LTLIBRARIES = libmysqlcl_idb.la -libmysqlcl_idb_la_CPPFLAGS = -I/usr/include/libxml2 $(AM_CPPFLAGS) -libmysqlcl_idb_la_SOURCES = \ - column.cc \ - command.cc \ - conn.cc \ - conn_uds.cc \ - drizzle.cc \ - field.cc \ - handshake.cc \ - pack.cc \ - query.cc \ - result.cc \ - row.cc \ - sha1.cc \ - state.cc -include_HEADERS = - -test: - -coverage: - -leakcheck: - -docs: - -bootstrap: install-data-am - -install-data-hook: - cp -Rpf libdrizzle-2.0 $(DESTDIR)$(includedir) diff --git a/utils/mysqlcl_idb/column.cc b/utils/mysqlcl_idb/column.cc deleted file mode 100644 index 371ea685f..000000000 --- a/utils/mysqlcl_idb/column.cc +++ /dev/null @@ -1,1208 +0,0 @@ -/* - * Drizzle Client & Protocol Library - * - * Copyright (C) 2008 Eric Day (eday@oddments.org) - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * - * * The names of its contributors may not be used to endorse or - * promote products derived from this software without specific prior - * written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - - -/** - * @file - * @brief Column definitions - */ - -#include - -/* - * Private variables. - */ - -static drizzle_column_type_t _column_type_drizzle_map_to[]= -{ - DRIZZLE_COLUMN_TYPE_TINY, - DRIZZLE_COLUMN_TYPE_LONG, - DRIZZLE_COLUMN_TYPE_DOUBLE, - DRIZZLE_COLUMN_TYPE_NULL, - DRIZZLE_COLUMN_TYPE_TIMESTAMP, - DRIZZLE_COLUMN_TYPE_LONGLONG, - DRIZZLE_COLUMN_TYPE_DATETIME, - DRIZZLE_COLUMN_TYPE_NEWDATE, - DRIZZLE_COLUMN_TYPE_VARCHAR, - DRIZZLE_COLUMN_TYPE_NEWDECIMAL, - DRIZZLE_COLUMN_TYPE_ENUM, - DRIZZLE_COLUMN_TYPE_BLOB -}; - -static drizzle_column_type_drizzle_t _column_type_drizzle_map_from[]= -{ - DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, /* 0 */ - DRIZZLE_COLUMN_TYPE_DRIZZLE_BOOLEAN, - DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, - DRIZZLE_COLUMN_TYPE_DRIZZLE_LONG, - DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, - DRIZZLE_COLUMN_TYPE_DRIZZLE_DOUBLE, - DRIZZLE_COLUMN_TYPE_DRIZZLE_NULL, - DRIZZLE_COLUMN_TYPE_DRIZZLE_TIMESTAMP, - DRIZZLE_COLUMN_TYPE_DRIZZLE_LONGLONG, - DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, - - DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, /* 10 */ - DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, - DRIZZLE_COLUMN_TYPE_DRIZZLE_DATETIME, - DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, - DRIZZLE_COLUMN_TYPE_DRIZZLE_DATE, - DRIZZLE_COLUMN_TYPE_DRIZZLE_VARCHAR, - DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, - DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, - DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, - DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, - - DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, /* 20 */ - DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, - DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, - DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, - DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, - DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, - DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, - DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, - DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, - DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, - - DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, /* 30 */ - DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, - DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, - DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, - DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, - DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, - DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, - DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, - DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, - DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, - - DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, /* 40 */ - DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, - DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, - DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, - DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, - DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, - DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, - DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, - DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, - DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, - - DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, /* 50 */ - DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, - DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, - DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, - DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, - DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, - DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, - DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, - DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, - DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, - - DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, /* 60 */ - DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, - DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, - DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, - DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, - DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, - DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, - DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, - DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, - DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, - - DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, /* 70 */ - DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, - DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, - DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, - DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, - DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, - DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, - DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, - DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, - DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, - - DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, /* 80 */ - DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, - DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, - DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, - DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, - DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, - DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, - DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, - DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, - DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, - - DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, /* 90 */ - DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, - DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, - DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, - DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, - DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, - DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, - DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, - DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, - DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, - - DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, /* 100 */ - DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, - DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, - DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, - DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, - DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, - DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, - DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, - DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, - DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, - - DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, /* 110 */ - DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, - DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, - DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, - DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, - DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, - DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, - DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, - DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, - DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, - - DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, /* 120 */ - DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, - DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, - DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, - DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, - DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, - DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, - DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, - DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, - DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, - - DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, /* 130 */ - DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, - DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, - DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, - DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, - DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, - DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, - DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, - DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, - DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, - - DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, /* 140 */ - DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, - DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, - DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, - DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, - DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, - DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, - DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, - DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, - DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, - - DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, /* 150 */ - DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, - DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, - DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, - DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, - DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, - DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, - DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, - DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, - DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, - - DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, /* 160 */ - DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, - DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, - DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, - DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, - DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, - DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, - DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, - DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, - DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, - - DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, /* 170 */ - DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, - DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, - DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, - DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, - DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, - DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, - DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, - DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, - DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, - - DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, /* 180 */ - DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, - DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, - DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, - DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, - DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, - DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, - DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, - DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, - DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, - - DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, /* 190 */ - DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, - DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, - DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, - DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, - DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, - DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, - DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, - DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, - DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, - - DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, /* 200 */ - DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, - DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, - DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, - DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, - DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, - DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, - DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, - DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, - DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, - - DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, /* 210 */ - DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, - DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, - DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, - DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, - DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, - DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, - DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, - DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, - DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, - - DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, /* 220 */ - DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, - DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, - DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, - DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, - DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, - DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, - DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, - DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, - DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, - - DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, /* 230 */ - DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, - DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, - DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, - DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, - DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, - DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, - DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, - DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, - DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, - - DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, /* 240 */ - DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, - DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, - DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, - DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, - DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, - DRIZZLE_COLUMN_TYPE_DRIZZLE_NEWDECIMAL, - DRIZZLE_COLUMN_TYPE_DRIZZLE_ENUM, - DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, - DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, - - DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, /* 250 */ - DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, - DRIZZLE_COLUMN_TYPE_DRIZZLE_BLOB, - DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, - DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX, - DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX -}; - -/* - * Common definitions - */ - -drizzle_column_st *drizzle_column_create(drizzle_result_st *result, - drizzle_column_st *column) -{ - if (result == NULL) - { - return NULL; - } - - if (column == NULL) - { - column= new (std::nothrow) drizzle_column_st; - - if (column == NULL) - { - return NULL; - } - - column->result= result; - /* SET BELOW: column->next */ - column->prev= NULL; - column->options.is_allocated= true; - column->catalog[0]= '\0'; - column->schema[0]= '\0'; - column->table[0]= '\0'; - column->orig_table[0]= '\0'; - column->name[0]= '\0'; - column->orig_name[0]= '\0'; - column->charset= 0; - column->size= 0; - column->max_size= 0; - column->type= static_cast(0); - column->flags= drizzle_column_flags_t(); - column->decimals= 0; - /* UNSET: column->default_value */ - column->default_value_size= 0; - } - else - { - column->result = result; - /* SET BELOW: column->next */ - column->prev = NULL; - column->options.is_allocated= false; - column->catalog[0] = '\0'; - column->schema[0] = '\0'; - column->table[0] = '\0'; - column->orig_table[0] = '\0'; - column->name[0] = '\0'; - column->orig_name[0] = '\0'; - column->charset = 0; - column->size = 0; - column->max_size = 0; - column->type = static_cast(0); - column->flags = drizzle_column_flags_t(); - column->decimals = 0; - /* UNSET: column->default_value */ - column->default_value_size = 0; - } - - column->result= result; - - if (result->column_list) - result->column_list->prev= column; - column->next= result->column_list; - result->column_list= column; - - return column; -} - -void drizzle_column_free(drizzle_column_st *column) -{ - if (column == NULL) - { - return; - } - - if (column->result->column_list == column) - { - column->result->column_list= column->next; - } - - if (column->prev) - { - column->prev->next= column->next; - } - - if (column->next) - { - column->next->prev= column->prev; - } - - if (column->options.is_allocated) - { - delete column; - } -} - -drizzle_result_st *drizzle_column_drizzle_result(drizzle_column_st *column) -{ - if (column == NULL) - { - return NULL; - } - - return column->result; -} - -const char *drizzle_column_catalog(drizzle_column_st *column) -{ - if (column == NULL) - { - return NULL; - } - - return column->catalog; -} - -const char *drizzle_column_shema(drizzle_column_st *column) -{ - if (column == NULL) - { - return NULL; - } - - return column->schema; -} - -const char *drizzle_column_db(drizzle_column_st *column) -{ - return drizzle_column_shema(column); -} - -const char *drizzle_column_table(drizzle_column_st *column) -{ - if (column == NULL) - { - return NULL; - } - - return column->table; -} - -const char *drizzle_column_orig_table(drizzle_column_st *column) -{ - if (column == NULL) - { - return NULL; - } - - return column->orig_table; -} - -const char *drizzle_column_name(drizzle_column_st *column) -{ - if (column == NULL) - { - return NULL; - } - - return column->name; -} - -const char *drizzle_column_orig_name(drizzle_column_st *column) -{ - if (column == NULL) - { - return NULL; - } - - return column->orig_name; -} - -drizzle_charset_t drizzle_column_charset(drizzle_column_st *column) -{ - if (column == NULL) - { - return 0; - } - - return column->charset; -} - -uint32_t drizzle_column_size(drizzle_column_st *column) -{ - if (column == NULL) - { - return 0; - } - - return column->size; -} - -size_t drizzle_column_max_size(drizzle_column_st *column) -{ - if (column == NULL) - { - return 0; - } - - return column->max_size; -} - -void drizzle_column_set_max_size(drizzle_column_st *column, size_t size) -{ - if (column == NULL) - { - return; - } - - column->max_size= size; -} - -drizzle_column_type_t drizzle_column_type(drizzle_column_st *column) -{ - if (column == NULL) - { - return drizzle_column_type_t(); - } - - return column->type; -} - -drizzle_column_type_drizzle_t drizzle_column_type_drizzle(drizzle_column_st *column) -{ - if (column == NULL) - { - return drizzle_column_type_drizzle_t(); - } - - return _column_type_drizzle_map_from[column->type]; -} - -int drizzle_column_flags(drizzle_column_st *column) -{ - if (column == NULL) - { - return 0; - } - - return column->flags; -} - -uint8_t drizzle_column_decimals(drizzle_column_st *column) -{ - if (column == NULL) - { - return 0; - } - - return column->decimals; -} - -const uint8_t *drizzle_column_default_value(drizzle_column_st *column, - size_t *size) -{ - *size= column->default_value_size; - return column->default_value; -} - -/* - * Client definitions - */ - -drizzle_return_t drizzle_column_skip(drizzle_result_st *result) -{ - if (result == NULL) - { - return DRIZZLE_RETURN_INVALID_ARGUMENT; - } - - if (drizzle_state_none(result->con)) - { - result->options|= DRIZZLE_RESULT_SKIP_COLUMN; - - drizzle_state_push(result->con, drizzle_state_column_read); - drizzle_state_push(result->con, drizzle_state_packet_read); - } - drizzle_return_t ret= drizzle_state_loop(result->con); - result->options&= ~DRIZZLE_RESULT_SKIP_COLUMN; - return ret; -} - -drizzle_return_t drizzle_column_skip_all(drizzle_result_st *result) -{ - if (result == NULL) - { - return DRIZZLE_RETURN_INVALID_ARGUMENT; - } - - for (uint16_t it= 1; it <= result->column_count; it++) - { - drizzle_return_t ret= drizzle_column_skip(result); - if (ret != DRIZZLE_RETURN_OK) - { - return ret; - } - } - - return DRIZZLE_RETURN_OK; -} - -drizzle_column_st *drizzle_column_read(drizzle_result_st *result, - drizzle_column_st *column, - drizzle_return_t *ret_ptr) -{ - if (result == NULL) - { - return NULL; - } - - if (drizzle_state_none(result->con)) - { - result->column= column; - - drizzle_state_push(result->con, drizzle_state_column_read); - drizzle_state_push(result->con, drizzle_state_packet_read); - } - - *ret_ptr= drizzle_state_loop(result->con); - return result->column; -} - -drizzle_return_t drizzle_column_buffer(drizzle_result_st *result) -{ - if (result == NULL) - { - return DRIZZLE_RETURN_INVALID_ARGUMENT; - } - - drizzle_return_t ret; - - if (result->column_buffer == NULL) - { - if (result->column_count == 0) - { - result->options|= DRIZZLE_RESULT_BUFFER_COLUMN; - return DRIZZLE_RETURN_OK; - } - - result->column_buffer= new (std::nothrow) drizzle_column_st[result->column_count]; - - if (result->column_buffer == NULL) - { - return DRIZZLE_RETURN_MEMORY; - } - } - - /* No while body, just keep calling to buffer columns. */ - while (drizzle_column_read(result, - &(result->column_buffer[result->column_current]), - &ret) != NULL && ret == DRIZZLE_RETURN_OK) - { } - - if (ret == DRIZZLE_RETURN_OK) - { - result->column_current= 0; - result->options|= DRIZZLE_RESULT_BUFFER_COLUMN; - } - - return ret; -} - -drizzle_column_st *drizzle_column_next(drizzle_result_st *result) -{ - if (result == NULL) - { - return NULL; - } - - if (result->column_current == result->column_count) - { - return NULL; - } - - result->column_current++; - return &(result->column_buffer[result->column_current - 1]); -} - -drizzle_column_st *drizzle_column_prev(drizzle_result_st *result) -{ - if (result->column_current == 0) - return NULL; - - result->column_current--; - return &(result->column_buffer[result->column_current]); -} - -void drizzle_column_seek(drizzle_result_st *result, uint16_t column) -{ - if (result == NULL) - { - return; - } - - if (column <= result->column_count) - { - result->column_current= column; - } -} - -drizzle_column_st *drizzle_column_index(drizzle_result_st *result, uint16_t column) -{ - if (result == NULL) - { - return NULL; - } - - if (column >= result->column_count) - { - return NULL; - } - - return &(result->column_buffer[column]); -} - -uint16_t drizzle_column_current(drizzle_result_st *result) -{ - if (result == NULL) - { - return 0; - } - - return result->column_current; -} - -/* - * Server definitions - */ - -drizzle_return_t drizzle_column_write(drizzle_result_st *result, - drizzle_column_st *column) -{ - if (result == NULL) - { - return DRIZZLE_RETURN_INVALID_ARGUMENT; - } - - if (drizzle_state_none(result->con)) - { - result->column= column; - - drizzle_state_push(result->con, drizzle_state_column_write); - } - - return drizzle_state_loop(result->con); -} - -void drizzle_column_set_catalog(drizzle_column_st *column, const char *catalog) -{ - if (column == NULL) - { - return; - } - - if (catalog == NULL) - { - column->catalog[0]= 0; - } - else - { - strncpy(column->catalog, catalog, DRIZZLE_MAX_CATALOG_SIZE); - column->catalog[DRIZZLE_MAX_CATALOG_SIZE - 1]= 0; - } -} - -void drizzle_column_set_schema(drizzle_column_st *column, const char *schema) -{ - if (column == NULL) - { - return; - } - - if (schema == NULL) - { - column->schema[0]= 0; - } - else - { - strncpy(column->schema, schema, DRIZZLE_MAX_DB_SIZE); - column->schema[DRIZZLE_MAX_DB_SIZE - 1]= 0; - } -} - -void drizzle_column_set_db(drizzle_column_st *column, const char *schema) -{ - drizzle_column_set_schema(column, schema); -} - - -void drizzle_column_set_table(drizzle_column_st *column, const char *table) -{ - if (column == NULL) - { - return; - } - - if (table == NULL) - { - column->table[0]= 0; - } - else - { - strncpy(column->table, table, DRIZZLE_MAX_TABLE_SIZE); - column->table[DRIZZLE_MAX_TABLE_SIZE - 1]= 0; - } -} - -void drizzle_column_set_orig_table(drizzle_column_st *column, - const char *orig_table) -{ - if (column == NULL) - { - return; - } - - if (orig_table == NULL) - column->orig_table[0]= 0; - else - { - strncpy(column->orig_table, orig_table, DRIZZLE_MAX_TABLE_SIZE); - column->orig_table[DRIZZLE_MAX_TABLE_SIZE - 1]= 0; - } -} - -void drizzle_column_set_name(drizzle_column_st *column, const char *name) -{ - if (column == NULL) - { - return; - } - - if (name == NULL) - column->name[0]= 0; - else - { - strncpy(column->name, name, DRIZZLE_MAX_COLUMN_NAME_SIZE); - column->name[DRIZZLE_MAX_COLUMN_NAME_SIZE - 1]= 0; - } -} - -void drizzle_column_set_orig_name(drizzle_column_st *column, - const char *orig_name) -{ - if (column == NULL) - { - return; - } - - if (orig_name == NULL) - column->orig_name[0]= 0; - else - { - strncpy(column->orig_name, orig_name, DRIZZLE_MAX_COLUMN_NAME_SIZE); - column->orig_name[DRIZZLE_MAX_COLUMN_NAME_SIZE - 1]= 0; - } -} - -void drizzle_column_set_charset(drizzle_column_st *column, - drizzle_charset_t charset) -{ - if (column == NULL) - { - return; - } - - column->charset= charset; -} - -void drizzle_column_set_size(drizzle_column_st *column, uint32_t size) -{ - if (column == NULL) - { - return; - } - - column->size= size; -} - -void drizzle_column_set_type(drizzle_column_st *column, - drizzle_column_type_t type) -{ - if (column == NULL) - { - return; - } - - column->type= type; -} - -void drizzle_column_set_flags(drizzle_column_st *column, - int flags) -{ - if (column == NULL) - { - return; - } - - column->flags= flags; -} - -void drizzle_column_set_decimals(drizzle_column_st *column, uint8_t decimals) -{ - if (column == NULL) - { - return; - } - - column->decimals= decimals; -} - -void drizzle_column_set_default_value(drizzle_column_st *column, - const uint8_t *default_value, - size_t size) -{ - if (column == NULL) - { - return; - } - - if (default_value == NULL) - { - column->default_value[0]= 0; - } - else - { - if (size < DRIZZLE_MAX_DEFAULT_VALUE_SIZE) - { - memcpy(column->default_value, default_value, size); - column->default_value[size]= 0; - column->default_value_size= size; - } - else - { - memcpy(column->default_value, default_value, - DRIZZLE_MAX_DEFAULT_VALUE_SIZE - 1); - column->default_value[DRIZZLE_MAX_DEFAULT_VALUE_SIZE - 1]= 0; - column->default_value_size= DRIZZLE_MAX_DEFAULT_VALUE_SIZE; - } - } -} - -/* - * Internal state functions. - */ - -drizzle_return_t drizzle_state_column_read(drizzle_con_st *con) -{ - if (con == NULL) - { - return DRIZZLE_RETURN_INVALID_ARGUMENT; - } - - drizzle_column_st *column; - drizzle_column_type_drizzle_t drizzle_type; - - drizzle_log_debug(con->drizzle, "drizzle_state_column_read"); - - /* Assume the entire column packet will fit in the buffer. */ - if (con->buffer_size < con->packet_size) - { - drizzle_state_push(con, drizzle_state_read); - return DRIZZLE_RETURN_OK; - } - - if (con->packet_size == 5 && con->buffer_ptr[0] == 254) - { - /* EOF packet marking end of columns. */ - con->result->column= NULL; - con->result->warning_count= drizzle_get_byte2(con->buffer_ptr + 1); - con->status= (drizzle_con_status_t)drizzle_get_byte2(con->buffer_ptr + 3); - con->buffer_ptr+= 5; - con->buffer_size-= 5; - - drizzle_state_pop(con); - } - else if (con->result->options & DRIZZLE_RESULT_SKIP_COLUMN) - { - con->buffer_ptr+= con->packet_size; - con->buffer_size-= con->packet_size; - con->packet_size= 0; - con->result->column_count++; - - drizzle_state_pop(con); - } - else - { - column= drizzle_column_create(con->result, con->result->column); - if (column == NULL) - return DRIZZLE_RETURN_MEMORY; - - con->result->column= column; - - /* These functions can only fail if they need to read data, but we know we - buffered the entire packet, so ignore returns. */ - (void)drizzle_unpack_string(con, column->catalog, DRIZZLE_MAX_CATALOG_SIZE); - (void)drizzle_unpack_string(con, column->schema, DRIZZLE_MAX_DB_SIZE); - (void)drizzle_unpack_string(con, column->table, DRIZZLE_MAX_TABLE_SIZE); - (void)drizzle_unpack_string(con, column->orig_table, - DRIZZLE_MAX_TABLE_SIZE); - (void)drizzle_unpack_string(con, column->name, - DRIZZLE_MAX_COLUMN_NAME_SIZE); - (void)drizzle_unpack_string(con, column->orig_name, - DRIZZLE_MAX_COLUMN_NAME_SIZE); - - /* Skip one filler byte. */ - column->charset= (drizzle_charset_t)drizzle_get_byte2(con->buffer_ptr + 1); - column->size= drizzle_get_byte4(con->buffer_ptr + 3); - - if (con->options & DRIZZLE_CON_MYSQL) - column->type= (drizzle_column_type_t)con->buffer_ptr[7]; - else - { - drizzle_type= (drizzle_column_type_drizzle_t)con->buffer_ptr[7]; - if (drizzle_type >= DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX) - drizzle_type= DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX; - column->type= _column_type_drizzle_map_to[drizzle_type]; - } - - column->flags= drizzle_get_byte2(con->buffer_ptr + 8); - if (column->type <= DRIZZLE_COLUMN_TYPE_INT24 && - column->type != DRIZZLE_COLUMN_TYPE_TIMESTAMP) - { - column->flags|= DRIZZLE_COLUMN_FLAGS_NUM; - } - - column->decimals= con->buffer_ptr[10]; - /* Skip two reserved bytes. */ - - con->buffer_ptr+= 13; - con->buffer_size-= 13; - con->packet_size-= 13; - - if (con->packet_size > 0) - { - drizzle_column_set_default_value(column, con->buffer_ptr, - con->packet_size); - - con->buffer_ptr+= con->packet_size; - con->buffer_size-= con->packet_size; - } - else - column->default_value[0]= 0; - - con->result->column_current++; - - drizzle_state_pop(con); - } - - return DRIZZLE_RETURN_OK; -} - -drizzle_return_t drizzle_state_column_write(drizzle_con_st *con) -{ - if (con == NULL) - { - return DRIZZLE_RETURN_INVALID_ARGUMENT; - } - - uint8_t *start= con->buffer_ptr + con->buffer_size; - uint8_t *ptr; - drizzle_column_st *column= con->result->column; - - drizzle_log_debug(con->drizzle, "drizzle_state_column_write"); - - /* Calculate max packet size. */ - con->packet_size= 9 + strlen(column->catalog) - + 9 + strlen(column->schema) - + 9 + strlen(column->table) - + 9 + strlen(column->orig_table) - + 9 + strlen(column->name) - + 9 + strlen(column->orig_name) - + 1 /* Unused */ - + 2 /* Charset */ - + 4 /* Size */ - + 1 /* Type */ - + 2 /* Flags */ - + 1 /* Decimals */ - + 2 /* Unused */ - + column->default_value_size; - - /* Assume the entire column packet will fit in the buffer. */ - if ((con->packet_size + 4) > DRIZZLE_MAX_BUFFER_SIZE) - { - drizzle_set_error(con->drizzle, "drizzle_state_column_write", - "buffer too small:%zu", con->packet_size + 4); - return DRIZZLE_RETURN_INTERNAL_ERROR; - } - - /* Flush buffer if there is not enough room. */ - if (((size_t)DRIZZLE_MAX_BUFFER_SIZE - (size_t)(start - con->buffer)) < - con->packet_size) - { - drizzle_state_push(con, drizzle_state_write); - return DRIZZLE_RETURN_OK; - } - - /* Store packet size at the end since it may change. */ - ptr= start; - ptr[3]= con->packet_number; - con->packet_number++; - ptr+= 4; - - ptr= drizzle_pack_string(column->catalog, ptr); - ptr= drizzle_pack_string(column->schema, ptr); - ptr= drizzle_pack_string(column->table, ptr); - ptr= drizzle_pack_string(column->orig_table, ptr); - ptr= drizzle_pack_string(column->name, ptr); - ptr= drizzle_pack_string(column->orig_name, ptr); - - /* This unused byte is set to 12 for some reason. */ - ptr[0]= 12; - ptr++; - - drizzle_set_byte2(ptr, column->charset); - ptr+= 2; - - drizzle_set_byte4(ptr, column->size); - ptr+= 4; - - if (con->options & DRIZZLE_CON_MYSQL) - { - ptr[0]= column->type; - } - else - { - ptr[0]= _column_type_drizzle_map_from[column->type]; - } - ptr++; - - drizzle_set_byte2(ptr, column->flags); - ptr+= 2; - - ptr[0]= column->decimals; - ptr++; - - memset(ptr, 0, 2); - ptr+= 2; - - if (column->default_value_size > 0) - { - memcpy(ptr, column->default_value, column->default_value_size); - ptr+= column->default_value_size; - } - - con->packet_size= ((size_t)(ptr - start) - 4); - con->buffer_size+= (4 + con->packet_size); - - /* Store packet size now. */ - drizzle_set_byte3(start, con->packet_size); - - con->result->column_current++; - - drizzle_state_pop(con); - - return DRIZZLE_RETURN_OK; -} diff --git a/utils/mysqlcl_idb/command.cc b/utils/mysqlcl_idb/command.cc deleted file mode 100644 index d86d3c152..000000000 --- a/utils/mysqlcl_idb/command.cc +++ /dev/null @@ -1,254 +0,0 @@ -/* - * Drizzle Client & Protocol Library - * - * Copyright (C) 2008 Eric Day (eday@oddments.org) - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * - * * The names of its contributors may not be used to endorse or - * promote products derived from this software without specific prior - * written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - - -/** - * @file - * @brief Command definitions - */ - -#include - -/* - * Private variables. - */ - -static drizzle_command_drizzle_t _command_drizzle_map[]= -{ - DRIZZLE_COMMAND_DRIZZLE_END, - DRIZZLE_COMMAND_DRIZZLE_QUIT, - DRIZZLE_COMMAND_DRIZZLE_INIT_DB, - DRIZZLE_COMMAND_DRIZZLE_QUERY, - DRIZZLE_COMMAND_DRIZZLE_END, - DRIZZLE_COMMAND_DRIZZLE_END, - DRIZZLE_COMMAND_DRIZZLE_END, - DRIZZLE_COMMAND_DRIZZLE_END, - DRIZZLE_COMMAND_DRIZZLE_SHUTDOWN, - DRIZZLE_COMMAND_DRIZZLE_END, // STATISTICS - DRIZZLE_COMMAND_DRIZZLE_END, // PROCESS_INFO - DRIZZLE_COMMAND_DRIZZLE_END, // CONNECT - DRIZZLE_COMMAND_DRIZZLE_KILL,// PROCESS_KILL - DRIZZLE_COMMAND_DRIZZLE_END, - DRIZZLE_COMMAND_DRIZZLE_PING, - DRIZZLE_COMMAND_DRIZZLE_END, - DRIZZLE_COMMAND_DRIZZLE_END, - DRIZZLE_COMMAND_DRIZZLE_END, - DRIZZLE_COMMAND_DRIZZLE_END, - DRIZZLE_COMMAND_DRIZZLE_END, - DRIZZLE_COMMAND_DRIZZLE_END, - DRIZZLE_COMMAND_DRIZZLE_END, - DRIZZLE_COMMAND_DRIZZLE_END, - DRIZZLE_COMMAND_DRIZZLE_END, - DRIZZLE_COMMAND_DRIZZLE_END, - DRIZZLE_COMMAND_DRIZZLE_END, - DRIZZLE_COMMAND_DRIZZLE_END, - DRIZZLE_COMMAND_DRIZZLE_END, - DRIZZLE_COMMAND_DRIZZLE_END, - DRIZZLE_COMMAND_DRIZZLE_END, - DRIZZLE_COMMAND_DRIZZLE_END -}; - -/* - * State Definitions - */ - -drizzle_return_t drizzle_state_command_read(drizzle_con_st *con) -{ - drizzle_log_debug(con->drizzle, "drizzle_state_command_read"); - - if (con->buffer_size == 0) - { - drizzle_state_push(con, drizzle_state_read); - return DRIZZLE_RETURN_OK; - } - - if (con->command_total == 0) - { - con->command= (drizzle_command_t)(con->buffer_ptr[0]); - con->buffer_ptr++; - con->buffer_size--; - - con->command_total= (con->packet_size - 1); - } - - if (con->buffer_size < (con->command_total - con->command_offset)) - { - con->command_size= con->buffer_size; - con->command_offset+= con->command_size; - } - else - { - con->command_size= (con->command_total - con->command_offset); - con->command_offset= con->command_total; - } - - con->command_data= con->buffer_ptr; - con->buffer_ptr+= con->command_size; - con->buffer_size-= con->command_size; - - if (con->command_offset == con->command_total) - { - drizzle_state_pop(con); - } - else - { - return DRIZZLE_RETURN_PAUSE; - } - - return DRIZZLE_RETURN_OK; -} - -drizzle_return_t drizzle_state_command_write(drizzle_con_st *con) -{ - uint8_t *start; - uint8_t *ptr; - size_t free_size; - drizzle_return_t ret; - - drizzle_log_debug(con->drizzle, "drizzle_state_command_write"); - - if (con->command_data == NULL && con->command_total != 0 && - con->command != DRIZZLE_COMMAND_CHANGE_USER) - { - return DRIZZLE_RETURN_PAUSE; - } - - if (con->buffer_size == 0) - { - con->buffer_ptr= con->buffer; - start= con->buffer; - } - else - start= con->buffer_ptr + con->buffer_size; - - if (con->command_offset == 0) - { - /* Make sure we can fit the largest non-streaming packet, currently a - DRIZZLE_COMMAND_CHANGE_USER command. */ - - con->packet_size= 1 /* Command */ - + strlen(con->user) + 1 - + 1 /* Scramble size */ - + DRIZZLE_MAX_SCRAMBLE_SIZE - + strlen(con->schema) +1; - - /* Flush buffer if there is not enough room. */ - free_size= (size_t)DRIZZLE_MAX_BUFFER_SIZE - (size_t)(start - con->buffer); - if (free_size < con->packet_size) - { - drizzle_state_push(con, drizzle_state_write); - return DRIZZLE_RETURN_OK; - } - - /* Store packet size at the end since it may change. */ - con->packet_number= 1; - ptr= start; - ptr[3]= 0; - if (con->options & DRIZZLE_CON_MYSQL) - { - ptr[4]= uint8_t(con->command); - } - else - { - ptr[4]= uint8_t(_command_drizzle_map[con->command]); - } - ptr+= 5; - - if (con->command == DRIZZLE_COMMAND_CHANGE_USER) - { - ptr= drizzle_pack_auth(con, ptr, &ret); - if (ret != DRIZZLE_RETURN_OK) - return ret; - - con->buffer_size+= (4 + con->packet_size); - } - else if (con->command_total == 0) - { - con->packet_size= 1; - con->buffer_size+= 5; - } - else - { - con->packet_size= 1 + con->command_total; - free_size-= 5; - - /* Copy as much of the data in as we can into the write buffer. */ - if (con->command_size <= free_size) - { - memcpy(ptr, con->command_data, con->command_size); - con->command_offset= con->command_size; - con->command_data= NULL; - con->buffer_size+= 5 + con->command_size; - } - else - { - memcpy(ptr, con->command_data, free_size); - con->command_offset= free_size; - con->command_data+= free_size; - con->command_size-= free_size; - con->buffer_size+= 5 + free_size; - } - } - - /* Store packet size now. */ - drizzle_set_byte3(start, con->packet_size); - } - else - { - /* Write directly from the caller buffer for the rest. */ - con->buffer_ptr= con->command_data; - con->buffer_size= con->command_size; - con->command_offset+= con->command_size; - con->command_data= NULL; - } - - if (con->command_offset == con->command_total) - { - drizzle_state_pop(con); - - if (!(con->options & (DRIZZLE_CON_RAW_PACKET | - DRIZZLE_CON_NO_RESULT_READ)) && - con->command != DRIZZLE_COMMAND_FIELD_LIST) - { - drizzle_state_push(con, drizzle_state_result_read); - drizzle_state_push(con, drizzle_state_packet_read); - } - } - - drizzle_state_push(con, drizzle_state_write); - - return DRIZZLE_RETURN_OK; -} diff --git a/utils/mysqlcl_idb/conn.cc b/utils/mysqlcl_idb/conn.cc deleted file mode 100644 index dc671b322..000000000 --- a/utils/mysqlcl_idb/conn.cc +++ /dev/null @@ -1,1733 +0,0 @@ -/* - * Drizzle Client & Protocol Library - * - * Copyright (C) 2008 Eric Day (eday@oddments.org) - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * - * * The names of its contributors may not be used to endorse or - * promote products derived from this software without specific prior - * written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - - -/** - * @file - * @brief Connection Definitions - */ - -#include - -/** - * @addtogroup drizzle_con_static Static Connection Declarations - * @ingroup drizzle_con - * @{ - */ - -/** - * Set socket options for a connection. - * - * @param[in] con Connection structure previously initialized with - * drizzle_con_create(), drizzle_con_clone(), or related functions. - * @return Standard drizzle return value. - */ -static drizzle_return_t _con_setsockopt(drizzle_con_st *con); - -/** @} */ - -/* - * Common Definitions - */ - -int drizzle_con_fd(const drizzle_con_st *con) -{ - return con->fd; -} - -drizzle_return_t drizzle_con_set_fd(drizzle_con_st *con, int fd) -{ - con->fd= fd; - - drizzle_return_t ret= _con_setsockopt(con); - if (ret != DRIZZLE_RETURN_OK) - con->drizzle->last_errno= errno; - - return ret; -} - -void drizzle_con_close(drizzle_con_st *con) -{ - if (con->fd == -1) - return; - - (void)closesocket(con->fd); - con->fd= -1; - - con->options&= ~DRIZZLE_CON_READY; - con->packet_number= 0; - con->buffer_ptr= con->buffer; - con->buffer_size= 0; - con->events= 0; - con->revents= 0; - - drizzle_state_reset(con); -} - -drizzle_return_t drizzle_con_set_events(drizzle_con_st *con, short events) -{ - if ((con->events | events) == con->events) - return DRIZZLE_RETURN_OK; - - con->events|= events; - - if (con->drizzle->event_watch_fn != NULL) - { - drizzle_return_t ret= con->drizzle->event_watch_fn(con, con->events, - con->drizzle->event_watch_context); - if (ret != DRIZZLE_RETURN_OK) - { - drizzle_con_close(con); - return ret; - } - } - - return DRIZZLE_RETURN_OK; -} - -drizzle_return_t drizzle_con_set_revents(drizzle_con_st *con, short revents) -{ - if (revents != 0) - con->options|= DRIZZLE_CON_IO_READY; - - con->revents= revents; - - /* Remove external POLLOUT watch if we didn't ask for it. Otherwise we spin - forever until another POLLIN state change. This is much more efficient - than removing POLLOUT on every state change since some external polling - mechanisms need to use a system call to change flags (like Linux epoll). */ - if (revents & POLLOUT && !(con->events & POLLOUT) && - con->drizzle->event_watch_fn != NULL) - { - drizzle_return_t ret= con->drizzle->event_watch_fn(con, con->events, - con->drizzle->event_watch_context); - if (ret != DRIZZLE_RETURN_OK) - { - drizzle_con_close(con); - return ret; - } - } - - con->events&= (short)~revents; - - return DRIZZLE_RETURN_OK; -} - -drizzle_st *drizzle_con_drizzle(const drizzle_con_st *con) -{ - return con->drizzle; -} - -const char *drizzle_con_error(const drizzle_con_st *con) -{ - return drizzle_error(con->drizzle); -} - -int drizzle_con_errno(const drizzle_con_st *con) -{ - return drizzle_errno(con->drizzle); -} - -uint16_t drizzle_con_error_code(const drizzle_con_st *con) -{ - return drizzle_error_code(con->drizzle); -} - -const char *drizzle_con_sqlstate(const drizzle_con_st *con) -{ - return drizzle_sqlstate(con->drizzle); -} - -int drizzle_con_options(const drizzle_con_st *con) -{ - return con->options; -} - -void drizzle_con_set_options(drizzle_con_st *con, int options) -{ - con->options= options; -} - -void drizzle_con_add_options(drizzle_con_st *con, int options) -{ - con->options|= options; - - /* If asking for the experimental Drizzle protocol, clean the MySQL flag. */ - if (con->options & DRIZZLE_CON_EXPERIMENTAL) - { - con->options&= ~DRIZZLE_CON_MYSQL; - } -} - -void drizzle_con_remove_options(drizzle_con_st *con, int options) -{ - con->options&= ~options; -} - -const char *drizzle_con_host(const drizzle_con_st *con) -{ - if (con == NULL) - { - return NULL; - } - - if (con->socket_type == DRIZZLE_CON_SOCKET_TCP) - { - if (con->socket.tcp.host == NULL && !(con->options & DRIZZLE_CON_LISTEN)) - { - return DRIZZLE_DEFAULT_TCP_HOST; - } - - return con->socket.tcp.host; - } - - return NULL; -} - -in_port_t drizzle_con_port(const drizzle_con_st *con) -{ - if (con->socket_type == DRIZZLE_CON_SOCKET_TCP) - { - if (con->socket.tcp.port != 0) - return con->socket.tcp.port; - - if (con->options & DRIZZLE_CON_MYSQL) - return DRIZZLE_DEFAULT_TCP_PORT_MYSQL; - - return DRIZZLE_DEFAULT_TCP_PORT; - } - - return 0; -} - -void drizzle_con_set_tcp(drizzle_con_st *con, const char *host, in_port_t port) -{ - drizzle_con_reset_addrinfo(con); - - con->socket_type= DRIZZLE_CON_SOCKET_TCP; - - if (host == NULL) - { - con->socket.tcp.host= NULL; - } - else - { - con->socket.tcp.host= con->socket.tcp.host_buffer; - strncpy(con->socket.tcp.host, host, NI_MAXHOST); - con->socket.tcp.host[NI_MAXHOST - 1]= 0; - } - - con->socket.tcp.port= port; -} - -const char *drizzle_con_user(const drizzle_con_st *con) -{ - if (con == NULL) - { - return NULL; - } - - return con->user; -} - -const char *drizzle_con_password(const drizzle_con_st *con) -{ - if (con == NULL) - { - return NULL; - } - - return con->password; -} - -void drizzle_con_set_auth(drizzle_con_st *con, const char *user, const char *password) -{ - if (con == NULL) - { - return; - } - - if (user == NULL) - { - con->user[0]= 0; - } - else - { - strncpy(con->user, user, DRIZZLE_MAX_USER_SIZE); - con->user[DRIZZLE_MAX_USER_SIZE - 1]= 0; - } - - if (password == NULL) - { - con->password[0]= 0; - } - else - { - strncpy(con->password, password, DRIZZLE_MAX_PASSWORD_SIZE); - con->password[DRIZZLE_MAX_PASSWORD_SIZE - 1]= 0; - } -} - -const char *drizzle_con_schema(const drizzle_con_st *con) -{ - if (con == NULL) - { - return NULL; - } - - return con->schema; -} - -const char *drizzle_con_db(const drizzle_con_st *con) -{ - return drizzle_con_schema(con); -} - -void drizzle_con_set_schema(drizzle_con_st *con, const char *schema) -{ - if (con == NULL) - { - return; - } - - if (schema == NULL) - { - con->schema[0]= 0; - } - else - { - strncpy(con->schema, schema, DRIZZLE_MAX_DB_SIZE); - con->schema[DRIZZLE_MAX_DB_SIZE - 1]= 0; - } -} - -void drizzle_con_set_db(drizzle_con_st *con, const char *schema) -{ - drizzle_con_set_schema(con, schema); -} - -void *drizzle_con_context(const drizzle_con_st *con) -{ - if (con == NULL) - { - return NULL; - } - - return con->context; -} - -void drizzle_con_set_context(drizzle_con_st *con, void *context) -{ - if (con == NULL) - { - return; - } - - con->context= context; -} - -void drizzle_con_set_context_free_fn(drizzle_con_st *con, - drizzle_con_context_free_fn *function) -{ - if (con == NULL) - { - return; - } - - con->context_free_fn= function; -} - -uint8_t drizzle_con_protocol_version(const drizzle_con_st *con) -{ - if (con == NULL) - { - return 0; - } - - return con->protocol_version; -} - -const char *drizzle_con_server_version(const drizzle_con_st *con) -{ - if (con == NULL) - { - return NULL; - } - - return con->server_version; -} - -uint32_t drizzle_con_server_version_number(const drizzle_con_st *con) -{ - if (con == NULL || con->server_version) - { - return 0; - } - - const char *current= con->server_version; - - char *end; - uint32_t major= (uint32_t)strtoul(current, &end, 10); - current= end + 1; - - uint32_t minor= (uint32_t)strtoul(current, &end, 10); - current= end + 1; - - uint32_t version= (uint32_t)strtoul(current, &end, 10); - - return (major * 10000) + (minor * 100) + version; -} - -uint32_t drizzle_con_thread_id(const drizzle_con_st *con) -{ - if (con == NULL) - { - return 0; - } - - return con->thread_id; -} - -const uint8_t *drizzle_con_scramble(const drizzle_con_st *con) -{ - if (con == NULL) - { - return 0; - } - - return con->scramble; -} - -int drizzle_con_capabilities(const drizzle_con_st *con) -{ - if (con == NULL) - { - return 0; - } - - return con->capabilities; -} - -drizzle_charset_t drizzle_con_charset(const drizzle_con_st *con) -{ - if (con == NULL) - { - return drizzle_charset_t(); - } - - return con->charset; -} - -drizzle_con_status_t drizzle_con_status(const drizzle_con_st *con) -{ - if (con == NULL) - { - return drizzle_con_status_t(); - } - - return con->status; -} - -uint32_t drizzle_con_max_packet_size(const drizzle_con_st *con) -{ - if (con == NULL) - { - return 0; - } - - return con->max_packet_size; -} - -/* - * Client Definitions - */ - -drizzle_return_t drizzle_con_connect(drizzle_con_st *con) -{ - if (con == NULL) - { - return DRIZZLE_RETURN_INVALID_ARGUMENT; - } - - if (con->options & DRIZZLE_CON_READY) - { - return DRIZZLE_RETURN_OK; - } - - if (drizzle_state_none(con)) - { - if (!(con->options & DRIZZLE_CON_RAW_PACKET)) - { - drizzle_state_push(con, drizzle_state_handshake_server_read); - drizzle_state_push(con, drizzle_state_packet_read); - } - - drizzle_state_push(con, drizzle_state_connect); - drizzle_state_push(con, drizzle_state_addrinfo); - } - - return drizzle_state_loop(con); -} - -drizzle_result_st *drizzle_con_quit(drizzle_con_st *con, - drizzle_result_st *result, - drizzle_return_t *ret_ptr) -{ - return drizzle_con_command_write(con, result, DRIZZLE_COMMAND_QUIT, NULL, 0, - 0, ret_ptr); -} - -drizzle_result_st *drizzle_quit(drizzle_con_st *con, - drizzle_result_st *result, - drizzle_return_t *ret_ptr) -{ - return drizzle_con_quit(con, result, ret_ptr); -} - -drizzle_result_st *drizzle_con_select_db(drizzle_con_st *con, - drizzle_result_st *result, - const char *db, - drizzle_return_t *ret_ptr) -{ - drizzle_con_set_db(con, db); - return drizzle_con_command_write(con, result, DRIZZLE_COMMAND_INIT_DB, - db, strlen(db), strlen(db), ret_ptr); -} - -drizzle_result_st *drizzle_select_db(drizzle_con_st *con, - drizzle_result_st *result, - const char *db, - drizzle_return_t *ret_ptr) -{ - return drizzle_con_select_db(con, result, db, ret_ptr); -} - -drizzle_result_st *drizzle_con_shutdown(drizzle_con_st *con, - drizzle_result_st *result, - drizzle_return_t *ret_ptr) -{ - if (con == NULL) - { - return NULL; - } - - if (con->options & DRIZZLE_CON_MYSQL) - { - return drizzle_con_command_write(con, result, DRIZZLE_COMMAND_SHUTDOWN, - "0", 1, 1, ret_ptr); - } - - return drizzle_con_command_write(con, result, DRIZZLE_COMMAND_SHUTDOWN, NULL, - 0, 0, ret_ptr); -} - -drizzle_result_st *drizzle_shutdown(drizzle_con_st *con, - drizzle_result_st *result, uint32_t, - drizzle_return_t *ret_ptr) -{ - return drizzle_con_shutdown(con, result, ret_ptr); -} - -drizzle_result_st *drizzle_kill(drizzle_con_st *con, - drizzle_result_st *result, - uint32_t query_id, - drizzle_return_t *ret_ptr) -{ - uint32_t sent= htonl(query_id); - return drizzle_con_command_write(con, result, DRIZZLE_COMMAND_PROCESS_KILL, - &sent, sizeof(uint32_t), sizeof(uint32_t), ret_ptr); -} - -drizzle_result_st *drizzle_con_ping(drizzle_con_st *con, - drizzle_result_st *result, - drizzle_return_t *ret_ptr) -{ - return drizzle_con_command_write(con, result, DRIZZLE_COMMAND_PING, NULL, 0, - 0, ret_ptr); -} - -drizzle_result_st *drizzle_ping(drizzle_con_st *con, - drizzle_result_st *result, - drizzle_return_t *ret_ptr) -{ - return drizzle_con_ping(con, result, ret_ptr); -} - -drizzle_result_st *drizzle_con_command_write(drizzle_con_st *con, - drizzle_result_st *result, - drizzle_command_t command, - const void *data, size_t size, - size_t total, - drizzle_return_t *ret_ptr) -{ - if (con == NULL) - { - return NULL; - } - - drizzle_return_t unused; - if (ret_ptr == NULL) - { - ret_ptr= &unused; - } - - if ((con->options & DRIZZLE_CON_READY) == 0) - { - if (con->options & DRIZZLE_CON_RAW_PACKET) - { - drizzle_set_error(con->drizzle, "drizzle_command_write", "connection not ready"); - *ret_ptr= DRIZZLE_RETURN_NOT_READY; - return NULL; - } - - *ret_ptr= drizzle_con_connect(con); - if (*ret_ptr != DRIZZLE_RETURN_OK) - { - return NULL; - } - } - - if (drizzle_state_none(con)) - { - if (con->options & (DRIZZLE_CON_RAW_PACKET | DRIZZLE_CON_NO_RESULT_READ)) - { - con->result= NULL; - } - else - { - for (drizzle_result_st *old_result= con->result_list; old_result != NULL; old_result= old_result->next) - { - if (result == old_result) - { - drizzle_set_error(con->drizzle, "drizzle_command_write", "result struct already in use"); - *ret_ptr= DRIZZLE_RETURN_INTERNAL_ERROR; - return NULL; - } - } - - con->result= drizzle_result_create_with(con, result); - if (con->result == NULL) - { - *ret_ptr= DRIZZLE_RETURN_MEMORY; - return NULL; - } - } - - con->command= command; - con->command_data= (uint8_t *)data; - con->command_size= size; - con->command_offset= 0; - con->command_total= total; - - drizzle_state_push(con, drizzle_state_command_write); - } - else if (con->command_data == NULL) - { - con->command_data= (uint8_t *)data; - con->command_size= size; - } - - *ret_ptr= drizzle_state_loop(con); - if (*ret_ptr == DRIZZLE_RETURN_PAUSE) - { - *ret_ptr= DRIZZLE_RETURN_OK; - } - else if (*ret_ptr != DRIZZLE_RETURN_OK && - *ret_ptr != DRIZZLE_RETURN_IO_WAIT && - *ret_ptr != DRIZZLE_RETURN_ERROR_CODE) - { - drizzle_result_free(con->result); - con->result= result; - } - - return con->result; -} - -/* - * Server Definitions - */ - -drizzle_return_t drizzle_con_listen(drizzle_con_st *con) -{ - if (con == NULL) - { - return DRIZZLE_RETURN_INVALID_ARGUMENT; - } - - if (con->options & DRIZZLE_CON_READY) - { - return DRIZZLE_RETURN_OK; - } - - if (drizzle_state_none(con)) - { - drizzle_state_push(con, drizzle_state_listen); - drizzle_state_push(con, drizzle_state_addrinfo); - } - - return drizzle_state_loop(con); -} - -int drizzle_con_backlog(const drizzle_con_st *con) -{ - if (con == NULL) - { - return 0; - } - - return con->backlog; -} - -void drizzle_con_set_backlog(drizzle_con_st *con, int backlog) -{ - if (con == NULL) - { - return; - } - - con->backlog= backlog; -} - -void drizzle_con_set_protocol_version(drizzle_con_st *con, uint8_t protocol_version) -{ - if (con == NULL) - { - return; - } - - con->protocol_version= protocol_version; -} - -void drizzle_con_set_server_version(drizzle_con_st *con, - const char *server_version) -{ - if (con == NULL) - { - return; - } - - if (server_version == NULL) - { - con->server_version[0]= 0; - } - else - { - strncpy(con->server_version, server_version, - DRIZZLE_MAX_SERVER_VERSION_SIZE); - con->server_version[DRIZZLE_MAX_SERVER_VERSION_SIZE - 1]= 0; - } -} - -void drizzle_con_set_thread_id(drizzle_con_st *con, uint32_t thread_id) -{ - if (con == NULL) - { - return; - } - - con->thread_id= thread_id; -} - -void drizzle_con_set_scramble(drizzle_con_st *con, const uint8_t *scramble) -{ - if (con == NULL) - { - return; - } - - if (scramble == NULL) - { - con->scramble= NULL; - } - else - { - con->scramble= con->scramble_buffer; - memcpy(con->scramble, scramble, DRIZZLE_MAX_SCRAMBLE_SIZE); - } -} - -void drizzle_con_set_capabilities(drizzle_con_st *con, - int capabilities) -{ - if (con == NULL) - { - return; - } - - con->capabilities= capabilities; -} - -void drizzle_con_set_charset(drizzle_con_st *con, drizzle_charset_t charset) -{ - if (con == NULL) - { - return; - } - - con->charset= charset; -} - -void drizzle_con_set_status(drizzle_con_st *con, drizzle_con_status_t status) -{ - if (con == NULL) - { - return; - } - - con->status= status; -} - -void drizzle_con_set_max_packet_size(drizzle_con_st *con, - uint32_t max_packet_size) -{ - if (con == NULL) - { - return; - } - - con->max_packet_size= max_packet_size; -} - -void drizzle_con_copy_handshake(drizzle_con_st *con, drizzle_con_st *from) -{ - if (con == NULL) - { - return; - } - - drizzle_con_set_auth(con, from->user, NULL); - drizzle_con_set_scramble(con, from->scramble); - drizzle_con_set_db(con, from->schema); - drizzle_con_set_protocol_version(con, from->protocol_version); - drizzle_con_set_server_version(con, from->server_version); - drizzle_con_set_thread_id(con, from->thread_id); - drizzle_con_set_scramble(con, from->scramble); - drizzle_con_set_capabilities(con, from->capabilities); - drizzle_con_set_charset(con, from->charset); - drizzle_con_set_status(con, from->status); - drizzle_con_set_max_packet_size(con, from->max_packet_size); -} - -void *drizzle_con_command_read(drizzle_con_st *con, - drizzle_command_t *command, size_t *offset, - size_t *size, size_t *total, - drizzle_return_t *ret_ptr) -{ - if (con == NULL) - { - return NULL; - } - - drizzle_return_t unused; - if (ret_ptr == NULL) - { - ret_ptr= &unused; - } - - if (drizzle_state_none(con)) - { - con->packet_number= 0; - con->command_offset= 0; - con->command_total= 0; - - drizzle_state_push(con, drizzle_state_command_read); - drizzle_state_push(con, drizzle_state_packet_read); - } - - *offset= con->command_offset; - - *ret_ptr= drizzle_state_loop(con); - if (*ret_ptr == DRIZZLE_RETURN_PAUSE) - *ret_ptr= DRIZZLE_RETURN_OK; - - *command= con->command; - *size= con->command_size; - *total= con->command_total; - - return con->command_data; -} - -void *drizzle_con_command_buffer(drizzle_con_st *con, - drizzle_command_t *command, size_t *total, - drizzle_return_t *ret_ptr) -{ - size_t offset= 0; - size_t size= 0; - - if (con == NULL) - { - return NULL; - } - - drizzle_return_t unused; - if (ret_ptr == NULL) - { - ret_ptr= &unused; - } - - size_t total_unused; - if (total == NULL) - { - total= &total_unused; - } - - uint8_t *command_data= - static_cast(drizzle_con_command_read(con, command, &offset, - &size, total, ret_ptr)); - if (*ret_ptr != DRIZZLE_RETURN_OK) - { - return NULL; - } - - if (command_data == NULL) - { - *total= 0; - return NULL; - } - - if (con->command_buffer == NULL) - { - con->command_buffer= new (std::nothrow) uint8_t[(*total) + 1]; - - if (con->command_buffer == NULL) - { - *total= 0; - *ret_ptr= DRIZZLE_RETURN_MEMORY; - return NULL; - } - } - - memcpy(con->command_buffer + offset, command_data, size); - - while ((offset + size) != (*total)) - { - command_data= (uint8_t *)drizzle_con_command_read(con, command, &offset, - &size, total, ret_ptr); - if (*ret_ptr != DRIZZLE_RETURN_OK) - { - return NULL; - } - - memcpy(con->command_buffer + offset, command_data, size); - } - - command_data= con->command_buffer; - con->command_buffer= NULL; - command_data[*total]= 0; - - return command_data; -} - -void drizzle_con_command_buffer_free(uint8_t *command_buffer) -{ - delete[] command_buffer; -} - -/* - * Local Definitions - */ - -void drizzle_con_reset_addrinfo(drizzle_con_st *con) -{ - switch (con->socket_type) - { - case DRIZZLE_CON_SOCKET_TCP: - if (con->socket.tcp.addrinfo != NULL) - { - freeaddrinfo(con->socket.tcp.addrinfo); - con->socket.tcp.addrinfo= NULL; - } - break; - - case DRIZZLE_CON_SOCKET_UDS: - con->socket.uds.addrinfo.ai_addr= NULL; - break; - - default: - break; - } - - con->addrinfo_next= NULL; -} - -/* - * State Definitions - */ - -drizzle_return_t drizzle_state_addrinfo(drizzle_con_st *con) -{ - drizzle_con_tcp_st *tcp; - const char *host; - char port[NI_MAXSERV]; - struct addrinfo ai; - int ret; - - if (con == NULL) - { - return DRIZZLE_RETURN_INVALID_ARGUMENT; - } - - drizzle_log_debug(con->drizzle, "drizzle_state_addrinfo"); - - switch (con->socket_type) - { - case DRIZZLE_CON_SOCKET_TCP: - tcp= &(con->socket.tcp); - - if (tcp->addrinfo != NULL) - { - freeaddrinfo(tcp->addrinfo); - tcp->addrinfo= NULL; - } - - if (tcp->port != 0) - { - snprintf(port, NI_MAXSERV, "%u", tcp->port); - } - else if (con->options & DRIZZLE_CON_MYSQL) - { - snprintf(port, NI_MAXSERV, "%u", DRIZZLE_DEFAULT_TCP_PORT_MYSQL); - } - else - { - snprintf(port, NI_MAXSERV, "%u", DRIZZLE_DEFAULT_TCP_PORT); - } - port[NI_MAXSERV-1]= 0; - - memset(&ai, 0, sizeof(ai)); - ai.ai_socktype= SOCK_STREAM; - ai.ai_protocol= IPPROTO_TCP; - ai.ai_flags = AI_PASSIVE; - ai.ai_family = AF_UNSPEC; - - if (con->options & DRIZZLE_CON_LISTEN) - { - host= tcp->host; - } - else - { - if (tcp->host == NULL) - host= DRIZZLE_DEFAULT_TCP_HOST; - else - host= tcp->host; - } - - ret= getaddrinfo(host, port, &ai, &(tcp->addrinfo)); - if (ret != 0) - { - drizzle_set_error(con->drizzle, "drizzle_state_addrinfo", - "getaddrinfo:%s", gai_strerror(ret)); - return DRIZZLE_RETURN_GETADDRINFO; - } - - con->addrinfo_next= tcp->addrinfo; - - break; - - case DRIZZLE_CON_SOCKET_UDS: - con->addrinfo_next= &(con->socket.uds.addrinfo); - break; - } - - drizzle_state_pop(con); - return DRIZZLE_RETURN_OK; -} - -drizzle_return_t drizzle_state_connect(drizzle_con_st *con) -{ - if (con == NULL) - { - return DRIZZLE_RETURN_INVALID_ARGUMENT; - } - drizzle_log_debug(con->drizzle, "drizzle_state_connect"); - - if (con->fd != -1) - { - (void)closesocket(con->fd); - con->fd= -1; - } - - if (con->addrinfo_next == NULL) - { - drizzle_set_error(con->drizzle, "drizzle_state_connect", - "could not connect"); - drizzle_state_reset(con); - return DRIZZLE_RETURN_COULD_NOT_CONNECT; - } - - con->fd= socket(con->addrinfo_next->ai_family, - con->addrinfo_next->ai_socktype, - con->addrinfo_next->ai_protocol); - if (con->fd == -1) - { - drizzle_set_error(con->drizzle, "drizzle_state_connect", "socket:%d", - errno); - con->drizzle->last_errno= errno; - return DRIZZLE_RETURN_ERRNO; - } - - drizzle_return_t dret= _con_setsockopt(con); - if (dret != DRIZZLE_RETURN_OK) - { - con->drizzle->last_errno= errno; - return dret; - } - - while (1) - { - int ret= connect(con->fd, con->addrinfo_next->ai_addr, con->addrinfo_next->ai_addrlen); - -#ifdef _WIN32 -#define EINPROGRESS 1 -#define ECONNREFUSED 2 -#define ENETUNREACH 3 -#define ETIMEDOUT 4 -#define ECONNRESET 5 -#define EADDRINUSE 6 -#define EOPNOTSUPP 7 -#define ENOPROTOOPT 8 - errno = WSAGetLastError(); - switch(errno) { - case WSAEINVAL: - case WSAEALREADY: - case WSAEWOULDBLOCK: - errno= EINPROGRESS; - break; - case WSAECONNREFUSED: - errno= ECONNREFUSED; - break; - case WSAENETUNREACH: - errno= ENETUNREACH; - break; - case WSAETIMEDOUT: - errno= ETIMEDOUT; - break; - case WSAECONNRESET: - errno= ECONNRESET; - break; - case WSAEADDRINUSE: - errno= EADDRINUSE; - break; - case WSAEOPNOTSUPP: - errno= EOPNOTSUPP; - break; - case WSAENOPROTOOPT: - errno= ENOPROTOOPT; - break; - default: - break; - } -#endif /* _WIN32 */ - - drizzle_log_crazy(con->drizzle, "connect return=%d errno=%d", ret, errno); - - if (ret == 0) - { - con->addrinfo_next= NULL; - break; - } - - if (errno == EAGAIN || errno == EINTR) - continue; - - if (errno == EINPROGRESS) - { - drizzle_state_pop(con); - drizzle_state_push(con, drizzle_state_connecting); - return DRIZZLE_RETURN_OK; - } - - if (errno == ECONNREFUSED || errno == ENETUNREACH || errno == ETIMEDOUT) - { - con->addrinfo_next= con->addrinfo_next->ai_next; - return DRIZZLE_RETURN_OK; - } - - drizzle_set_error(con->drizzle, "drizzle_state_connect", "connect:%d", - errno); - con->drizzle->last_errno= errno; - return DRIZZLE_RETURN_ERRNO; - } - - drizzle_state_pop(con); - return DRIZZLE_RETURN_OK; -} - -drizzle_return_t drizzle_state_connecting(drizzle_con_st *con) -{ - if (con == NULL) - { - return DRIZZLE_RETURN_INVALID_ARGUMENT; - } - drizzle_log_debug(con->drizzle, "drizzle_state_connecting"); - - while (1) - { - if (con->revents & POLLOUT) - { - drizzle_state_pop(con); - return DRIZZLE_RETURN_OK; - } - else if (con->revents & (POLLERR | POLLHUP | POLLNVAL)) - { - con->revents= 0; - drizzle_state_pop(con); - drizzle_state_push(con, drizzle_state_connect); - con->addrinfo_next= con->addrinfo_next->ai_next; - return DRIZZLE_RETURN_OK; - } - - drizzle_return_t ret= drizzle_con_set_events(con, POLLOUT); - if (ret != DRIZZLE_RETURN_OK) - return ret; - - if (con->drizzle->options.is_non_blocking) - { - return DRIZZLE_RETURN_IO_WAIT; - } - - ret= drizzle_con_wait(con->drizzle); - if (ret != DRIZZLE_RETURN_OK) - { - return ret; - } - } -} - -drizzle_return_t drizzle_state_read(drizzle_con_st *con) -{ - if (con == NULL) - { - return DRIZZLE_RETURN_INVALID_ARGUMENT; - } - - drizzle_log_debug(con->drizzle, "drizzle_state_read"); - - if (con->buffer_size == 0) - con->buffer_ptr= con->buffer; - else if ((con->buffer_ptr - con->buffer) > (DRIZZLE_MAX_BUFFER_SIZE / 2)) - { - memmove(con->buffer, con->buffer_ptr, con->buffer_size); - con->buffer_ptr= con->buffer; - } - - if ((con->revents & POLLIN) == 0 && - (con->drizzle->options.is_non_blocking)) - { - /* non-blocking mode: return IO_WAIT instead of attempting to read. This - * avoids reading immediately after writing a command, which typically - * returns EAGAIN. This improves performance. */ - drizzle_return_t ret= drizzle_con_set_events(con, POLLIN); - if (ret != DRIZZLE_RETURN_OK) - { - return ret; - } - return DRIZZLE_RETURN_IO_WAIT; - } - - while (1) - { - size_t available_buffer= (size_t)DRIZZLE_MAX_BUFFER_SIZE - - ((size_t)(con->buffer_ptr - con->buffer) + con->buffer_size); - ssize_t read_size = recv(con->fd, (char *)con->buffer_ptr + con->buffer_size, - available_buffer, 0); -#ifdef _WIN32 - errno = WSAGetLastError(); - switch(errno) { - case WSAENOTCONN: - case WSAEWOULDBLOCK: - errno= EAGAIN; - break; - case WSAEINVAL: - case WSAEALREADY: - errno= EINPROGRESS; - break; - case WSAECONNREFUSED: - errno= ECONNREFUSED; - break; - case WSAENETUNREACH: - errno= ENETUNREACH; - break; - case WSAETIMEDOUT: - errno= ETIMEDOUT; - break; - case WSAECONNRESET: - errno= ECONNRESET; - break; - case WSAEADDRINUSE: - errno= EADDRINUSE; - break; - case WSAEOPNOTSUPP: - errno= EOPNOTSUPP; - break; - case WSAENOPROTOOPT: - errno= ENOPROTOOPT; - break; - default: - break; - } -#endif /* _WIN32 */ - - drizzle_log_crazy(con->drizzle, "read fd=%d return=%zd errno=%d", con->fd, - read_size, errno); - - if (read_size == 0) - { - drizzle_set_error(con->drizzle, "drizzle_state_read", - "lost connection to server (EOF)"); - return DRIZZLE_RETURN_LOST_CONNECTION; - } - else if (read_size == -1) - { - if (errno == EAGAIN) - { - /* clear the read ready flag */ - con->revents&= ~POLLIN; - drizzle_return_t ret= drizzle_con_set_events(con, POLLIN); - if (ret != DRIZZLE_RETURN_OK) - { - return ret; - } - - if (con->drizzle->options.is_non_blocking) - { - return DRIZZLE_RETURN_IO_WAIT; - } - - ret= drizzle_con_wait(con->drizzle); - if (ret != DRIZZLE_RETURN_OK) - { - return ret; - } - - continue; - } - else if (errno == ECONNREFUSED) - { - con->revents= 0; - drizzle_state_pop(con); - drizzle_state_push(con, drizzle_state_connect); - con->addrinfo_next= con->addrinfo_next->ai_next; - return DRIZZLE_RETURN_OK; - } - else if (errno == EINTR) - continue; - else if (errno == EPIPE || errno == ECONNRESET) - { - drizzle_set_error(con->drizzle, "drizzle_state_read", - "lost connection to server (%d)", errno); - return DRIZZLE_RETURN_LOST_CONNECTION; - } - - drizzle_set_error(con->drizzle, "drizzle_state_read", "read:%d", errno); - con->drizzle->last_errno= errno; - return DRIZZLE_RETURN_ERRNO; - } - - /* clear the "read ready" flag if we read all available data. */ - if ((size_t) read_size < available_buffer) con->revents&= ~POLLIN; - con->buffer_size+= (size_t)read_size; - break; - } - - drizzle_state_pop(con); - return DRIZZLE_RETURN_OK; -} - -drizzle_return_t drizzle_state_write(drizzle_con_st *con) -{ - if (con == NULL) - { - return DRIZZLE_RETURN_INVALID_ARGUMENT; - } - - drizzle_log_debug(con->drizzle, "drizzle_state_write"); - - while (con->buffer_size != 0) - { - ssize_t write_size = send(con->fd,(char *) con->buffer_ptr, con->buffer_size, 0); - -#ifdef _WIN32 - errno = WSAGetLastError(); - switch(errno) { - case WSAENOTCONN: - case WSAEWOULDBLOCK: - errno= EAGAIN; - break; - case WSAEINVAL: - case WSAEALREADY: - errno= EINPROGRESS; - break; - case WSAECONNREFUSED: - errno= ECONNREFUSED; - break; - case WSAENETUNREACH: - errno= ENETUNREACH; - break; - case WSAETIMEDOUT: - errno= ETIMEDOUT; - break; - case WSAECONNRESET: - errno= ECONNRESET; - break; - case WSAEADDRINUSE: - errno= EADDRINUSE; - break; - case WSAEOPNOTSUPP: - errno= EOPNOTSUPP; - break; - case WSAENOPROTOOPT: - errno= ENOPROTOOPT; - break; - default: - break; - } -#endif /* _WIN32 */ - - drizzle_log_crazy(con->drizzle, "write fd=%d return=%zd errno=%d", con->fd, - write_size, errno); - - if (write_size == 0) - { - drizzle_set_error(con->drizzle, "drizzle_state_write", - "lost connection to server (EOF)"); - return DRIZZLE_RETURN_LOST_CONNECTION; - } - else if (write_size == -1) - { - if (errno == EAGAIN) - { - drizzle_return_t ret= drizzle_con_set_events(con, POLLOUT); - if (ret != DRIZZLE_RETURN_OK) - { - return ret; - } - - if (con->drizzle->options.is_non_blocking) - { - return DRIZZLE_RETURN_IO_WAIT; - } - - ret= drizzle_con_wait(con->drizzle); - if (ret != DRIZZLE_RETURN_OK) - { - return ret; - } - - continue; - } - else if (errno == EINTR) - { - continue; - } - else if (errno == EPIPE || errno == ECONNRESET) - { - drizzle_set_error(con->drizzle, "drizzle_state_write", - "lost connection to server (%d)", errno); - return DRIZZLE_RETURN_LOST_CONNECTION; - } - - drizzle_set_error(con->drizzle, "drizzle_state_write", "write:%d", errno); - con->drizzle->last_errno= errno; - return DRIZZLE_RETURN_ERRNO; - } - - con->buffer_ptr+= write_size; - con->buffer_size-= (size_t)write_size; - if (con->buffer_size == 0) - break; - } - - con->buffer_ptr= con->buffer; - - drizzle_state_pop(con); - return DRIZZLE_RETURN_OK; -} - -drizzle_return_t drizzle_state_listen(drizzle_con_st *con) -{ - char host[NI_MAXHOST]; - char port[NI_MAXSERV]; - int ret; - int fd; - int opt; - drizzle_con_st *new_con; - - if (con == NULL) - { - return DRIZZLE_RETURN_INVALID_ARGUMENT; - } - - - for (; con->addrinfo_next != NULL; - con->addrinfo_next= con->addrinfo_next->ai_next) - { - ret= getnameinfo(con->addrinfo_next->ai_addr, - con->addrinfo_next->ai_addrlen, host, NI_MAXHOST, port, - NI_MAXSERV, NI_NUMERICHOST | NI_NUMERICSERV); - if (ret != 0) - { - drizzle_set_error(con->drizzle, "drizzle_state_listen", "getnameinfo:%s", - gai_strerror(ret)); - return DRIZZLE_RETURN_GETADDRINFO; - } - - /* Call to socket() can fail for some getaddrinfo results, try another. */ - fd= socket(con->addrinfo_next->ai_family, con->addrinfo_next->ai_socktype, - con->addrinfo_next->ai_protocol); - if (fd == -1) - { - drizzle_log_info(con->drizzle, "could not listen on %s:%s", host, port); - drizzle_set_error(con->drizzle, "drizzle_state_listen", "socket:%d", - errno); - continue; - } - - opt= 1; -#ifdef _WIN32 - ret= setsockopt(fd, SOL_SOCKET, SO_REUSEADDR,(const char*) &opt, sizeof(opt)); -#else - ret= setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(opt)); -#endif /* _WIN32 */ - if (ret == -1) - { - closesocket(fd); - drizzle_set_error(con->drizzle, "drizzle_state_listen", "setsockopt:%d", - errno); - return DRIZZLE_RETURN_ERRNO; - } - - ret= bind(fd, con->addrinfo_next->ai_addr, con->addrinfo_next->ai_addrlen); - if (ret == -1) - { - closesocket(fd); - drizzle_set_error(con->drizzle, "drizzle_state_listen", "bind:%d", errno); - if (errno == EADDRINUSE) - { - if (con->fd == -1) - { - drizzle_log_info(con->drizzle, "could not listen on %s:%s", host, - port); - } - - continue; - } - - return DRIZZLE_RETURN_ERRNO; - } - - if (listen(fd, con->backlog) == -1) - { - closesocket(fd); - drizzle_set_error(con->drizzle, "drizzle_state_listen", "listen:%d", - errno); - return DRIZZLE_RETURN_ERRNO; - } - - if (con->fd == -1) - { - con->fd= fd; - new_con= con; - } - else - { - new_con= drizzle_con_clone(con->drizzle, con); - if (new_con == NULL) - { - closesocket(fd); - return DRIZZLE_RETURN_MEMORY; - } - - new_con->fd= fd; - } - - /* Wait for read events on the listening socket. */ - drizzle_return_t driz_ret= drizzle_con_set_events(new_con, POLLIN); - if (ret != DRIZZLE_RETURN_OK) - { - drizzle_con_free(new_con); - return driz_ret; - } - - drizzle_log_info(con->drizzle, "listening on %s:%s", host, port); - } - - /* Report last socket() error if we couldn't find an address to bind. */ - if (con->fd == -1) - { - return DRIZZLE_RETURN_ERRNO; - } - - drizzle_state_pop(con); - return DRIZZLE_RETURN_OK; -} - -/* - * Static Definitions - */ - -static drizzle_return_t _con_setsockopt(drizzle_con_st *con) -{ - int ret; - struct linger linger; - struct timeval waittime; - - if (con == NULL) - { - return DRIZZLE_RETURN_INVALID_ARGUMENT; - } - - - ret= 1; - -#ifdef _WIN32 - ret= setsockopt(con->fd, IPPROTO_TCP, TCP_NODELAY, (const char*)&ret, - (socklen_t)sizeof(int)); -#else - ret= setsockopt(con->fd, IPPROTO_TCP, TCP_NODELAY, &ret, - (socklen_t)sizeof(int)); -#endif /* _WIN32 */ - - if (ret == -1 && errno != EOPNOTSUPP) - { - drizzle_set_error(con->drizzle, "_con_setsockopt", - "setsockopt:TCP_NODELAY:%d", errno); - return DRIZZLE_RETURN_ERRNO; - } - - linger.l_onoff= 1; - linger.l_linger= DRIZZLE_DEFAULT_SOCKET_TIMEOUT; - -#ifdef _WIN32 - ret= setsockopt(con->fd, SOL_SOCKET, SO_LINGER, (const char*)&linger, - (socklen_t)sizeof(struct linger)); -#else - ret= setsockopt(con->fd, SOL_SOCKET, SO_LINGER, &linger, - (socklen_t)sizeof(struct linger)); -#endif /* _WIN32 */ - - if (ret == -1) - { - drizzle_set_error(con->drizzle, "_con_setsockopt", - "setsockopt:SO_LINGER:%d", errno); - return DRIZZLE_RETURN_ERRNO; - } - - waittime.tv_sec= DRIZZLE_DEFAULT_SOCKET_TIMEOUT; - waittime.tv_usec= 0; - -#ifdef _WIN32 - ret= setsockopt(con->fd, SOL_SOCKET, SO_SNDTIMEO, (const char*)&waittime, - (socklen_t)sizeof(struct timeval)); -#else - ret= setsockopt(con->fd, SOL_SOCKET, SO_SNDTIMEO, &waittime, - (socklen_t)sizeof(struct timeval)); -#endif /* _WIN32 */ - - if (ret == -1 && errno != ENOPROTOOPT) - { - drizzle_set_error(con->drizzle, "_con_setsockopt", - "setsockopt:SO_SNDTIMEO:%d", errno); - return DRIZZLE_RETURN_ERRNO; - } - -#ifdef _WIN32 - ret= setsockopt(con->fd, SOL_SOCKET, SO_RCVTIMEO, (const char*)&waittime, - (socklen_t)sizeof(struct timeval)); -#else - ret= setsockopt(con->fd, SOL_SOCKET, SO_RCVTIMEO, &waittime, - (socklen_t)sizeof(struct timeval)); -#endif /* _WIN32 */ - - if (ret == -1 && errno != ENOPROTOOPT) - { - drizzle_set_error(con->drizzle, "_con_setsockopt", - "setsockopt:SO_RCVTIMEO:%d", errno); - return DRIZZLE_RETURN_ERRNO; - } - - ret= DRIZZLE_DEFAULT_SOCKET_SEND_SIZE; -#ifdef _WIN32 - ret= setsockopt(con->fd, SOL_SOCKET, SO_SNDBUF, (const char*)&ret, (socklen_t)sizeof(int)); -#else - ret= setsockopt(con->fd, SOL_SOCKET, SO_SNDBUF, &ret, (socklen_t)sizeof(int)); -#endif /* _WIN32 */ - if (ret == -1) - { - drizzle_set_error(con->drizzle, "_con_setsockopt", - "setsockopt:SO_SNDBUF:%d", errno); - return DRIZZLE_RETURN_ERRNO; - } - - ret= DRIZZLE_DEFAULT_SOCKET_RECV_SIZE; -#ifdef _WIN32 - ret= setsockopt(con->fd, SOL_SOCKET, SO_RCVBUF, (const char*)&ret, (socklen_t)sizeof(int)); -#else - ret= setsockopt(con->fd, SOL_SOCKET, SO_RCVBUF, &ret, (socklen_t)sizeof(int)); -#endif /* _WIN32 */ - if (ret == -1) - { - drizzle_set_error(con->drizzle, "_con_setsockopt", - "setsockopt:SO_RCVBUF:%d", errno); - return DRIZZLE_RETURN_ERRNO; - } - -#if defined (_WIN32) - { - unsigned long asyncmode; - asyncmode= 1; - ioctlsocket(con->fd, FIONBIO, &asyncmode); - } -#else - ret= fcntl(con->fd, F_GETFL, 0); - if (ret == -1) - { - drizzle_set_error(con->drizzle, "_con_setsockopt", "fcntl:F_GETFL:%d", - errno); - return DRIZZLE_RETURN_ERRNO; - } - - ret= fcntl(con->fd, F_SETFL, ret | O_NONBLOCK); - if (ret == -1) - { - drizzle_set_error(con->drizzle, "_con_setsockopt", "fcntl:F_SETFL:%d", - errno); - return DRIZZLE_RETURN_ERRNO; - } -#endif - - return DRIZZLE_RETURN_OK; -} diff --git a/utils/mysqlcl_idb/conn_uds.cc b/utils/mysqlcl_idb/conn_uds.cc deleted file mode 100644 index 6aa69517f..000000000 --- a/utils/mysqlcl_idb/conn_uds.cc +++ /dev/null @@ -1,79 +0,0 @@ -/* - * Drizzle Client & Protocol Library - * - * Copyright (C) 2008 Eric Day (eday@oddments.org) - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * - * * The names of its contributors may not be used to endorse or - * promote products derived from this software without specific prior - * written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -/** - * @file - * @brief Connection Definitions for Unix Domain Sockets - */ - -#include - -const char *drizzle_con_uds(const drizzle_con_st *con) -{ - if (con->socket_type == DRIZZLE_CON_SOCKET_UDS) - { - if (con->socket.uds.sockaddr.sun_path[0] != 0) - return con->socket.uds.sockaddr.sun_path; - - if (con->options & DRIZZLE_CON_MYSQL) - return DRIZZLE_DEFAULT_UDS_MYSQL; - - return DRIZZLE_DEFAULT_UDS; - } - - return NULL; -} - -void drizzle_con_set_uds(drizzle_con_st *con, const char *uds) -{ - drizzle_con_reset_addrinfo(con); - - con->socket_type= DRIZZLE_CON_SOCKET_UDS; - - if (uds == NULL) - uds= ""; - - con->socket.uds.sockaddr.sun_family= AF_UNIX; - strncpy(con->socket.uds.sockaddr.sun_path, uds, - sizeof(con->socket.uds.sockaddr.sun_path)); - con->socket.uds.sockaddr.sun_path[sizeof(con->socket.uds.sockaddr.sun_path) - 1]= 0; - - con->socket.uds.addrinfo.ai_family= AF_UNIX; - con->socket.uds.addrinfo.ai_socktype= SOCK_STREAM; - con->socket.uds.addrinfo.ai_protocol= 0; - con->socket.uds.addrinfo.ai_addrlen= sizeof(struct sockaddr_un); - con->socket.uds.addrinfo.ai_addr= (struct sockaddr *)&(con->socket.uds.sockaddr); -} diff --git a/utils/mysqlcl_idb/drizzle.cc b/utils/mysqlcl_idb/drizzle.cc deleted file mode 100644 index d4fb36d4c..000000000 --- a/utils/mysqlcl_idb/drizzle.cc +++ /dev/null @@ -1,761 +0,0 @@ -/* - * Drizzle Client & Protocol Library - * - * Copyright (C) 2008 Eric Day (eday@oddments.org) - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * - * * The names of its contributors may not be used to endorse or - * promote products derived from this software without specific prior - * written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -/** - * @file - * @brief Drizzle Definitions - */ - -#include - -/** - * @addtogroup drizzle_static Static Drizzle Declarations - * @ingroup drizzle - * @{ - */ - -/** - * Names of the verbose levels provided. - */ -static const char *_verbose_name[DRIZZLE_VERBOSE_MAX]= -{ - "NEVER", - "FATAL", - "ERROR", - "INFO", - "DEBUG", - "CRAZY" -}; - -/** @} */ - -/* - * Common Definitions - */ - -const char *drizzle_version() -{ - return PACKAGE_VERSION; -} - -const char *drizzle_bugreport() -{ - return PACKAGE_BUGREPORT; -} - -const char *drizzle_verbose_name(drizzle_verbose_t verbose) -{ - if (verbose >= DRIZZLE_VERBOSE_MAX) - { - return "UNKNOWN"; - } - - return _verbose_name[verbose]; -} - -drizzle_st *drizzle_create() -{ -#if defined(_WIN32) - /* if it is MS windows, invoke WSAStartup */ - WSADATA wsaData; - if ( WSAStartup( MAKEWORD(2,2), &wsaData ) != 0 ) - printf("Error at WSAStartup()\n"); -#else - struct sigaction act; - memset(&act, 0, sizeof(act)); - - act.sa_handler = SIG_IGN; - sigaction(SIGPIPE, &act, NULL); -#endif - - drizzle_st *drizzle= new (std::nothrow) drizzle_st; - - if (drizzle == NULL) - { - return NULL; - } - - /* @todo remove this default free flag with new API. */ - drizzle->options.is_free_objects= true; - drizzle->error_code= 0; - - /* drizzle->options set above */ - drizzle->verbose= DRIZZLE_VERBOSE_NEVER; - drizzle->con_count= 0; - drizzle->pfds_size= 0; - drizzle->query_count= 0; - drizzle->query_new= 0; - drizzle->query_running= 0; - drizzle->last_errno= 0; - drizzle->timeout= -1; - drizzle->con_list= NULL; - drizzle->context= NULL; - drizzle->context_free_fn= NULL; - drizzle->event_watch_fn= NULL; - drizzle->event_watch_context= NULL; - drizzle->log_fn= NULL; - drizzle->log_context= NULL; - drizzle->pfds= NULL; - drizzle->query_list= NULL; - drizzle->sqlstate[0]= 0; - drizzle->last_error[0]= 0; - - return drizzle; -} - -drizzle_st *drizzle_clone(const drizzle_st *source) -{ - drizzle_st *drizzle= drizzle_create(); - if (drizzle == NULL) - { - return NULL; - } - - for (drizzle_con_st* con= source->con_list; con != NULL; con= con->next) - { - if (drizzle_con_clone(drizzle, con) == NULL) - { - drizzle_free(drizzle); - return NULL; - } - } - - return drizzle; -} - -void drizzle_free(drizzle_st *drizzle) -{ - if (drizzle->context != NULL && drizzle->context_free_fn != NULL) - { - drizzle->context_free_fn(drizzle, drizzle->context); - } - - if (drizzle->options.is_free_objects) - { - drizzle_con_free_all(drizzle); - drizzle_query_free_all(drizzle); - } - else if (drizzle->options.is_assert_dangling) - { - assert(drizzle->con_list == NULL); - assert(drizzle->query_list == NULL); - } - - free(drizzle->pfds); - - delete drizzle; -#if defined(_WIN32) - /* if it is MS windows, invoke WSACleanup() at the end*/ - WSACleanup(); -#endif -} - -const char *drizzle_error(const drizzle_st *drizzle) -{ - return drizzle->last_error; -} - -drizzle_return_t drizzle_set_option(drizzle_st *drizzle, drizzle_options_t arg, bool set) -{ - switch (arg) - { - case DRIZZLE_NON_BLOCKING: - drizzle->options.is_non_blocking= set; - return DRIZZLE_RETURN_OK; - - case DRIZZLE_FREE_OBJECTS: - return DRIZZLE_RETURN_OK; - - case DRIZZLE_ASSERT_DANGLING: - return DRIZZLE_RETURN_OK; - - default: - break; - } - - return DRIZZLE_RETURN_INVALID_ARGUMENT; -} - -int drizzle_errno(const drizzle_st *drizzle) -{ - return drizzle->last_errno; -} - -uint16_t drizzle_error_code(const drizzle_st *drizzle) -{ - return drizzle->error_code; -} - -const char *drizzle_sqlstate(const drizzle_st *drizzle) -{ - return drizzle->sqlstate; -} - -void *drizzle_context(const drizzle_st *drizzle) -{ - return drizzle->context; -} - -void drizzle_set_context(drizzle_st *drizzle, void *context) -{ - drizzle->context= context; -} - -void drizzle_set_context_free_fn(drizzle_st *drizzle, - drizzle_context_free_fn *function) -{ - drizzle->context_free_fn= function; -} - -int drizzle_timeout(const drizzle_st *drizzle) -{ - return drizzle->timeout; -} - -void drizzle_set_timeout(drizzle_st *drizzle, int timeout) -{ - drizzle->timeout= timeout; -} - -drizzle_verbose_t drizzle_verbose(const drizzle_st *drizzle) -{ - return drizzle->verbose; -} - -void drizzle_set_verbose(drizzle_st *drizzle, drizzle_verbose_t verbose) -{ - drizzle->verbose= verbose; -} - -void drizzle_set_log_fn(drizzle_st *drizzle, drizzle_log_fn *function, - void *context) -{ - drizzle->log_fn= function; - drizzle->log_context= context; -} - -void drizzle_set_event_watch_fn(drizzle_st *drizzle, - drizzle_event_watch_fn *function, - void *context) -{ - drizzle->event_watch_fn= function; - drizzle->event_watch_context= context; -} - -drizzle_con_st *drizzle_con_create(drizzle_st *drizzle) -{ - if (drizzle == NULL) - { - return NULL; - } - - drizzle_con_st *con= new (std::nothrow) drizzle_con_st; - - if (con == NULL) - { - return NULL; - } - - if (drizzle->con_list != NULL) - { - drizzle->con_list->prev= con; - } - - con->next= drizzle->con_list; - con->prev= NULL; - drizzle->con_list= con; - drizzle->con_count++; - - con->packet_number= 0; - con->protocol_version= 0; - con->state_current= 0; - con->events= 0; - con->revents= 0; - con->capabilities= DRIZZLE_CAPABILITIES_NONE; - con->charset= 0; - con->command= DRIZZLE_COMMAND_SLEEP; - con->options|= DRIZZLE_CON_MYSQL; - con->socket_type= DRIZZLE_CON_SOCKET_TCP; - con->status= DRIZZLE_CON_STATUS_NONE; - con->max_packet_size= DRIZZLE_MAX_PACKET_SIZE; - con->result_count= 0; - con->thread_id= 0; - con->backlog= DRIZZLE_DEFAULT_BACKLOG; - con->fd= -1; - con->buffer_size= 0; - con->command_offset= 0; - con->command_size= 0; - con->command_total= 0; - con->packet_size= 0; - con->addrinfo_next= NULL; - con->buffer_ptr= con->buffer; - con->command_buffer= NULL; - con->command_data= NULL; - con->context= NULL; - con->context_free_fn= NULL; - con->drizzle= drizzle; - /* con->next set above */ - /* con->prev set above */ - con->query= NULL; - /* con->result doesn't need to be set */ - con->result_list= NULL; - con->scramble= NULL; - con->socket.tcp.addrinfo= NULL; - con->socket.tcp.host= NULL; - con->socket.tcp.port= 0; - /* con->buffer doesn't need to be set */ - con->schema[0]= 0; - con->password[0]= 0; - /* con->scramble_buffer doesn't need to be set */ - con->server_version[0]= 0; - /* con->state_stack doesn't need to be set */ - con->user[0]= 0; - - return con; -} - -drizzle_con_st *drizzle_con_clone(drizzle_st *drizzle, drizzle_con_st *source) -{ - drizzle_con_st *con= drizzle_con_create(drizzle); - if (con == NULL) - { - return NULL; - } - - /* Clear "operational" options such as IO status. */ - con->options|= (source->options & ~(DRIZZLE_CON_ALLOCATED|DRIZZLE_CON_READY| - DRIZZLE_CON_NO_RESULT_READ|DRIZZLE_CON_IO_READY| - DRIZZLE_CON_LISTEN)); - con->backlog= source->backlog; - strcpy(con->schema, source->schema); - strcpy(con->password, source->password); - strcpy(con->user, source->user); - - switch (source->socket_type) - { - case DRIZZLE_CON_SOCKET_TCP: - drizzle_con_set_tcp(con, source->socket.tcp.host, source->socket.tcp.port); - break; - - case DRIZZLE_CON_SOCKET_UDS: - drizzle_con_set_uds(con, source->socket.uds.sockaddr.sun_path); - break; - } - - return con; -} - -void drizzle_con_free(drizzle_con_st *con) -{ - if (con->context != NULL && con->context_free_fn != NULL) - { - con->context_free_fn(con, con->context); - } - - if (con->drizzle->options.is_free_objects) - { - drizzle_result_free_all(con); - } - else if (con->drizzle->options.is_assert_dangling) - { - assert(con->result_list == NULL); - } - - if (con->fd != -1) - { - drizzle_con_close(con); - } - - drizzle_con_reset_addrinfo(con); - - if (con->drizzle->con_list == con) - { - con->drizzle->con_list= con->next; - } - if (con->prev != NULL) - { - con->prev->next= con->next; - } - if (con->next != NULL) - { - con->next->prev= con->prev; - } - con->drizzle->con_count--; - - delete con; -} - -void drizzle_con_free_all(drizzle_st *drizzle) -{ - while (drizzle->con_list != NULL) - { - drizzle_con_free(drizzle->con_list); - } -} - -drizzle_return_t drizzle_con_wait(drizzle_st *drizzle) -{ - struct pollfd *pfds; - int ret; - drizzle_return_t dret; - - if (drizzle->pfds_size < drizzle->con_count) - { - pfds= (struct pollfd *)realloc(drizzle->pfds, drizzle->con_count * sizeof(struct pollfd)); - if (pfds == NULL) - { - drizzle_set_error(drizzle, "drizzle_con_wait", "realloc"); - return DRIZZLE_RETURN_MEMORY; - } - - drizzle->pfds= pfds; - drizzle->pfds_size= drizzle->con_count; - } - else - { - pfds= drizzle->pfds; - } - - uint32_t x= 0; - for (drizzle_con_st* con= drizzle->con_list; con != NULL; con= con->next) - { - if (con->events == 0) - continue; - - pfds[x].fd= con->fd; - pfds[x].events= con->events; - pfds[x].revents= 0; - x++; - } - - if (x == 0) - { - drizzle_set_error(drizzle, "drizzle_con_wait", - "no active file descriptors"); - return DRIZZLE_RETURN_NO_ACTIVE_CONNECTIONS; - } - - while (1) - { - drizzle_log_crazy(drizzle, "poll count=%d timeout=%d", x, - drizzle->timeout); - - ret= poll(pfds, x, drizzle->timeout); - - drizzle_log_crazy(drizzle, "poll return=%d errno=%d", ret, errno); - - if (ret == -1) - { - if (errno == EINTR) - continue; - - drizzle_set_error(drizzle, "drizzle_con_wait", "poll:%d", errno); - drizzle->last_errno= errno; - return DRIZZLE_RETURN_ERRNO; - } - - break; - } - - if (ret == 0) - { - drizzle_set_error(drizzle, "drizzle_con_wait", "timeout reached"); - return DRIZZLE_RETURN_TIMEOUT; - } - - x= 0; - for (drizzle_con_st* con= drizzle->con_list; con != NULL; con= con->next) - { - if (con->events == 0) - continue; - - dret= drizzle_con_set_revents(con, pfds[x].revents); - if (dret != DRIZZLE_RETURN_OK) - return dret; - - x++; - } - - return DRIZZLE_RETURN_OK; -} - -drizzle_con_st *drizzle_con_ready(drizzle_st *drizzle) -{ - /* We can't keep state between calls since connections may be removed during - processing. If this list ever gets big, we may want something faster. */ - - for (drizzle_con_st* con= drizzle->con_list; con != NULL; con= con->next) - { - if (con->options & DRIZZLE_CON_IO_READY) - { - con->options&= ~DRIZZLE_CON_IO_READY; - return con; - } - } - return NULL; -} - -drizzle_con_st *drizzle_con_ready_listen(drizzle_st *drizzle) -{ - /* We can't keep state between calls since connections may be removed during - processing. If this list ever gets big, we may want something faster. */ - - for (drizzle_con_st* con= drizzle->con_list; con != NULL; con= con->next) - { - if ((con->options & (DRIZZLE_CON_IO_READY | DRIZZLE_CON_LISTEN)) == - (DRIZZLE_CON_IO_READY | DRIZZLE_CON_LISTEN)) - { - con->options&= ~DRIZZLE_CON_IO_READY; - return con; - } - } - return NULL; -} - -/* - * Client Definitions - */ - -drizzle_con_st *drizzle_con_add_tcp(drizzle_st *drizzle, - const char *host, in_port_t port, - const char *user, const char *password, - const char *db, - drizzle_con_options_t options) -{ - drizzle_con_st *con= drizzle_con_create(drizzle); - if (con == NULL) - { - return NULL; - } - - drizzle_con_set_tcp(con, host, port); - drizzle_con_set_auth(con, user, password); - drizzle_con_set_db(con, db); - drizzle_con_add_options(con, options); - - return con; -} - -drizzle_con_st *drizzle_con_add_uds(drizzle_st *drizzle, - const char *uds, const char *user, - const char *password, const char *db, - drizzle_con_options_t options) -{ - drizzle_con_st *con= drizzle_con_create(drizzle); - if (con == NULL) - { - return NULL; - } - - drizzle_con_set_uds(con, uds); - drizzle_con_set_auth(con, user, password); - drizzle_con_set_db(con, db); - drizzle_con_add_options(con, options); - - return con; -} - -/* - * Server Definitions - */ - -drizzle_con_st *drizzle_con_add_tcp_listen(drizzle_st *drizzle, - const char *host, in_port_t port, - int backlog, - drizzle_con_options_t options) -{ - drizzle_con_st *con= drizzle_con_create(drizzle); - if (con == NULL) - { - return NULL; - } - - drizzle_con_set_tcp(con, host, port); - drizzle_con_set_backlog(con, backlog); - drizzle_con_add_options(con, options | DRIZZLE_CON_LISTEN); - - return con; -} - -drizzle_con_st *drizzle_con_add_uds_listen(drizzle_st *drizzle, - const char *uds, int backlog, - drizzle_con_options_t options) -{ - drizzle_con_st *con= drizzle_con_create(drizzle); - if (con == NULL) - { - return NULL; - } - - drizzle_con_set_uds(con, uds); - drizzle_con_set_backlog(con, backlog); - drizzle_con_add_options(con, options | DRIZZLE_CON_LISTEN); - - return con; -} - -drizzle_con_st *drizzle_con_accept(drizzle_st *drizzle, - drizzle_return_t *ret_ptr) -{ - drizzle_return_t unused; - if (ret_ptr == NULL) - { - ret_ptr= &unused; - } - - while (1) - { - if (drizzle_con_st* ready= drizzle_con_ready_listen(drizzle)) - { - int fd= accept(ready->fd, NULL, NULL); - - drizzle_con_st *con= drizzle_con_create(drizzle); - if (con == NULL) - { - (void)closesocket(fd); - *ret_ptr= DRIZZLE_RETURN_MEMORY; - return NULL; - } - - *ret_ptr= drizzle_con_set_fd(con, fd); - if (*ret_ptr != DRIZZLE_RETURN_OK) - { - (void)closesocket(fd); - return NULL; - } - - if (ready->options & DRIZZLE_CON_MYSQL) - drizzle_con_add_options(con, DRIZZLE_CON_MYSQL); - - *ret_ptr= DRIZZLE_RETURN_OK; - return con; - } - - if (drizzle->options.is_non_blocking) - { - *ret_ptr= DRIZZLE_RETURN_IO_WAIT; - return NULL; - } - - for (drizzle_con_st* ready= drizzle->con_list; ready != NULL; ready= ready->next) - { - if (ready->options & DRIZZLE_CON_LISTEN) - { - drizzle_con_set_events(ready, POLLIN); - } - } - - *ret_ptr= drizzle_con_wait(drizzle); - if (*ret_ptr != DRIZZLE_RETURN_OK) - { - return NULL; - } - } -} - -/* - * Local Definitions - */ - -void drizzle_set_error(drizzle_st *drizzle, const char *function, - const char *format, ...) -{ - if (drizzle == NULL) - { - return; - } - char log_buffer[DRIZZLE_MAX_ERROR_SIZE]; - - size_t size= strlen(function); - char* ptr= (char *)memcpy(log_buffer, function, size); - ptr+= size; - ptr[0]= ':'; - size++; - ptr++; - - va_list args; - va_start(args, format); - int written= vsnprintf(ptr, DRIZZLE_MAX_ERROR_SIZE - size, format, args); - va_end(args); - - if (written < 0) - { - size= DRIZZLE_MAX_ERROR_SIZE; - } - else - { - size+= written; - } - - if (size >= DRIZZLE_MAX_ERROR_SIZE) - { - size= DRIZZLE_MAX_ERROR_SIZE - 1; - } - log_buffer[size]= 0; - - if (drizzle->log_fn == NULL) - { - memcpy(drizzle->last_error, log_buffer, size + 1); - } - else - { - drizzle->log_fn(log_buffer, DRIZZLE_VERBOSE_ERROR, drizzle->log_context); - } -} - -void drizzle_log(drizzle_st *drizzle, drizzle_verbose_t verbose, - const char *format, va_list args) -{ - char log_buffer[DRIZZLE_MAX_ERROR_SIZE]; - - if (drizzle == NULL) - { - return; - } - - if (drizzle->log_fn == NULL) - { - printf("%5s: ", drizzle_verbose_name(verbose)); - vprintf(format, args); - printf("\n"); - } - else - { - vsnprintf(log_buffer, DRIZZLE_MAX_ERROR_SIZE, format, args); - log_buffer[DRIZZLE_MAX_ERROR_SIZE-1]= 0; - drizzle->log_fn(log_buffer, verbose, drizzle->log_context); - } -} diff --git a/utils/mysqlcl_idb/field.cc b/utils/mysqlcl_idb/field.cc deleted file mode 100644 index 3af7e4d5d..000000000 --- a/utils/mysqlcl_idb/field.cc +++ /dev/null @@ -1,396 +0,0 @@ -/* - * Drizzle Client & Protocol Library - * - * Copyright (C) 2008 Eric Day (eday@oddments.org) - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * - * * The names of its contributors may not be used to endorse or - * promote products derived from this software without specific prior - * written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -/** - * @file - * @brief Field definitions - */ - -#include - -/* - * Client definitions - */ - -drizzle_field_t drizzle_field_read(drizzle_result_st *result, size_t *offset, - size_t *size, size_t *total, - drizzle_return_t *ret_ptr) -{ - if (drizzle_state_none(result->con)) - { - if (result->field_current == result->column_count) - { - *ret_ptr= DRIZZLE_RETURN_ROW_END; - return NULL; - } - - drizzle_state_push(result->con, drizzle_state_field_read); - } - - *ret_ptr= drizzle_state_loop(result->con); - if (*ret_ptr == DRIZZLE_RETURN_OK && - result->options & DRIZZLE_RESULT_ROW_BREAK) - { - *ret_ptr= DRIZZLE_RETURN_ROW_BREAK; - } - - *offset= result->field_offset; - *size= result->field_size; - *total= result->field_total; - - return result->field; -} - -drizzle_field_t drizzle_field_buffer(drizzle_result_st *result, size_t *total, - drizzle_return_t *ret_ptr) -{ - size_t offset= 0; - size_t size= 0; - - drizzle_return_t unused; - if (ret_ptr == NULL) - { - ret_ptr= &unused; - } - - drizzle_field_t field= drizzle_field_read(result, &offset, &size, total, ret_ptr); - if (*ret_ptr != DRIZZLE_RETURN_OK) - { - return NULL; - } - - if (field == NULL) - { - *total= 0; - return NULL; - } - - if (result->field_buffer == NULL) - { - result->field_buffer= new (std::nothrow) drizzle_field_t_type[(*total) + 1]; - - if (result->field_buffer == NULL) - { - *ret_ptr= DRIZZLE_RETURN_MEMORY; - *total= 0; - return NULL; - } - } - - memcpy(result->field_buffer + offset, field, size); - - while ((offset + size) != (*total)) - { - field= drizzle_field_read(result, &offset, &size, total, ret_ptr); - if (*ret_ptr != DRIZZLE_RETURN_OK) - { - return NULL; - } - - memcpy(result->field_buffer + offset, field, size); - } - - field= result->field_buffer; - result->field_buffer= NULL; - field[*total]= 0; - - return field; -} - -void drizzle_field_free(drizzle_field_t field) -{ - delete[] field; -} - -/* - * Server definitions - */ - -drizzle_return_t drizzle_field_write(drizzle_result_st *result, - const drizzle_field_t field, size_t size, - size_t total) -{ - drizzle_return_t ret; - - if (drizzle_state_none(result->con)) - { - if (result->options & DRIZZLE_RESULT_ROW_BREAK) - { - result->options&= ~DRIZZLE_RESULT_ROW_BREAK; - result->field= field; - result->field_size= size; - } - else - { - result->field= field; - result->field_size= size; - result->field_offset= 0; - result->field_total= total; - } - - drizzle_state_push(result->con, drizzle_state_field_write); - } - else if (result->field == NULL) - { - result->field= field; - result->field_size= size; - } - - ret= drizzle_state_loop(result->con); - if (ret == DRIZZLE_RETURN_PAUSE) - ret= DRIZZLE_RETURN_OK; - - return ret; -} - -/* - * Internal state functions. - */ - -drizzle_return_t drizzle_state_field_read(drizzle_con_st *con) -{ - drizzle_return_t ret; - - drizzle_log_debug(con->drizzle, "drizzle_state_field_read"); - - if (con->buffer_size == 0) - { - drizzle_state_push(con, drizzle_state_read); - return DRIZZLE_RETURN_OK; - } - - con->result->field_offset+= con->result->field_size; - if (con->result->field_offset == con->result->field_total) - { - con->result->field_offset= 0; - con->result->field_size= 0; - - con->result->field_total= (size_t)drizzle_unpack_length(con, &ret); - if (ret == DRIZZLE_RETURN_NULL_SIZE) - { - con->result->field= NULL; - con->result->field_current++; - drizzle_state_pop(con); - return DRIZZLE_RETURN_OK; - } - else if (ret != DRIZZLE_RETURN_OK) - { - if (ret == DRIZZLE_RETURN_IO_WAIT) - { - drizzle_state_push(con, drizzle_state_read); - return DRIZZLE_RETURN_OK; - } - - return ret; - } - - drizzle_log_debug(con->drizzle, - "field_offset= %zu, field_size= %zu, field_total= %zu", - con->result->field_offset, con->result->field_size, - con->result->field_total); - - if ((size_t)(con->buffer_size) >= con->result->field_total) - con->result->field_size= con->result->field_total; - else - con->result->field_size= con->buffer_size; - } - else - { - if ((con->result->field_offset + con->buffer_size) >= - con->result->field_total) - { - con->result->field_size= (con->result->field_total - - con->result->field_offset); - } - else - con->result->field_size= con->buffer_size; - } - - /* This is a special case when a row is larger than the packet size. */ - if (con->result->field_size > (size_t)con->packet_size) - { - con->result->field_size= con->packet_size; - - if (con->options & DRIZZLE_CON_RAW_PACKET) - con->result->options|= DRIZZLE_RESULT_ROW_BREAK; - else - { - drizzle_state_pop(con); - drizzle_state_push(con, drizzle_state_packet_read); - drizzle_state_push(con, drizzle_state_field_read); - } - } - - con->result->field= (char *)con->buffer_ptr; - con->buffer_ptr+= con->result->field_size; - con->buffer_size-= con->result->field_size; - con->packet_size-= con->result->field_size; - - drizzle_log_debug(con->drizzle, - "field_offset= %zu, field_size= %zu, field_total= %zu", - con->result->field_offset, con->result->field_size, - con->result->field_total); - - if ((con->result->field_offset + con->result->field_size) == - con->result->field_total) - { - if (con->result->column_buffer != NULL && - con->result->column_buffer[con->result->field_current].max_size < - con->result->field_total) - { - con->result->column_buffer[con->result->field_current].max_size= - con->result->field_total; - } - - con->result->field_current++; - } - - if (con->result->field_total == 0 || con->result->field_size > 0 || - con->packet_size == 0) - { - drizzle_state_pop(con); - } - - return DRIZZLE_RETURN_OK; -} - -drizzle_return_t drizzle_state_field_write(drizzle_con_st *con) -{ - uint8_t *start= con->buffer_ptr + con->buffer_size; - uint8_t *ptr; - size_t free_size; - drizzle_result_st *result= con->result; - - drizzle_log_debug(con->drizzle, "drizzle_state_field_write"); - - if (result->field == NULL && result->field_total != 0) - return DRIZZLE_RETURN_PAUSE; - - free_size= (size_t)DRIZZLE_MAX_BUFFER_SIZE - (size_t)(start - con->buffer); - ptr= start; - - if (result->field_offset == 0) - { - /* Make sure we can fit the max length and 1 byte of data in (9 + 1). */ - if (free_size < 10) - { - drizzle_state_push(con, drizzle_state_write); - return DRIZZLE_RETURN_OK; - } - - if (result->field == NULL) - { - ptr[0]= 251; - ptr++; - } - else if (result->field_total == 0) - { - ptr[0]= 0; - ptr++; - } - else - ptr= drizzle_pack_length(result->field_total, ptr); - - free_size-= (size_t)(ptr - start); - con->buffer_size+= (size_t)(ptr - start); - con->packet_size-= (size_t)(ptr - start); - } - else if (result->field_size > DRIZZLE_BUFFER_COPY_THRESHOLD) - { - /* Flush the internal buffer first. */ - if (con->buffer_size != 0) - { - drizzle_state_push(con, drizzle_state_write); - return DRIZZLE_RETURN_OK; - } - - /* We do this to write directly from the field buffer to avoid memcpy(). */ - con->buffer_ptr= (uint8_t *)result->field; - con->buffer_size= result->field_size; - con->packet_size-= result->field_size; - result->field_offset+= result->field_size; - result->field= NULL; - - if (result->field_offset == result->field_total) - drizzle_state_pop(con); - else if (con->packet_size == 0) - { - con->result->options|= DRIZZLE_RESULT_ROW_BREAK; - drizzle_state_pop(con); - } - - drizzle_state_push(con, drizzle_state_write); - return DRIZZLE_RETURN_OK; - } - - if (result->field_size == 0) - drizzle_state_pop(con); - else - { - if (result->field_size < free_size) - free_size= result->field_size; - - memcpy(ptr, result->field, free_size); - result->field_offset+= free_size; - con->buffer_size+= free_size; - con->packet_size-= free_size; - - if (result->field_offset == result->field_total) - { - result->field= NULL; - drizzle_state_pop(con); - } - else - { - if (con->packet_size == 0) - { - con->result->options|= DRIZZLE_RESULT_ROW_BREAK; - drizzle_state_pop(con); - } - - if (result->field_size == free_size) - result->field= NULL; - else - { - result->field+= free_size; - result->field_size-= free_size; - drizzle_state_push(con, drizzle_state_write); - } - } - } - - return DRIZZLE_RETURN_OK; -} diff --git a/utils/mysqlcl_idb/handshake.cc b/utils/mysqlcl_idb/handshake.cc deleted file mode 100644 index 6a2d725d0..000000000 --- a/utils/mysqlcl_idb/handshake.cc +++ /dev/null @@ -1,612 +0,0 @@ -/* - * Drizzle Client & Protocol Library - * - * Copyright (C) 2008 Eric Day (eday@oddments.org) - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * - * * The names of its contributors may not be used to endorse or - * promote products derived from this software without specific prior - * written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -/** - * @file - * @brief Handshake Definitions - */ - -#include - -/* - * Client Definitions - */ - -drizzle_return_t drizzle_handshake_server_read(drizzle_con_st *con) -{ - if (drizzle_state_none(con)) - { - drizzle_state_push(con, drizzle_state_handshake_server_read); - drizzle_state_push(con, drizzle_state_packet_read); - } - - return drizzle_state_loop(con); -} - -drizzle_return_t drizzle_handshake_client_write(drizzle_con_st *con) -{ - if (drizzle_state_none(con)) - { - drizzle_state_push(con, drizzle_state_write); - drizzle_state_push(con, drizzle_state_handshake_client_write); - } - - return drizzle_state_loop(con); -} - -/* - * Server Definitions - */ - -drizzle_return_t drizzle_handshake_server_write(drizzle_con_st *con) -{ - if (drizzle_state_none(con)) - { - drizzle_state_push(con, drizzle_state_write); - drizzle_state_push(con, drizzle_state_handshake_server_write); - } - - return drizzle_state_loop(con); -} - -drizzle_return_t drizzle_handshake_client_read(drizzle_con_st *con) -{ - if (drizzle_state_none(con)) - { - drizzle_state_push(con, drizzle_state_handshake_client_read); - drizzle_state_push(con, drizzle_state_packet_read); - } - - return drizzle_state_loop(con); -} - -/* - * State Definitions - */ - -drizzle_return_t drizzle_state_handshake_server_read(drizzle_con_st *con) -{ - uint8_t *ptr; - int extra_length; - unsigned char* packet_end; - - drizzle_log_debug(con->drizzle, "drizzle_state_handshake_server_read"); - - /* Assume the entire handshake packet will fit in the buffer. */ - if (con->buffer_size < con->packet_size) - { - drizzle_state_push(con, drizzle_state_read); - return DRIZZLE_RETURN_OK; - } - - if (con->packet_size < 46) - { - drizzle_set_error(con->drizzle, "drizzle_state_handshake_server_read", - "bad packet size:>=46:%zu", con->packet_size); - return DRIZZLE_RETURN_BAD_HANDSHAKE_PACKET; - } - - packet_end= con->buffer_ptr + con->packet_size; - con->protocol_version= con->buffer_ptr[0]; - con->buffer_ptr++; - - if (con->protocol_version != 10) - { - /* This is a special case where the server determines that authentication - will be impossible and denies any attempt right away. */ - if (con->protocol_version == 255) - { - drizzle_set_error(con->drizzle, "drizzle_state_handshake_server_read", - "%.*s", (int32_t)con->packet_size - 3, - con->buffer_ptr + 2); - return DRIZZLE_RETURN_AUTH_FAILED; - } - - drizzle_set_error(con->drizzle, "drizzle_state_handshake_server_read", - "protocol version not supported:%d", - con->protocol_version); - return DRIZZLE_RETURN_PROTOCOL_NOT_SUPPORTED; - } - - /* Look for null-terminated server version string. */ - ptr= (uint8_t *)memchr(con->buffer_ptr, 0, con->buffer_size - 1); - if (ptr == NULL) - { - drizzle_set_error(con->drizzle, "drizzle_state_handshake_server_read", - "server version string not found"); - return DRIZZLE_RETURN_BAD_HANDSHAKE_PACKET; - } - - if (con->packet_size < (46 + (size_t)(ptr - con->buffer_ptr))) - { - drizzle_set_error(con->drizzle, "drizzle_state_handshake_server_read", - "bad packet size:%zu:%zu", - (46 + (size_t)(ptr - con->buffer_ptr)), con->packet_size); - return DRIZZLE_RETURN_BAD_HANDSHAKE_PACKET; - } - - strncpy(con->server_version, (char *)con->buffer_ptr, - DRIZZLE_MAX_SERVER_VERSION_SIZE); - con->server_version[DRIZZLE_MAX_SERVER_VERSION_SIZE - 1]= 0; - con->buffer_ptr+= ((ptr - con->buffer_ptr) + 1); - - con->thread_id= (uint32_t)drizzle_get_byte4(con->buffer_ptr); - con->buffer_ptr+= 4; - - con->scramble= con->scramble_buffer; - memcpy(con->scramble, con->buffer_ptr, 8); - /* Skip scramble and filler. */ - con->buffer_ptr+= 9; - - /* Even though drizzle_capabilities is more than 2 bytes, the protocol only - allows for 2. This means some capabilities are not possible during this - handshake step. The options beyond 2 bytes are for client response only. */ - con->capabilities= (drizzle_capabilities_t)drizzle_get_byte2(con->buffer_ptr); - con->buffer_ptr+= 2; - - if (con->options & DRIZZLE_CON_MYSQL && - !(con->capabilities & DRIZZLE_CAPABILITIES_PROTOCOL_41)) - { - drizzle_set_error(con->drizzle, "drizzle_state_handshake_server_read", - "protocol version not supported, must be MySQL 4.1+"); - return DRIZZLE_RETURN_PROTOCOL_NOT_SUPPORTED; - } - - con->charset= con->buffer_ptr[0]; - con->buffer_ptr+= 1; - - con->status= (drizzle_con_status_t)drizzle_get_byte2(con->buffer_ptr); - /* Skip status and filler. */ - con->buffer_ptr+= 15; - - memcpy(con->scramble + 8, con->buffer_ptr, 12); - con->buffer_ptr+= 13; - - /* MySQL 5.5 adds "mysql_native_password" after the server greeting. */ - extra_length= packet_end - con->buffer_ptr; - assert(extra_length >= 0); - if (extra_length > DRIZZLE_MAX_SERVER_EXTRA_SIZE - 1) - extra_length= DRIZZLE_MAX_SERVER_EXTRA_SIZE - 1; - memcpy(con->server_extra, (char *)con->buffer_ptr, extra_length); - con->server_extra[extra_length]= 0; - - con->buffer_size-= con->packet_size; - if (con->buffer_size != 0) - { - drizzle_set_error(con->drizzle, "drizzle_state_handshake_server_read", - "unexpected data after packet:%zu", con->buffer_size); - return DRIZZLE_RETURN_UNEXPECTED_DATA; - } - - con->buffer_ptr= con->buffer; - - drizzle_state_pop(con); - - if (!(con->options & DRIZZLE_CON_RAW_PACKET)) - { - drizzle_state_push(con, drizzle_state_handshake_result_read); - drizzle_state_push(con, drizzle_state_packet_read); - drizzle_state_push(con, drizzle_state_write); - drizzle_state_push(con, drizzle_state_handshake_client_write); - } - - return DRIZZLE_RETURN_OK; -} - -drizzle_return_t drizzle_state_handshake_server_write(drizzle_con_st *con) -{ - uint8_t *ptr; - - drizzle_log_debug(con->drizzle, "drizzle_state_handshake_server_write"); - - /* Calculate max packet size. */ - con->packet_size= 1 /* Protocol version */ - + strlen(con->server_version) + 1 - + 4 /* Thread ID */ - + 8 /* Scramble */ - + 1 /* NULL */ - + 2 /* Capabilities */ - + 1 /* Language */ - + 2 /* Status */ - + 13 /* Unused */ - + 12 /* Scramble */ - + 1; /* NULL */ - - /* Assume the entire handshake packet will fit in the buffer. */ - if ((con->packet_size + 4) > DRIZZLE_MAX_BUFFER_SIZE) - { - drizzle_set_error(con->drizzle, "drizzle_state_handshake_server_write", - "buffer too small:%zu", con->packet_size + 4); - return DRIZZLE_RETURN_INTERNAL_ERROR; - } - - ptr= con->buffer_ptr; - - /* Store packet size and packet number first. */ - drizzle_set_byte3(ptr, con->packet_size); - ptr[3]= 0; - con->packet_number= 1; - ptr+= 4; - - ptr[0]= con->protocol_version; - ptr++; - - memcpy(ptr, con->server_version, strlen(con->server_version)); - ptr+= strlen(con->server_version); - - ptr[0]= 0; - ptr++; - - drizzle_set_byte4(ptr, con->thread_id); - ptr+= 4; - - if (con->scramble == NULL) - memset(ptr, 0, 8); - else - memcpy(ptr, con->scramble, 8); - ptr+= 8; - - ptr[0]= 0; - ptr++; - - if (con->options & DRIZZLE_CON_MYSQL) - con->capabilities|= DRIZZLE_CAPABILITIES_PROTOCOL_41; - - /* We can only send two bytes worth, this is a protocol limitation. */ - drizzle_set_byte2(ptr, con->capabilities); - ptr+= 2; - - ptr[0]= con->charset; - ptr++; - - drizzle_set_byte2(ptr, con->status); - ptr+= 2; - - memset(ptr, 0, 13); - ptr+= 13; - - if (con->scramble == NULL) - memset(ptr, 0, 12); - else - memcpy(ptr, con->scramble + 8, 12); - ptr+= 12; - - ptr[0]= 0; - ptr++; - - con->buffer_size+= (4 + con->packet_size); - - /* Make sure we packed it correctly. */ - if ((size_t)(ptr - con->buffer_ptr) != (4 + con->packet_size)) - { - drizzle_set_error(con->drizzle, "drizzle_state_handshake_server_write", - "error packing server handshake:%zu:%zu", - (size_t)(ptr - con->buffer_ptr), 4 + con->packet_size); - return DRIZZLE_RETURN_INTERNAL_ERROR; - } - - drizzle_state_pop(con); - return DRIZZLE_RETURN_OK; -} - -drizzle_return_t drizzle_state_handshake_client_read(drizzle_con_st *con) -{ - size_t real_size; - uint8_t *ptr; - uint8_t scramble_size; - - drizzle_log_debug(con->drizzle, "drizzle_state_handshake_client_read"); - - /* Assume the entire handshake packet will fit in the buffer. */ - if (con->buffer_size < con->packet_size) - { - drizzle_state_push(con, drizzle_state_read); - return DRIZZLE_RETURN_OK; - } - - /* This is the minimum packet size. */ - if (con->packet_size < 34) - { - drizzle_set_error(con->drizzle, "drizzle_state_handshake_client_read", - "bad packet size:>=34:%zu", con->packet_size); - return DRIZZLE_RETURN_BAD_HANDSHAKE_PACKET; - } - - real_size= 34; - - con->capabilities= drizzle_get_byte4(con->buffer_ptr); - con->buffer_ptr+= 4; - - if (con->options & DRIZZLE_CON_MYSQL && - !(con->capabilities & DRIZZLE_CAPABILITIES_PROTOCOL_41)) - { - drizzle_set_error(con->drizzle, "drizzle_state_handshake_client_read", - "protocol version not supported, must be MySQL 4.1+"); - return DRIZZLE_RETURN_PROTOCOL_NOT_SUPPORTED; - } - - con->max_packet_size= (uint32_t)drizzle_get_byte4(con->buffer_ptr); - con->buffer_ptr+= 4; - - con->charset= con->buffer_ptr[0]; - con->buffer_ptr+= 1; - - /* Skip unused. */ - con->buffer_ptr+= 23; - - /* Look for null-terminated user string. */ - ptr= (uint8_t *)memchr(con->buffer_ptr, 0, con->buffer_size - 32); - if (ptr == NULL) - { - drizzle_set_error(con->drizzle, "drizzle_state_handshake_client_read", - "user string not found"); - return DRIZZLE_RETURN_BAD_HANDSHAKE_PACKET; - } - - if (con->buffer_ptr == ptr) - { - con->user[0]= 0; - con->buffer_ptr++; - } - else - { - real_size+= (size_t)(ptr - con->buffer_ptr); - if (con->packet_size < real_size) - { - drizzle_set_error(con->drizzle, "drizzle_state_handshake_client_read", - "bad packet size:>=%zu:%zu", real_size, - con->packet_size); - return DRIZZLE_RETURN_BAD_HANDSHAKE_PACKET; - } - - strncpy(con->user, (char *)con->buffer_ptr, DRIZZLE_MAX_USER_SIZE); - con->user[DRIZZLE_MAX_USER_SIZE - 1]= 0; - con->buffer_ptr+= ((ptr - con->buffer_ptr) + 1); - } - - scramble_size= con->buffer_ptr[0]; - con->buffer_ptr+= 1; - - if (scramble_size == 0) - { - con->scramble= NULL; - } - else - { - if (scramble_size != DRIZZLE_MAX_SCRAMBLE_SIZE) - { - drizzle_set_error(con->drizzle, "drizzle_state_handshake_client_read", - "wrong scramble size"); - return DRIZZLE_RETURN_BAD_HANDSHAKE_PACKET; - } - - real_size+= scramble_size; - con->scramble= con->scramble_buffer; - memcpy(con->scramble, con->buffer_ptr, DRIZZLE_MAX_SCRAMBLE_SIZE); - - con->buffer_ptr+= DRIZZLE_MAX_SCRAMBLE_SIZE; - } - - /* Look for null-terminated schema string. */ - if ((34 + strlen(con->user) +scramble_size) == con->packet_size) - { - con->schema[0]= 0; - } - else - { - ptr= (uint8_t *)memchr(con->buffer_ptr, 0, con->buffer_size - - (34 + strlen(con->user) + scramble_size)); - if (ptr == NULL) - { - drizzle_set_error(con->drizzle, "drizzle_state_handshake_client_read", - "schema string not found"); - return DRIZZLE_RETURN_BAD_HANDSHAKE_PACKET; - } - - real_size+= ((size_t)(ptr - con->buffer_ptr) + 1); - if (con->packet_size != real_size) - { - drizzle_set_error(con->drizzle, "drizzle_state_handshake_client_read", - "bad packet size:%zu:%zu", real_size, con->packet_size); - return DRIZZLE_RETURN_BAD_HANDSHAKE_PACKET; - } - - if (con->buffer_ptr == ptr) - { - con->schema[0]= 0; - con->buffer_ptr++; - } - else - { - strncpy(con->schema, (char *)con->buffer_ptr, DRIZZLE_MAX_DB_SIZE); - con->schema[DRIZZLE_MAX_DB_SIZE - 1]= 0; - con->buffer_ptr+= ((ptr - con->buffer_ptr) + 1); - } - } - - con->buffer_size-= con->packet_size; - if (con->buffer_size != 0) - { - drizzle_set_error(con->drizzle, "drizzle_state_handshake_client_read", - "unexpected data after packet:%zu", con->buffer_size); - return DRIZZLE_RETURN_UNEXPECTED_DATA; - } - - con->buffer_ptr= con->buffer; - - drizzle_state_pop(con); - return DRIZZLE_RETURN_OK; -} - -drizzle_return_t drizzle_state_handshake_client_write(drizzle_con_st *con) -{ - uint8_t *ptr; - int capabilities; - - drizzle_log_debug(con->drizzle, "drizzle_state_handshake_client_write"); - - /* Calculate max packet size. */ - con->packet_size= 4 /* Capabilities */ - + 4 /* Max packet size */ - + 1 /* Charset */ - + 23 /* Unused */ - + strlen(con->user) + 1 - + 1 /* Scramble size */ - + DRIZZLE_MAX_SCRAMBLE_SIZE - + strlen(con->schema) + 1; - - /* Assume the entire handshake packet will fit in the buffer. */ - if ((con->packet_size + 4) > DRIZZLE_MAX_BUFFER_SIZE) - { - drizzle_set_error(con->drizzle, "drizzle_state_handshake_client_write", - "buffer too small:%zu", con->packet_size + 4); - return DRIZZLE_RETURN_INTERNAL_ERROR; - } - - ptr= con->buffer_ptr; - - /* Store packet size at the end since it may change. */ - ptr[3]= con->packet_number; - con->packet_number++; - ptr+= 4; - - if (con->options & DRIZZLE_CON_MYSQL) - { - con->capabilities|= DRIZZLE_CAPABILITIES_PROTOCOL_41; - } - - capabilities= con->capabilities & DRIZZLE_CAPABILITIES_CLIENT; - if (!(con->options & DRIZZLE_CON_FOUND_ROWS)) - capabilities&= ~DRIZZLE_CAPABILITIES_FOUND_ROWS; - - if (con->options & DRIZZLE_CON_INTERACTIVE) - { - capabilities|= DRIZZLE_CAPABILITIES_INTERACTIVE; - } - - if (con->options & DRIZZLE_CON_MULTI_STATEMENTS) - { - capabilities|= DRIZZLE_CAPABILITIES_MULTI_STATEMENTS; - } - - if (con->options & DRIZZLE_CON_AUTH_PLUGIN) - { - capabilities|= DRIZZLE_CAPABILITIES_PLUGIN_AUTH; - } - - capabilities&= ~(DRIZZLE_CAPABILITIES_COMPRESS | DRIZZLE_CAPABILITIES_SSL); - if (con->schema[0] == 0) - { - capabilities&= ~DRIZZLE_CAPABILITIES_CONNECT_WITH_DB; - } - - drizzle_set_byte4(ptr, capabilities); - ptr+= 4; - - drizzle_set_byte4(ptr, con->max_packet_size); - ptr+= 4; - - ptr[0]= con->charset; - ptr++; - - memset(ptr, 0, 23); - ptr+= 23; - - drizzle_return_t ret; - ptr= drizzle_pack_auth(con, ptr, &ret); - if (ret != DRIZZLE_RETURN_OK) - { - return ret; - } - - con->buffer_size+= (4 + con->packet_size); - - /* Make sure we packed it correctly. */ - if ((size_t)(ptr - con->buffer_ptr) != (4 + con->packet_size)) - { - drizzle_set_error(con->drizzle, "drizzle_state_handshake_client_write", - "error packing client handshake:%zu:%zu", - (size_t)(ptr - con->buffer_ptr), 4 + con->packet_size); - return DRIZZLE_RETURN_INTERNAL_ERROR; - } - - /* Store packet size now. */ - drizzle_set_byte3(con->buffer_ptr, con->packet_size); - - drizzle_state_pop(con); - return DRIZZLE_RETURN_OK; -} - -drizzle_return_t drizzle_state_handshake_result_read(drizzle_con_st *con) -{ - drizzle_result_st *result; - - drizzle_log_debug(con->drizzle, "drizzle_state_handshake_result_read"); - - if ((result= drizzle_result_create(con)) == NULL) - { - return DRIZZLE_RETURN_MEMORY; - } - - con->result= result; - - drizzle_return_t ret= drizzle_state_result_read(con); - if (drizzle_state_none(con)) - { - if (ret == DRIZZLE_RETURN_OK) - { - if (drizzle_result_eof(result)) - { - drizzle_set_error(con->drizzle, "drizzle_state_handshake_result_read", - "old insecure authentication mechanism not supported"); - ret= DRIZZLE_RETURN_AUTH_FAILED; - } - else - { - con->options|= DRIZZLE_CON_READY; - } - } - } - - drizzle_result_free(result); - - if (ret == DRIZZLE_RETURN_ERROR_CODE) - { - return DRIZZLE_RETURN_HANDSHAKE_FAILED; - } - - return ret; -} diff --git a/utils/mysqlcl_idb/libdrizzle-2.0/column.h b/utils/mysqlcl_idb/libdrizzle-2.0/column.h deleted file mode 100644 index 05aed97e7..000000000 --- a/utils/mysqlcl_idb/libdrizzle-2.0/column.h +++ /dev/null @@ -1,176 +0,0 @@ -/* - * Drizzle Client & Protocol Library - * - * Copyright (C) 2008 Eric Day (eday@oddments.org) - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * - * * The names of its contributors may not be used to endorse or - * promote products derived from this software without specific prior - * written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -#pragma once - -/** - * @file - * @brief Column Declarations - */ - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * @addtogroup drizzle_column Column Declarations - * @ingroup drizzle_client_interface - * @ingroup drizzle_server_interface - * - * These functions are used to get detailed column information. This information - * is usually sent as the first part of a result set. There are multiple ways - * for column information to be buffered depending on the functions being used. - * @{ - */ - -/** - * Initialize a column structure. - */ -DRIZZLE_API -drizzle_column_st *drizzle_column_create(drizzle_result_st *result, - drizzle_column_st *column); - -/** - * Free a column structure. - */ -DRIZZLE_API -void drizzle_column_free(drizzle_column_st *column); - -/** - * Get the drizzle_result_st struct that the column belongs to. - */ -DRIZZLE_API -drizzle_result_st *drizzle_column_drizzle_result(drizzle_column_st *column); - -/** - * Get catalog name for a column. - */ -DRIZZLE_API -const char *drizzle_column_catalog(drizzle_column_st *column); - -/** - * Get schema name for a column. - */ -DRIZZLE_API -const char *drizzle_column_shema(drizzle_column_st *column); - -DRIZZLE_API -const char *drizzle_column_db(drizzle_column_st *column); - -/** - * Get table name for a column. - */ -DRIZZLE_API -const char *drizzle_column_table(drizzle_column_st *column); - -/** - * Get original table name for a column. - */ -DRIZZLE_API -const char *drizzle_column_orig_table(drizzle_column_st *column); - -/** - * Get column name for a column. - */ -DRIZZLE_API -const char *drizzle_column_name(drizzle_column_st *column); - -/** - * Get original column name for a column. - */ -DRIZZLE_API -const char *drizzle_column_orig_name(drizzle_column_st *column); - -/** - * Get charset for a column. - */ -DRIZZLE_API -drizzle_charset_t drizzle_column_charset(drizzle_column_st *column); - -/** - * Get size of a column. - */ -DRIZZLE_API -uint32_t drizzle_column_size(drizzle_column_st *column); - -/** - * Get max size of a column. - */ -DRIZZLE_API -size_t drizzle_column_max_size(drizzle_column_st *column); - -/** - * Set max size of a column. - */ -DRIZZLE_API -void drizzle_column_set_max_size(drizzle_column_st *column, size_t size); - -/** - * Get the type of a column. - */ -DRIZZLE_API -drizzle_column_type_t drizzle_column_type(drizzle_column_st *column); - -/** - * Get the Drizzle type of a column. - */ -DRIZZLE_API -drizzle_column_type_drizzle_t drizzle_column_type_drizzle(drizzle_column_st *column); - -/** - * Get flags for a column. - */ -DRIZZLE_API -int drizzle_column_flags(drizzle_column_st *column); - -/** - * Get the number of decimals for numeric columns. - */ -DRIZZLE_API -uint8_t drizzle_column_decimals(drizzle_column_st *column); - -/** - * Get default value for a column. - */ -DRIZZLE_API -const uint8_t *drizzle_column_default_value(drizzle_column_st *column, - size_t *size); - -/** @} */ - -#ifdef __cplusplus -} -#endif diff --git a/utils/mysqlcl_idb/libdrizzle-2.0/column_client.h b/utils/mysqlcl_idb/libdrizzle-2.0/column_client.h deleted file mode 100644 index ec7b0cfd4..000000000 --- a/utils/mysqlcl_idb/libdrizzle-2.0/column_client.h +++ /dev/null @@ -1,125 +0,0 @@ -/* - * Drizzle Client & Protocol Library - * - * Copyright (C) 2008 Eric Day (eday@oddments.org) - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * - * * The names of its contributors may not be used to endorse or - * promote products derived from this software without specific prior - * written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - - -/** - * @file - * @brief Column Declarations for Clients - */ - -#pragma once - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * @addtogroup drizzle_column_client Column Declarations for Clients - * @ingroup drizzle_client_interface - * - * These functions are used to get detailed column information. This information - * is usually sent as the first part of a result set. There are both buffered - * and unbuffered functions provided. - * @{ - */ - -/** - * Skip a column in result. - */ -DRIZZLE_API -drizzle_return_t drizzle_column_skip(drizzle_result_st *result); - -/** - * Skip all columns in a result. - */ -DRIZZLE_API -drizzle_return_t drizzle_column_skip_all(drizzle_result_st *result); - -/** - * Read column information. - * - * @param[in,out] result pointer to the structure to read from. - * @param[out] column pointer to the structure to contain the information. - * @param[out] ret_ptr Standard libdrizzle return value. - * @return column if there is valid data, NULL if there are no more columns. - */ -DRIZZLE_API -drizzle_column_st *drizzle_column_read(drizzle_result_st *result, - drizzle_column_st *column, - drizzle_return_t *ret_ptr); - -/** - * Buffer all columns in result structure. - */ -DRIZZLE_API -drizzle_return_t drizzle_column_buffer(drizzle_result_st *result); - -/** - * Get next buffered column from a result structure. - */ -DRIZZLE_API -drizzle_column_st *drizzle_column_next(drizzle_result_st *result); - -/** - * Get previous buffered column from a result structure. - */ -DRIZZLE_API -drizzle_column_st *drizzle_column_prev(drizzle_result_st *result); - -/** - * Seek to the given buffered column in a result structure. - */ -DRIZZLE_API -void drizzle_column_seek(drizzle_result_st *result, uint16_t column); - -/** - * Get the given buffered column from a result structure. - */ -DRIZZLE_API -drizzle_column_st *drizzle_column_index(drizzle_result_st *result, - uint16_t column); - -/** - * Get current column number in a buffered or unbuffered result. - */ -DRIZZLE_API -uint16_t drizzle_column_current(drizzle_result_st *result); - -/** @} */ - -#ifdef __cplusplus -} -#endif diff --git a/utils/mysqlcl_idb/libdrizzle-2.0/column_server.h b/utils/mysqlcl_idb/libdrizzle-2.0/column_server.h deleted file mode 100644 index 264de40d1..000000000 --- a/utils/mysqlcl_idb/libdrizzle-2.0/column_server.h +++ /dev/null @@ -1,149 +0,0 @@ -/* - * Drizzle Client & Protocol Library - * - * Copyright (C) 2008 Eric Day (eday@oddments.org) - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * - * * The names of its contributors may not be used to endorse or - * promote products derived from this software without specific prior - * written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -#pragma once - -/** - * @file - * @brief Column Declarations for Servers - */ - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * @addtogroup drizzle_column_server Column Declarations for Servers - * @ingroup drizzle_server_interface - * - * These functions allow you to send column information over a connection. - * @{ - */ - -/** - * Write column information. - */ -DRIZZLE_API -drizzle_return_t drizzle_column_write(drizzle_result_st *result, - drizzle_column_st *column); - -/** - * Set catalog name for a column. - */ -DRIZZLE_API -void drizzle_column_set_catalog(drizzle_column_st *column, const char *catalog); - -/** - * Set database name for a column. - */ -DRIZZLE_API -void drizzle_column_set_db(drizzle_column_st *column, const char *db); - -DRIZZLE_API -void drizzle_column_set_schema(drizzle_column_st *column, const char *schema); - -/** - * Set table name for a column. - */ -DRIZZLE_API -void drizzle_column_set_table(drizzle_column_st *column, const char *table); - -/** - * Set original table name for a column. - */ -DRIZZLE_API -void drizzle_column_set_orig_table(drizzle_column_st *column, - const char *orig_table); - -/** - * Set column name for a column. - */ -DRIZZLE_API -void drizzle_column_set_name(drizzle_column_st *column, const char *name); - -/** - * Set original column name for a column. - */ -DRIZZLE_API -void drizzle_column_set_orig_name(drizzle_column_st *column, - const char *orig_name); - -/** - * Set charset for a column. - */ -DRIZZLE_API -void drizzle_column_set_charset(drizzle_column_st *column, - drizzle_charset_t charset); - -/** - * Set size of a column. - */ -DRIZZLE_API -void drizzle_column_set_size(drizzle_column_st *column, uint32_t size); - -/** - * Set the type of a column. - */ -DRIZZLE_API -void drizzle_column_set_type(drizzle_column_st *column, - drizzle_column_type_t type); - -/** - * Set flags for a column. - */ -DRIZZLE_API -void drizzle_column_set_flags(drizzle_column_st *column, - int flags); - -/** - * Set the number of decimals for numeric columns. - */ -DRIZZLE_API -void drizzle_column_set_decimals(drizzle_column_st *column, uint8_t decimals); - -/** - * Set default value for a column. - */ -DRIZZLE_API -void drizzle_column_set_default_value(drizzle_column_st *column, - const uint8_t *default_value, - size_t size); - -/** @} */ - -#ifdef __cplusplus -} -#endif diff --git a/utils/mysqlcl_idb/libdrizzle-2.0/command.h b/utils/mysqlcl_idb/libdrizzle-2.0/command.h deleted file mode 100644 index f4feed2eb..000000000 --- a/utils/mysqlcl_idb/libdrizzle-2.0/command.h +++ /dev/null @@ -1,102 +0,0 @@ -/* - * Drizzle Client & Protocol Library - * - * Copyright (C) 2011 Brian Aker (brian@tangent.org) - * Copyright (C) 2008 Eric Day (eday@oddments.org) - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * - * * The names of its contributors may not be used to endorse or - * promote products derived from this software without specific prior - * written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - - -/** - * @ingroup drizzle_command - * Commands for drizzle_command functions. - */ -enum drizzle_command_t -{ - DRIZZLE_COMMAND_SLEEP, /* Not used currently. */ - DRIZZLE_COMMAND_QUIT, - DRIZZLE_COMMAND_INIT_DB, - DRIZZLE_COMMAND_QUERY, - DRIZZLE_COMMAND_FIELD_LIST, /* Deprecated. */ - DRIZZLE_COMMAND_CREATE_DB, /* Deprecated. */ - DRIZZLE_COMMAND_DROP_DB, /* Deprecated. */ - DRIZZLE_COMMAND_REFRESH, - DRIZZLE_COMMAND_SHUTDOWN, - DRIZZLE_COMMAND_STATISTICS, - DRIZZLE_COMMAND_PROCESS_INFO, /* Deprecated. */ - DRIZZLE_COMMAND_CONNECT, /* Not used currently. */ - DRIZZLE_COMMAND_PROCESS_KILL, /* Deprecated. */ - DRIZZLE_COMMAND_DEBUG, - DRIZZLE_COMMAND_PING, - DRIZZLE_COMMAND_TIME, /* Not used currently. */ - DRIZZLE_COMMAND_DELAYED_INSERT, /* Not used currently. */ - DRIZZLE_COMMAND_CHANGE_USER, - DRIZZLE_COMMAND_BINLOG_DUMP, /* Not used currently. */ - DRIZZLE_COMMAND_TABLE_DUMP, /* Not used currently. */ - DRIZZLE_COMMAND_CONNECT_OUT, /* Not used currently. */ - DRIZZLE_COMMAND_REGISTER_SLAVE, /* Not used currently. */ - DRIZZLE_COMMAND_STMT_PREPARE, /* Not used currently. */ - DRIZZLE_COMMAND_STMT_EXECUTE, /* Not used currently. */ - DRIZZLE_COMMAND_STMT_SEND_LONG_DATA, /* Not used currently. */ - DRIZZLE_COMMAND_STMT_CLOSE, /* Not used currently. */ - DRIZZLE_COMMAND_STMT_RESET, /* Not used currently. */ - DRIZZLE_COMMAND_SET_OPTION, /* Not used currently. */ - DRIZZLE_COMMAND_STMT_FETCH, /* Not used currently. */ - DRIZZLE_COMMAND_DAEMON, /* Not used currently. */ - DRIZZLE_COMMAND_END /* Not used currently. */ -}; - -#ifndef __cplusplus -typedef enum drizzle_command_t drizzle_command_t; -#endif - -/** - * @ingroup drizzle_command - * Commands for the Drizzle protocol functions. - */ -enum drizzle_command_drizzle_t -{ - DRIZZLE_COMMAND_DRIZZLE_SLEEP, - DRIZZLE_COMMAND_DRIZZLE_QUIT, - DRIZZLE_COMMAND_DRIZZLE_INIT_DB, - DRIZZLE_COMMAND_DRIZZLE_QUERY, - DRIZZLE_COMMAND_DRIZZLE_SHUTDOWN, - DRIZZLE_COMMAND_DRIZZLE_CONNECT, - DRIZZLE_COMMAND_DRIZZLE_PING, - DRIZZLE_COMMAND_DRIZZLE_KILL, - DRIZZLE_COMMAND_DRIZZLE_END -}; - -#ifndef __cplusplus -typedef enum drizzle_command_drizzle_t drizzle_command_drizzle_t; -#endif - diff --git a/utils/mysqlcl_idb/libdrizzle-2.0/command_client.h b/utils/mysqlcl_idb/libdrizzle-2.0/command_client.h deleted file mode 100644 index fe02dbb68..000000000 --- a/utils/mysqlcl_idb/libdrizzle-2.0/command_client.h +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Drizzle Client & Protocol Library - * - * Copyright (C) 2008 Eric Day (eday@oddments.org) - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * - * * The names of its contributors may not be used to endorse or - * promote products derived from this software without specific prior - * written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -#pragma once - -/** - * @file - * @brief Command Declarations for Clients - */ - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * @addtogroup drizzle_command_client Command Declarations for Clients - * @ingroup drizzle_client_interface - * - * These functions are used to issue commands on a connection. Normal SQL - * queries are issued using the drizzle_query* functions defined in query.h. - * @{ - */ - -/** @} */ - -#ifdef __cplusplus -} -#endif diff --git a/utils/mysqlcl_idb/libdrizzle-2.0/command_server.h b/utils/mysqlcl_idb/libdrizzle-2.0/command_server.h deleted file mode 100644 index df6b5cf5c..000000000 --- a/utils/mysqlcl_idb/libdrizzle-2.0/command_server.h +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Drizzle Client & Protocol Library - * - * Copyright (C) 2008 Eric Day (eday@oddments.org) - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * - * * The names of its contributors may not be used to endorse or - * promote products derived from this software without specific prior - * written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -#pragma once - -/** - * @file - * @brief Command Declarations for Servers - */ - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * @addtogroup drizzle_command_server Command Declarations for Servers - * @ingroup drizzle_server_interface - * - * These functions allow you to read comands on a connection. - * @{ - */ - -/** @} */ - -#ifdef __cplusplus -} -#endif diff --git a/utils/mysqlcl_idb/libdrizzle-2.0/common.h b/utils/mysqlcl_idb/libdrizzle-2.0/common.h deleted file mode 100644 index ac97c197e..000000000 --- a/utils/mysqlcl_idb/libdrizzle-2.0/common.h +++ /dev/null @@ -1,94 +0,0 @@ -/* - * Drizzle Client & Protocol Library - * - * Copyright (C) 2008 Eric Day (eday@oddments.org) - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * - * * The names of its contributors may not be used to endorse or - * promote products derived from this software without specific prior - * written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -/** - * @file - * @brief System Include Files - */ - -#pragma once - -#include - -#include -#include - -#include -#include -#include -#ifndef _WIN32 -# include -# include -# include -#endif -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include - -#ifdef _MSC_VER -#define random() rand() -#define srandom(a) srand(a) -#define get_socket_errno() WSAGetLastError() -#else -#define INVALID_SOCKET -1 -#define SOCKET_ERROR -1 -#define closesocket(a) close(a) -#define get_socket_errno() errno -#endif - -#ifndef PACKAGE_BUGREPORT -#define PACKAGE_BUGREPORT "drizzle@drizzle.org" -#endif - -#ifndef PACKAGE_VERSION -#define PACKAGE_VERSION "2.0" -#endif - -#ifdef __cplusplus -# include -# ifndef UINT32_MAX -const unsigned int UINT32_MAX=std::numeric_limits::max(); -# endif -#endif - diff --git a/utils/mysqlcl_idb/libdrizzle-2.0/conn.h b/utils/mysqlcl_idb/libdrizzle-2.0/conn.h deleted file mode 100644 index 3d4f0fa0b..000000000 --- a/utils/mysqlcl_idb/libdrizzle-2.0/conn.h +++ /dev/null @@ -1,436 +0,0 @@ -/* - * Drizzle Client & Protocol Library - * - * Copyright (C) 2008 Eric Day (eday@oddments.org) - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * - * * The names of its contributors may not be used to endorse or - * promote products derived from this software without specific prior - * written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -#pragma once - -/** - * @file - * @brief Connection Declarations - */ - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * @addtogroup drizzle_con Connection Declarations - * @ingroup drizzle_client_interface - * @ingroup drizzle_server_interface - * @{ - */ - -/** - * Get file descriptor for connection. - * - * @param[in] con Connection structure previously initialized with - * drizzle_con_create(), drizzle_con_clone(), or related functions. - * @return File descriptor of connection, or -1 if not active. - */ -DRIZZLE_API -int drizzle_con_fd(const drizzle_con_st *con); - -/** - * Use given file descriptor for connction. - * - * @param[in] con Connection structure previously initialized with - * drizzle_con_create(), drizzle_con_clone(), or related functions. - * @param[in] fd File descriptor for connection. - * @return Standard drizzle return value. - */ -DRIZZLE_API -drizzle_return_t drizzle_con_set_fd(drizzle_con_st *con, int fd); - -/** - * Close a connection. - * - * @param[in] con Connection structure previously initialized with - * drizzle_con_create(), drizzle_con_clone(), or related functions. - */ -DRIZZLE_API -void drizzle_con_close(drizzle_con_st *con); - -/** - * Set events to be watched for a connection. - * - * @param[in] con Connection structure previously initialized with - * drizzle_con_create(), drizzle_con_clone(), or related functions. - * @param[in] events Bitfield of poll() events to watch. - * @return Standard drizzle return value. - */ -DRIZZLE_API -drizzle_return_t drizzle_con_set_events(drizzle_con_st *con, short events); - -/** - * Set events that are ready for a connection. This is used with the external - * event callbacks. See drizzle_set_event_watch_fn(). - * - * @param[in] con Connection structure previously initialized with - * drizzle_con_create(), drizzle_con_clone(), or related functions. - * @param[in] revents Bitfield of poll() events that were detected. - * @return Standard drizzle return value. - */ -DRIZZLE_API -drizzle_return_t drizzle_con_set_revents(drizzle_con_st *con, short revents); - -/** - * Get the drizzle_st struct that the connection belongs to. - * - * @param[in] con Connection structure previously initialized with - * drizzle_con_create(), drizzle_con_clone(), or related functions. - * @return Drizzle object that this connection is part of. - */ -DRIZZLE_API -drizzle_st *drizzle_con_drizzle(const drizzle_con_st *con); - -/** - * Return an error string for last error encountered. - * - * @param[in] con Connection structure previously initialized with - * drizzle_con_create(), drizzle_con_clone(), or related functions. - * @return Pointer to static buffer in library that holds an error string. - */ -DRIZZLE_API -const char *drizzle_con_error(const drizzle_con_st *con); - -/** - * Value of errno in the case of a DRIZZLE_RETURN_ERRNO return value. - * - * @param[in] con Connection structure previously initialized with - * drizzle_con_create(), drizzle_con_clone(), or related functions. - * @return An errno value as defined in your system errno.h file. - */ -DRIZZLE_API -int drizzle_con_errno(const drizzle_con_st *con); - -/** - * Get server defined error code for the last result read. - * - * @param[in] con Connection structure previously initialized with - * drizzle_con_create(), drizzle_con_clone(), or related functions. - * @return An error code given back in the server response. - */ -DRIZZLE_API -uint16_t drizzle_con_error_code(const drizzle_con_st *con); - -/** - * Get SQL state code for the last result read. - * - * @param[in] con Connection structure previously initialized with - * drizzle_con_create(), drizzle_con_clone(), or related functions. - * @return A SQLSTATE code given back in the server response. - */ -DRIZZLE_API -const char *drizzle_con_sqlstate(const drizzle_con_st *con); - -/** - * Get options for a connection. - * - * @param[in] con Connection structure previously initialized with - * drizzle_con_create(), drizzle_con_clone(), or related functions. - * @return Options set for the connection structure. - */ -DRIZZLE_API -int drizzle_con_options(const drizzle_con_st *con); - -/** - * Set options for a connection. - * - * @param[in] con Connection structure previously initialized with - * drizzle_con_create(), drizzle_con_clone(), or related functions. - * @param[in] options Available options for connection structure to set. - */ -DRIZZLE_API -void drizzle_con_set_options(drizzle_con_st *con, - int options); - -/** - * Add options for a connection. - * - * @param[in] con Connection structure previously initialized with - * drizzle_con_create(), drizzle_con_clone(), or related functions. - * @param[in] options Available options for connection structure to set. - */ -DRIZZLE_API -void drizzle_con_add_options(drizzle_con_st *con, - int options); - -/** - * Remove options for a connection. - * - * @param[in] con Connection structure previously initialized with - * drizzle_con_create(), drizzle_con_clone(), or related functions. - * @param[in] options Available options for connection structure to remove. - */ -DRIZZLE_API -void drizzle_con_remove_options(drizzle_con_st *con, - int options); - -/** - * Get TCP host for a connection. - * - * @param[in] con Connection structure previously initialized with - * drizzle_con_create(), drizzle_con_clone(), or related functions. - * @return Host this connection is configured for, or NULL if not set. - */ -DRIZZLE_API -const char *drizzle_con_host(const drizzle_con_st *con); - -/** - * Get TCP port for a connection. - * - * @param[in] con Connection structure previously initialized with - * drizzle_con_create(), drizzle_con_clone(), or related functions. - * @return Port this connection is configured for, 0 if not set. - */ -DRIZZLE_API -in_port_t drizzle_con_port(const drizzle_con_st *con); - -/** - * Set TCP host and port for a connection. - * - * @param[in] con Connection structure previously initialized with - * drizzle_con_create(), drizzle_con_clone(), or related functions. - * @param[in] host Host to use for this connection, NULL for default value. - * @param[in] port Port to use for this connection, 0 for default value. - */ -DRIZZLE_API -void drizzle_con_set_tcp(drizzle_con_st *con, const char *host, in_port_t port); - -/** - * Get unix domain socket for a connection. - * - * @param[in] con Connection structure previously initialized with - * drizzle_con_create(), drizzle_con_clone(), or related functions. - * @return Unix domain socket set for this connection, NULL if not set. - */ -DRIZZLE_API -const char *drizzle_con_uds(const drizzle_con_st *con); - -/** - * Set unix domain socket for a connection. - * - * @param[in] con Connection structure previously initialized with - * drizzle_con_create(), drizzle_con_clone(), or related functions. - * @param[in] uds Unix domain socket to use for this connection, NULL for - * defailt value. - */ -DRIZZLE_API -void drizzle_con_set_uds(drizzle_con_st *con, const char *uds); - -/** - * Get username for a connection. - * - * @param[in] con Connection structure previously initialized with - * drizzle_con_create(), drizzle_con_clone(), or related functions. - * @return User associated with this connection. - */ -DRIZZLE_API -const char *drizzle_con_user(const drizzle_con_st *con); - -/** - * Get password for a connection. - * - * @param[in] con Connection structure previously initialized with - * drizzle_con_create(), drizzle_con_clone(), or related functions. - * @return Password associated with this connection. - */ -DRIZZLE_API -const char *drizzle_con_password(const drizzle_con_st *con); - -/** - * Set username and password for a connection. - * - * @param[in] con Connection structure previously initialized with - * drizzle_con_create(), drizzle_con_clone(), or related functions. - * @param[in] user Username to use for this connection. - * @param[in] password Password to use for this connection. - */ -DRIZZLE_API -void drizzle_con_set_auth(drizzle_con_st *con, const char *user, - const char *password); - -/** - * Get database for a connection. - * - * @param[in] con Connection structure previously initialized with - * drizzle_con_create(), drizzle_con_clone(), or related functions. - * @return Database associated with this connection. - */ -DRIZZLE_API -const char *drizzle_con_schema(const drizzle_con_st *con); - -DRIZZLE_API -const char *drizzle_con_db(const drizzle_con_st *con); - -/** - * Set database for a connection. - * - * @param[in] con Connection structure previously initialized with - * drizzle_con_create(), drizzle_con_clone(), or related functions. - * @param[in] schema Database to use with this connection. - */ -DRIZZLE_API -void drizzle_con_set_schema(drizzle_con_st *con, const char *schema); - -DRIZZLE_API -void drizzle_con_set_db(drizzle_con_st *con, const char *schema); - -/** - * Get application context pointer for a connection. - * - * @param[in] con Connection structure previously initialized with - * drizzle_con_create(), drizzle_con_clone(), or related functions. - * @return Application context with this connection. - */ -DRIZZLE_API -void *drizzle_con_context(const drizzle_con_st *con); - -/** - * Set application context pointer for a connection. - * - * @param[in] con Connection structure previously initialized with - * drizzle_con_create(), drizzle_con_clone(), or related functions. - * @param[in] context Application context to use with this connection. - */ -DRIZZLE_API -void drizzle_con_set_context(drizzle_con_st *con, void *context); - -/** - * Set callback function when the context pointer should be freed. - * - * @param[in] con Connection structure previously initialized with - * drizzle_con_create(), drizzle_con_clone(), or related functions. - * @param[in] function Function to call to clean up connection context. - */ -DRIZZLE_API -void drizzle_con_set_context_free_fn(drizzle_con_st *con, - drizzle_con_context_free_fn *function); - -/** - * Get protocol version for a connection. - * - * @param[in] con Connection structure previously initialized with - * drizzle_con_create(), drizzle_con_clone(), or related functions. - * @return Protocol version for connection. - */ -DRIZZLE_API -uint8_t drizzle_con_protocol_version(const drizzle_con_st *con); - -/** - * Get server version string for a connection. - * - * @param[in] con Connection structure previously initialized with - * drizzle_con_create(), drizzle_con_clone(), or related functions. - * @return Server version string for connection. - */ -DRIZZLE_API -const char *drizzle_con_server_version(const drizzle_con_st *con); - -/** - * Get server version number for a connection. - * - * @param[in] con Connection structure previously initialized with - * drizzle_con_create(), drizzle_con_clone(), or related functions. - * @return Server version number for connection. - */ -DRIZZLE_API -uint32_t drizzle_con_server_version_number(const drizzle_con_st *con); - -/** - * Get thread ID for a connection. - * - * @param[in] con Connection structure previously initialized with - * drizzle_con_create(), drizzle_con_clone(), or related functions. - * @return Thread ID for connection. - */ -DRIZZLE_API -uint32_t drizzle_con_thread_id(const drizzle_con_st *con); - -/** - * Get scramble buffer for a connection. - * - * @param[in] con Connection structure previously initialized with - * drizzle_con_create(), drizzle_con_clone(), or related functions. - * @return Scramble buffer for connection. - */ -DRIZZLE_API -const uint8_t *drizzle_con_scramble(const drizzle_con_st *con); - -/** - * Get capabilities for a connection. - * - * @param[in] con Connection structure previously initialized with - * drizzle_con_create(), drizzle_con_clone(), or related functions. - * @return Capabilities for connection. - */ -DRIZZLE_API -int drizzle_con_capabilities(const drizzle_con_st *con); - -/** - * Get character set for a connection. - * - * @param[in] con Connection structure previously initialized with - * drizzle_con_create(), drizzle_con_clone(), or related functions. - * @return Character set for connection. - */ -DRIZZLE_API -drizzle_charset_t drizzle_con_charset(const drizzle_con_st *con); - -/** - * Get status for a connection. - * - * @param[in] con Connection structure previously initialized with - * drizzle_con_create(), drizzle_con_clone(), or related functions. - * @return Status for connection. - */ -DRIZZLE_API -drizzle_con_status_t drizzle_con_status(const drizzle_con_st *con); - -/** - * Get max packet size for a connection. - * - * @param[in] con Connection structure previously initialized with - * drizzle_con_create(), drizzle_con_clone(), or related functions. - * @return Max packet size for connection. - */ -DRIZZLE_API -uint32_t drizzle_con_max_packet_size(const drizzle_con_st *con); - -/** @} */ - -#ifdef __cplusplus -} -#endif diff --git a/utils/mysqlcl_idb/libdrizzle-2.0/conn_client.h b/utils/mysqlcl_idb/libdrizzle-2.0/conn_client.h deleted file mode 100644 index ef9a435e4..000000000 --- a/utils/mysqlcl_idb/libdrizzle-2.0/conn_client.h +++ /dev/null @@ -1,192 +0,0 @@ -/* - * Drizzle Client & Protocol Library - * - * Copyright (C) 2008 Eric Day (eday@oddments.org) - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * - * * The names of its contributors may not be used to endorse or - * promote products derived from this software without specific prior - * written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -#pragma once - -/** - * @file - * @brief Connection Declarations for Clients - */ - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * @addtogroup drizzle_con_client Connection Declarations for Clients - * @ingroup drizzle_client_interface - * @{ - */ - -/** - * Connect to server. - * - * @param[in] con Connection structure previously initialized with - * drizzle_con_create(), drizzle_con_clone(), or related functions. - * @return Standard drizzle return value. - */ -DRIZZLE_API -drizzle_return_t drizzle_con_connect(drizzle_con_st *con); - -/** - * Send quit command to server for a connection. - * - * @param[in] con Connection structure previously initialized with - * drizzle_con_create(), drizzle_con_clone(), or related functions. - * @param[in] result Caller allocated structure, or NULL to allocate one. - * @param[out] ret_ptr Standard drizzle return value. - * @return On success, a pointer to the (possibly allocated) structure. On - * failure this will be NULL. - */ -DRIZZLE_API -drizzle_result_st *drizzle_con_quit(drizzle_con_st *con, - drizzle_result_st *result, - drizzle_return_t *ret_ptr); - -/** - * @todo Remove this with next major API change. - */ -DRIZZLE_API -drizzle_result_st *drizzle_quit(drizzle_con_st *con, - drizzle_result_st *result, - drizzle_return_t *ret_ptr); - -/** - * Select a new default database for a connection. - * - * @param[in] con Connection structure previously initialized with - * drizzle_con_create(), drizzle_con_clone(), or related functions. - * @param[in] result Caller allocated structure, or NULL to allocate one. - * @param[in] db Default database to select. - * @param[out] ret_ptr Standard drizzle return value. - * @return On success, a pointer to the (possibly allocated) structure. On - * failure this will be NULL. - */ -DRIZZLE_API -drizzle_result_st *drizzle_con_select_db(drizzle_con_st *con, - drizzle_result_st *result, - const char *db, - drizzle_return_t *ret_ptr); - -/** - * @todo Remove this with next major API change. - */ -DRIZZLE_API -drizzle_result_st *drizzle_select_db(drizzle_con_st *con, - drizzle_result_st *result, - const char *db, - drizzle_return_t *ret_ptr); - -/** - * Send a shutdown message to the server. - * - * @param[in] con Connection structure previously initialized with - * drizzle_con_create(), drizzle_con_clone(), or related functions. - * @param[in] result Caller allocated structure, or NULL to allocate one. - * @param[out] ret_ptr Standard drizzle return value. - * @return On success, a pointer to the (possibly allocated) structure. On - * failure this will be NULL. - */ -DRIZZLE_API -drizzle_result_st *drizzle_con_shutdown(drizzle_con_st *con, - drizzle_result_st *result, - drizzle_return_t *ret_ptr); - -DRIZZLE_API -drizzle_result_st *drizzle_kill(drizzle_con_st *con, - drizzle_result_st *result, - uint32_t query_id, - drizzle_return_t *ret_ptr); - -/** - * @todo Remove this with next major API change. - */ -#define DRIZZLE_SHUTDOWN_DEFAULT 0 -DRIZZLE_API -drizzle_result_st *drizzle_shutdown(drizzle_con_st *con, - drizzle_result_st *result, uint32_t level, - drizzle_return_t *ret_ptr); - -/** - * Send a ping request to the server. - * - * @param[in] con Connection structure previously initialized with - * drizzle_con_create(), drizzle_con_clone(), or related functions. - * @param[in] result Caller allocated structure, or NULL to allocate one. - * @param[out] ret_ptr Standard drizzle return value. - * @return On success, a pointer to the (possibly allocated) structure. On - * failure this will be NULL. - */ -DRIZZLE_API -drizzle_result_st *drizzle_con_ping(drizzle_con_st *con, - drizzle_result_st *result, - drizzle_return_t *ret_ptr); - -/** - * @todo Remove this with next major API change. - */ -DRIZZLE_API -drizzle_result_st *drizzle_ping(drizzle_con_st *con, - drizzle_result_st *result, - drizzle_return_t *ret_ptr); - -/** - * Send raw command to server, possibly in parts. - * - * @param[in] con Connection structure previously initialized with - * drizzle_con_create(), drizzle_con_clone(), or related functions. - * @param[in] result Caller allocated structure, or NULL to allocate one. - * @param[in] command Command to run on server. - * @param[in] data Data to send along with the command. - * @param[in] size Size of the current chunk of data being sent. - * @param[in] total Total size of all data being sent for command. - * @param[out] ret_ptr Standard drizzle return value. - * @return On success, a pointer to the (possibly allocated) structure. On - * failure this will be NULL. - */ -DRIZZLE_API -drizzle_result_st *drizzle_con_command_write(drizzle_con_st *con, - drizzle_result_st *result, - drizzle_command_t command, - const void *data, size_t size, - size_t total, - drizzle_return_t *ret_ptr); - -/** @} */ - -#ifdef __cplusplus -} -#endif diff --git a/utils/mysqlcl_idb/libdrizzle-2.0/conn_local.h b/utils/mysqlcl_idb/libdrizzle-2.0/conn_local.h deleted file mode 100644 index c152ee075..000000000 --- a/utils/mysqlcl_idb/libdrizzle-2.0/conn_local.h +++ /dev/null @@ -1,118 +0,0 @@ -/* - * Drizzle Client & Protocol Library - * - * Copyright (C) 2008 Eric Day (eday@oddments.org) - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * - * * The names of its contributors may not be used to endorse or - * promote products derived from this software without specific prior - * written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -#pragma once - -/** - * @file - * @brief Local Connection Declarations - */ - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * @addtogroup drizzle_con_local Local Connection Declarations - * @ingroup drizzle_con - * @{ - */ - -/** - * Clear address info, freeing structs if needed. - * - * @param[in] con Connection structure previously initialized with - * drizzle_con_create(), drizzle_con_clone(), or related functions. - */ -DRIZZLE_LOCAL -void drizzle_con_reset_addrinfo(drizzle_con_st *con); - -/** - * Check if state stack is empty. - * - * @param[in] con Connection structure previously initialized with - * drizzle_con_create(), drizzle_con_clone(), or related functions. - * @return True if empty, false if something is on the stack. - */ -static inline bool drizzle_state_none(drizzle_con_st *con) -{ - return con->state_current == 0; -} - -/** - * Push a function onto the stack. - * - * @param[in] con Connection structure previously initialized with - * drizzle_con_create(), drizzle_con_clone(), or related functions. - * @param[in] function Function to push. - */ -static inline void drizzle_state_push(drizzle_con_st *con, - drizzle_state_fn *function) -{ - /* The maximum stack depth can be determined at compile time, so bump this - constant if needed to avoid the dynamic memory management. */ - assert(con->state_current < DRIZZLE_STATE_STACK_SIZE); - con->state_stack[con->state_current]= function; - con->state_current++; -} - -/** - * Pop a function off of the stack. - * - * @param[in] con Connection structure previously initialized with - * drizzle_con_create(), drizzle_con_clone(), or related functions. - */ -static inline void drizzle_state_pop(drizzle_con_st *con) -{ - con->state_current--; -} - -/** - * Reset the stack so it is empty. - * - * @param[in] con Connection structure previously initialized with - * drizzle_con_create(), drizzle_con_clone(), or related functions. - */ -static inline void drizzle_state_reset(drizzle_con_st *con) -{ - con->state_current= 0; -} - -/** @} */ - -#ifdef __cplusplus -} -#endif diff --git a/utils/mysqlcl_idb/libdrizzle-2.0/conn_server.h b/utils/mysqlcl_idb/libdrizzle-2.0/conn_server.h deleted file mode 100644 index f990a9b37..000000000 --- a/utils/mysqlcl_idb/libdrizzle-2.0/conn_server.h +++ /dev/null @@ -1,224 +0,0 @@ -/* - * Drizzle Client & Protocol Library - * - * Copyright (C) 2008 Eric Day (eday@oddments.org) - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * - * * The names of its contributors may not be used to endorse or - * promote products derived from this software without specific prior - * written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -#pragma once - -/** - * @file - * @brief Connection Declarations for Servers - */ - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * @addtogroup drizzle_con_server Connection Declarations for Servers - * @ingroup drizzle_server_interface - * - * These functions extend the core connection functions with a set of functions - * for server application use. These functions allow you to set raw handshake - * information for use with the handshake write functions. - * @{ - */ - -/** - * Put a connection into listening mode. - * - * @param[in] con Connection structure previously initialized with - * drizzle_con_create(), drizzle_con_clone(), or related functions. - * @return Standard drizzle return value. - */ -DRIZZLE_API -drizzle_return_t drizzle_con_listen(drizzle_con_st *con); - -/** - * Get connection backlog queue length. - * - * @param[in] con Connection structure previously initialized with - * drizzle_con_create(), drizzle_con_clone(), or related functions. - * @return Backlog for connection - */ -DRIZZLE_API -int drizzle_con_backlog(const drizzle_con_st *con); - -/** - * Set connection backlog queue length. - * - * @param[in] con Connection structure previously initialized with - * drizzle_con_create(), drizzle_con_clone(), or related functions. - * @param[in] backlog Backlog to use for connection - */ -DRIZZLE_API -void drizzle_con_set_backlog(drizzle_con_st *con, int backlog); - -/** - * Set protocol version for a connection. - * - * @param[in] con Connection structure previously initialized with - * drizzle_con_create(), drizzle_con_clone(), or related functions. - * @param[in] protocol_version Protocol version to use for connection - */ -DRIZZLE_API -void drizzle_con_set_protocol_version(drizzle_con_st *con, - uint8_t protocol_version); - -/** - * Set server version string for a connection. - * - * @param[in] con Connection structure previously initialized with - * drizzle_con_create(), drizzle_con_clone(), or related functions. - * @param[in] server_version Server version to use for connection - */ -DRIZZLE_API -void drizzle_con_set_server_version(drizzle_con_st *con, - const char *server_version); - -/** - * Set thread ID for a connection. - * - * @param[in] con Connection structure previously initialized with - * drizzle_con_create(), drizzle_con_clone(), or related functions. - * @param[in] thread_id Thread ID to use for connection - */ -DRIZZLE_API -void drizzle_con_set_thread_id(drizzle_con_st *con, uint32_t thread_id); - -/** - * Set scramble buffer for a connection. - * - * @param[in] con Connection structure previously initialized with - * drizzle_con_create(), drizzle_con_clone(), or related functions. - * @param[in] scramble Scramble to use for connection - */ -DRIZZLE_API -void drizzle_con_set_scramble(drizzle_con_st *con, const uint8_t *scramble); - -/** - * Set capabilities for a connection. - * - * @param[in] con Connection structure previously initialized with - * drizzle_con_create(), drizzle_con_clone(), or related functions. - * @param[in] capabilities Capabilities to use for connection - */ -DRIZZLE_API -void drizzle_con_set_capabilities(drizzle_con_st *con, - int capabilities); - -/** - * Set charset for a connection. - * - * @param[in] con Connection structure previously initialized with - * drizzle_con_create(), drizzle_con_clone(), or related functions. - * @param[in] charset Character set to use for connection - */ -DRIZZLE_API -void drizzle_con_set_charset(drizzle_con_st *con, drizzle_charset_t charset); - -/** - * Set status for a connection. - * - * @param[in] con Connection structure previously initialized with - * drizzle_con_create(), drizzle_con_clone(), or related functions. - * @param[in] status Status to use for connection - */ -DRIZZLE_API -void drizzle_con_set_status(drizzle_con_st *con, drizzle_con_status_t status); - -/** - * Set max packet size for a connection. - * - * @param[in] con Connection structure previously initialized with - * drizzle_con_create(), drizzle_con_clone(), or related functions. - * @param[in] max_packet_size Max packet size to use for connection - */ -DRIZZLE_API -void drizzle_con_set_max_packet_size(drizzle_con_st *con, - uint32_t max_packet_size); - -/** - * Copy all handshake information from one connection into another. - * - * @param[in] con Connection structure previously initialized with - * drizzle_con_create(), drizzle_con_clone(), or related functions. - * @param[in] from Connection structure to copy from. - */ -DRIZZLE_API -void drizzle_con_copy_handshake(drizzle_con_st *con, drizzle_con_st *from); - -/** - * Read command without buffering. - * - * @param[in] con Connection structure previously initialized with - * drizzle_con_create(), drizzle_con_clone(), or related functions. - * @param[out] command Command that was read. - * @param[out] offset Where the data being returned begins in the command data. - * @param[out] size The size of the data chunk being returned. - * @param[out] total The total size of all command data being read. - * @param[out] ret_ptr Standard drizzle return value. - * @return On success, a pointer to an internal buffer with the command data. - * It will be *size bytes in length. - */ -DRIZZLE_API -void *drizzle_con_command_read(drizzle_con_st *con, - drizzle_command_t *command, size_t *offset, - size_t *size, size_t *total, - drizzle_return_t *ret_ptr); - -/** - * Read command and buffer it. - * - * @param[in] con Connection structure previously initialized with - * drizzle_con_create(), drizzle_con_clone(), or related functions. - * @param[out] command Command that was read. - * @param[out] total The total size of all command data being read. - * @param[out] ret_ptr Standard drizzle return value. - * @return On success, allocated buffer that holds the command data of length - * *total. - */ -DRIZZLE_API -void *drizzle_con_command_buffer(drizzle_con_st *con, - drizzle_command_t *command, size_t *total, - drizzle_return_t *ret_ptr); - -DRIZZLE_API -void drizzle_con_command_buffer_free(uint8_t *command_buffer); - -/** @} */ - -#ifdef __cplusplus -} -#endif diff --git a/utils/mysqlcl_idb/libdrizzle-2.0/constants.h b/utils/mysqlcl_idb/libdrizzle-2.0/constants.h deleted file mode 100644 index ffb44a665..000000000 --- a/utils/mysqlcl_idb/libdrizzle-2.0/constants.h +++ /dev/null @@ -1,474 +0,0 @@ -/* - * Drizzle Client & Protocol Library - * - * Copyright (C) 2011 Brian Aker (brian@tangent.org) - * Copyright (C) 2008 Eric Day (eday@oddments.org) - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * - * * The names of its contributors may not be used to endorse or - * promote products derived from this software without specific prior - * written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -#pragma once - -/** - * @file - * @brief Defines, typedefs, enums, and macros - */ - -#include - -#ifdef __cplusplus - -#include - -extern "C" { - -#endif - -/** - * @addtogroup drizzle_constants Constants - * @ingroup drizzle_client_interface - * @ingroup drizzle_server_interface - * @{ - */ - -/* Defines. */ -#define DRIZZLE_DEFAULT_TCP_HOST "localhost" -#define DRIZZLE_DEFAULT_TCP_PORT 4427 -#define DRIZZLE_DEFAULT_TCP_PORT_MYSQL 4427 -#define DRIZZLE_DEFAULT_UDS "/tmp/drizzle.sock" -#define DRIZZLE_DEFAULT_UDS_MYSQL "/tmp/mysql.sock" -#define DRIZZLE_DEFAULT_BACKLOG 64 -#define DRIZZLE_BUFFER_COPY_THRESHOLD 8192 -#define DRIZZLE_ROW_GROW_SIZE 8192 -#define DRIZZLE_STATE_STACK_SIZE 8 -#define DRIZZLE_DEFAULT_SOCKET_TIMEOUT 10 -#define DRIZZLE_DEFAULT_SOCKET_SEND_SIZE 32768 -#define DRIZZLE_DEFAULT_SOCKET_RECV_SIZE 32768 -#define DRIZZLE_MYSQL_PASSWORD_HASH 41 - -#include -#include -#include -#include -#include - -/** @} */ - -/** - * @ingroup drizzle_con - * Options for drizzle_con_st. - */ -enum drizzle_con_options_t -{ - DRIZZLE_CON_NONE= 0, - DRIZZLE_CON_ALLOCATED= (1 << 0), // DEPRECATED - DRIZZLE_CON_MYSQL= (1 << 1), - DRIZZLE_CON_RAW_PACKET= (1 << 2), - DRIZZLE_CON_RAW_SCRAMBLE= (1 << 3), - DRIZZLE_CON_READY= (1 << 4), - DRIZZLE_CON_NO_RESULT_READ= (1 << 5), - DRIZZLE_CON_IO_READY= (1 << 6), - DRIZZLE_CON_LISTEN= (1 << 7), - DRIZZLE_CON_EXPERIMENTAL= (1 << 8), - DRIZZLE_CON_FOUND_ROWS= (1 << 9), - DRIZZLE_CON_INTERACTIVE= (1 << 11), - DRIZZLE_CON_MULTI_STATEMENTS= (1 << 12), - DRIZZLE_CON_AUTH_PLUGIN= (1 << 13) -}; - -#ifndef __cplusplus -typedef enum drizzle_con_options_t drizzle_con_options_t; -#endif - -/** - * @ingroup drizzle_con - * Socket types for drizzle_con_st. - */ -enum drizzle_con_socket_t -{ - DRIZZLE_CON_SOCKET_TCP, - DRIZZLE_CON_SOCKET_UDS -}; - -#ifndef __cplusplus -typedef enum drizzle_con_socket_t drizzle_con_socket_t; -#endif - -/** - * @ingroup drizzle_con - * Status flags for drizle_con_st. - */ -enum drizzle_con_status_t -{ - DRIZZLE_CON_STATUS_NONE= 0, - DRIZZLE_CON_STATUS_IN_TRANS= (1 << 0), - DRIZZLE_CON_STATUS_AUTOCOMMIT= (1 << 1), - DRIZZLE_CON_STATUS_MORE_RESULTS_EXISTS= (1 << 3), - DRIZZLE_CON_STATUS_QUERY_NO_GOOD_INDEX_USED= (1 << 4), - DRIZZLE_CON_STATUS_QUERY_NO_INDEX_USED= (1 << 5), - DRIZZLE_CON_STATUS_CURSOR_EXISTS= (1 << 6), - DRIZZLE_CON_STATUS_LAST_ROW_SENT= (1 << 7), - DRIZZLE_CON_STATUS_DB_DROPPED= (1 << 8), - DRIZZLE_CON_STATUS_NO_BACKSLASH_ESCAPES= (1 << 9), - DRIZZLE_CON_STATUS_QUERY_WAS_SLOW= (1 << 10) -}; - -#ifndef __cplusplus -typedef enum drizzle_con_status_t drizzle_con_status_t; -#endif - -/** - * @ingroup drizzle_con - * Capabilities for drizzle_con_st. - */ -enum drizzle_capabilities_t -{ - DRIZZLE_CAPABILITIES_NONE= 0, - DRIZZLE_CAPABILITIES_LONG_PASSWORD= (1 << 0), - DRIZZLE_CAPABILITIES_FOUND_ROWS= (1 << 1), - DRIZZLE_CAPABILITIES_LONG_FLAG= (1 << 2), - DRIZZLE_CAPABILITIES_CONNECT_WITH_DB= (1 << 3), - DRIZZLE_CAPABILITIES_NO_SCHEMA= (1 << 4), - DRIZZLE_CAPABILITIES_COMPRESS= (1 << 5), - DRIZZLE_CAPABILITIES_ODBC= (1 << 6), - DRIZZLE_CAPABILITIES_LOCAL_FILES= (1 << 7), - DRIZZLE_CAPABILITIES_IGNORE_SPACE= (1 << 8), - DRIZZLE_CAPABILITIES_PROTOCOL_41= (1 << 9), - DRIZZLE_CAPABILITIES_INTERACTIVE= (1 << 10), - DRIZZLE_CAPABILITIES_SSL= (1 << 11), - DRIZZLE_CAPABILITIES_IGNORE_SIGPIPE= (1 << 12), - DRIZZLE_CAPABILITIES_TRANSACTIONS= (1 << 13), - DRIZZLE_CAPABILITIES_RESERVED= (1 << 14), - DRIZZLE_CAPABILITIES_SECURE_CONNECTION= (1 << 15), - DRIZZLE_CAPABILITIES_MULTI_STATEMENTS= (1 << 16), - DRIZZLE_CAPABILITIES_MULTI_RESULTS= (1 << 17), - DRIZZLE_CAPABILITIES_PS_MULTI_RESULTS= (1 << 18), - DRIZZLE_CAPABILITIES_PLUGIN_AUTH= (1 << 19), - DRIZZLE_CAPABILITIES_SSL_VERIFY_SERVER_CERT= (1 << 30), - DRIZZLE_CAPABILITIES_REMEMBER_OPTIONS= (1 << 31), - DRIZZLE_CAPABILITIES_CLIENT= (DRIZZLE_CAPABILITIES_LONG_PASSWORD | - DRIZZLE_CAPABILITIES_FOUND_ROWS | - DRIZZLE_CAPABILITIES_LONG_FLAG | - DRIZZLE_CAPABILITIES_CONNECT_WITH_DB | - DRIZZLE_CAPABILITIES_PLUGIN_AUTH | - DRIZZLE_CAPABILITIES_TRANSACTIONS | - DRIZZLE_CAPABILITIES_PROTOCOL_41 | - DRIZZLE_CAPABILITIES_SECURE_CONNECTION) -}; - -#ifndef __cplusplus -typedef enum drizzle_capabilities_t drizzle_capabilities_t; -#endif - -/** - * @ingroup drizzle_query - * States for drizle_query_st. - */ -enum drizzle_query_state_t -{ - DRIZZLE_QUERY_STATE_INIT, - DRIZZLE_QUERY_STATE_QUERY, - DRIZZLE_QUERY_STATE_RESULT, - DRIZZLE_QUERY_STATE_DONE -}; - -#ifndef __cplusplus -enum drizzle_query_state_t drizzle_query_state_t; -#endif - -/** - * @ingroup drizzle_result - * Options for drizzle_result_st. - */ -enum drizzle_result_options_t -{ - DRIZZLE_RESULT_NONE= 0, - DRIZZLE_RESULT_ALLOCATED= (1 << 0), // DEPRECATED - DRIZZLE_RESULT_SKIP_COLUMN= (1 << 1), - DRIZZLE_RESULT_BUFFER_COLUMN= (1 << 2), - DRIZZLE_RESULT_BUFFER_ROW= (1 << 3), - DRIZZLE_RESULT_EOF_PACKET= (1 << 4), - DRIZZLE_RESULT_ROW_BREAK= (1 << 5) -}; - -#ifndef __cplusplus -typedef enum drizzle_result_options_t drizzle_result_options_t; -#endif - -/** - * @ingroup drizzle_column - * Options for drizzle_column_st. - */ -enum drizzle_column_options_t -{ - DRIZZLE_COLUMN_ALLOCATED= (1 << 0) // DEPRECATED -}; - -#ifndef __cplusplus -typedef enum drizzle_column_options_t drizzle_column_options_t; -#endif - -/** - * @ingroup drizzle_column - * Types for drizzle_column_st. - */ -enum drizzle_column_type_t -{ - DRIZZLE_COLUMN_TYPE_DECIMAL, - DRIZZLE_COLUMN_TYPE_TINY, - DRIZZLE_COLUMN_TYPE_SHORT, - DRIZZLE_COLUMN_TYPE_LONG, - DRIZZLE_COLUMN_TYPE_FLOAT, - DRIZZLE_COLUMN_TYPE_DOUBLE, - DRIZZLE_COLUMN_TYPE_NULL, - DRIZZLE_COLUMN_TYPE_TIMESTAMP, - DRIZZLE_COLUMN_TYPE_LONGLONG, - DRIZZLE_COLUMN_TYPE_INT24, - DRIZZLE_COLUMN_TYPE_DATE, - DRIZZLE_COLUMN_TYPE_TIME, - DRIZZLE_COLUMN_TYPE_DATETIME, - DRIZZLE_COLUMN_TYPE_YEAR, - DRIZZLE_COLUMN_TYPE_NEWDATE, - DRIZZLE_COLUMN_TYPE_VARCHAR, - DRIZZLE_COLUMN_TYPE_BIT, - DRIZZLE_COLUMN_TYPE_NEWDECIMAL= 246, - DRIZZLE_COLUMN_TYPE_ENUM= 247, - DRIZZLE_COLUMN_TYPE_SET= 248, - DRIZZLE_COLUMN_TYPE_TINY_BLOB= 249, - DRIZZLE_COLUMN_TYPE_MEDIUM_BLOB= 250, - DRIZZLE_COLUMN_TYPE_LONG_BLOB= 251, - DRIZZLE_COLUMN_TYPE_BLOB= 252, - DRIZZLE_COLUMN_TYPE_VAR_STRING= 253, - DRIZZLE_COLUMN_TYPE_STRING= 254, - DRIZZLE_COLUMN_TYPE_GEOMETRY= 255 -}; - -#ifndef __cplusplus -typedef enum drizzle_column_type_t drizzle_column_type_t; -#endif - -/** - * @ingroup drizzle_column - * Types for drizzle_column_st for Drizzle. - */ -enum drizzle_column_type_drizzle_t -{ - DRIZZLE_COLUMN_TYPE_DRIZZLE_TINY, - DRIZZLE_COLUMN_TYPE_DRIZZLE_LONG, - DRIZZLE_COLUMN_TYPE_DRIZZLE_DOUBLE, - DRIZZLE_COLUMN_TYPE_DRIZZLE_NULL, - DRIZZLE_COLUMN_TYPE_DRIZZLE_TIMESTAMP, - DRIZZLE_COLUMN_TYPE_DRIZZLE_LONGLONG, - DRIZZLE_COLUMN_TYPE_DRIZZLE_DATETIME, - DRIZZLE_COLUMN_TYPE_DRIZZLE_DATE, - DRIZZLE_COLUMN_TYPE_DRIZZLE_VARCHAR, - DRIZZLE_COLUMN_TYPE_DRIZZLE_NEWDECIMAL, - DRIZZLE_COLUMN_TYPE_DRIZZLE_ENUM, - DRIZZLE_COLUMN_TYPE_DRIZZLE_BLOB, - DRIZZLE_COLUMN_TYPE_DRIZZLE_TIME, - DRIZZLE_COLUMN_TYPE_DRIZZLE_BOOLEAN, - DRIZZLE_COLUMN_TYPE_DRIZZLE_UUID, - DRIZZLE_COLUMN_TYPE_DRIZZLE_MICROTIME, - DRIZZLE_COLUMN_TYPE_DRIZZLE_MAX=DRIZZLE_COLUMN_TYPE_DRIZZLE_MICROTIME -}; - -#ifndef __cplusplus -typedef enum drizzle_column_type_drizzle_t drizzle_column_type_drizzle_t; -#endif - -/** - * @ingroup drizzle_column - * Flags for drizzle_column_st. - */ -enum drizzle_column_flags_t -{ - DRIZZLE_COLUMN_FLAGS_NONE= 0, - DRIZZLE_COLUMN_FLAGS_NOT_NULL= (1 << 0), - DRIZZLE_COLUMN_FLAGS_PRI_KEY= (1 << 1), - DRIZZLE_COLUMN_FLAGS_UNIQUE_KEY= (1 << 2), - DRIZZLE_COLUMN_FLAGS_MULTIPLE_KEY= (1 << 3), - DRIZZLE_COLUMN_FLAGS_BLOB= (1 << 4), - DRIZZLE_COLUMN_FLAGS_UNSIGNED= (1 << 5), - DRIZZLE_COLUMN_FLAGS_ZEROFILL= (1 << 6), - DRIZZLE_COLUMN_FLAGS_BINARY= (1 << 7), - DRIZZLE_COLUMN_FLAGS_ENUM= (1 << 8), - DRIZZLE_COLUMN_FLAGS_AUTO_INCREMENT= (1 << 9), - DRIZZLE_COLUMN_FLAGS_TIMESTAMP= (1 << 10), - DRIZZLE_COLUMN_FLAGS_SET= (1 << 11), - DRIZZLE_COLUMN_FLAGS_NO_DEFAULT_VALUE= (1 << 12), - DRIZZLE_COLUMN_FLAGS_ON_UPDATE_NOW= (1 << 13), - DRIZZLE_COLUMN_FLAGS_PART_KEY= (1 << 14), - DRIZZLE_COLUMN_FLAGS_NUM= (1 << 15), - DRIZZLE_COLUMN_FLAGS_GROUP= (1 << 15), /* NUM & GROUP the same. */ - DRIZZLE_COLUMN_FLAGS_UNIQUE= (1 << 16), - DRIZZLE_COLUMN_FLAGS_BINCMP= (1 << 17), - DRIZZLE_COLUMN_FLAGS_GET_FIXED_FIELDS= (1 << 18), - DRIZZLE_COLUMN_FLAGS_IN_PART_FUNC= (1 << 19), - DRIZZLE_COLUMN_FLAGS_IN_ADD_INDEX= (1 << 20), - DRIZZLE_COLUMN_FLAGS_RENAMED= (1 << 21) -}; - -#ifndef __cplusplus -typedef enum drizzle_column_flags_t drizzle_column_flags_t; -#endif - -/** - * @addtogroup drizzle_types Types - * @ingroup drizzle_client_interface - * @ingroup drizzle_server_interface - * @{ - */ - -/* Types. */ -#ifndef __cplusplus -typedef struct drizzle_st drizzle_st; -typedef struct drizzle_con_tcp_st drizzle_con_tcp_st; -typedef struct drizzle_con_uds_st drizzle_con_uds_st; -typedef struct drizzle_con_st drizzle_con_st; -typedef struct drizzle_query_st drizzle_query_st; -typedef struct drizzle_result_st drizzle_result_st; -typedef struct drizzle_column_st drizzle_column_st; -#else -class drizzle_st; -class drizzle_con_tcp_st; -class drizzle_con_uds_st; -class drizzle_con_st; -class drizzle_query_st; -class drizzle_result_st; -class drizzle_column_st; -#endif - -typedef char drizzle_field_t_type; -typedef drizzle_field_t_type *drizzle_field_t; -typedef drizzle_field_t drizzle_row_t_type; -typedef drizzle_row_t_type *drizzle_row_t; -typedef size_t * drizzle_field_sizes_type; -typedef uint8_t drizzle_charset_t; - -#if defined(__cplusplus) -typedef ::std::vector drizzle_row_list_t; -typedef ::std::vector drizzle_field_sizes_list_t; -#else -typedef void drizzle_row_list_t; -typedef void drizzle_field_sizes_list_t; -#endif - -/* Function types. */ -typedef void (drizzle_context_free_fn)(drizzle_st *drizzle, void *context); -typedef void (drizzle_log_fn)(const char *line, drizzle_verbose_t verbose, void *context); -typedef drizzle_return_t (drizzle_state_fn)(drizzle_con_st *con); -typedef void (drizzle_con_context_free_fn)(drizzle_con_st *con, void *context); -typedef void (drizzle_query_context_free_fn)(drizzle_query_st *query, void *context); -/** - * Custom function to register or deregister interest in file descriptor - * events. See drizzle_set_event_watch_fn(). - * - * @param[in] con Connection that has changed the events it is interested in. - * Use drizzle_con_fd() to get the file descriptor. - * @param[in] events A bit mask of POLLIN | POLLOUT, specifying if the - * connection is waiting for read or write events. - * @param[in] context Application context pointer registered with - * drizzle_set_event_watch_fn(). - * @return DRIZZLE_RETURN_OK if successful. - */ -typedef drizzle_return_t (drizzle_event_watch_fn)(drizzle_con_st *con, - short events, - void *context); - -/** @} */ - -/** - * @addtogroup drizzle_macros Macros - * @ingroup drizzle_client_interface - * @ingroup drizzle_server_interface - * @{ - */ - -/* Protocol unpacking macros. */ -#define drizzle_get_byte2(__buffer) \ - (uint16_t)((__buffer)[0] | \ - ((__buffer)[1] << 8)) -#define drizzle_get_byte3(__buffer) \ - (uint32_t)((__buffer)[0] | \ - ((__buffer)[1] << 8) | \ - ((__buffer)[2] << 16)) -#define drizzle_get_byte4(__buffer) \ - (uint32_t)((__buffer)[0] | \ - ((__buffer)[1] << 8) | \ - ((__buffer)[2] << 16) | \ - ((__buffer)[3] << 24)) -#define drizzle_get_byte8(__buffer) \ - ((uint64_t)(__buffer)[0] | \ - ((uint64_t)(__buffer)[1] << 8) | \ - ((uint64_t)(__buffer)[2] << 16) | \ - ((uint64_t)(__buffer)[3] << 24) | \ - ((uint64_t)(__buffer)[4] << 32) | \ - ((uint64_t)(__buffer)[5] << 40) | \ - ((uint64_t)(__buffer)[6] << 48) | \ - ((uint64_t)(__buffer)[7] << 56)) - -/* Protocol packing macros. */ -#define drizzle_set_byte2(__buffer, __int) do { \ - (__buffer)[0]= (uint8_t)((__int) & 0xFF); \ - (__buffer)[1]= (uint8_t)(((__int) >> 8) & 0xFF); } while (0) -#define drizzle_set_byte3(__buffer, __int) do { \ - (__buffer)[0]= (uint8_t)((__int) & 0xFF); \ - (__buffer)[1]= (uint8_t)(((__int) >> 8) & 0xFF); \ - (__buffer)[2]= (uint8_t)(((__int) >> 16) & 0xFF); } while (0) -#define drizzle_set_byte4(__buffer, __int) do { \ - (__buffer)[0]= (uint8_t)((__int) & 0xFF); \ - (__buffer)[1]= (uint8_t)(((__int) >> 8) & 0xFF); \ - (__buffer)[2]= (uint8_t)(((__int) >> 16) & 0xFF); \ - (__buffer)[3]= (uint8_t)(((__int) >> 24) & 0xFF); } while (0) -#define drizzle_set_byte8(__buffer, __int) do { \ - (__buffer)[0]= (uint8_t)((__int) & 0xFF); \ - (__buffer)[1]= (uint8_t)(((__int) >> 8) & 0xFF); \ - (__buffer)[2]= (uint8_t)(((__int) >> 16) & 0xFF); \ - (__buffer)[3]= (uint8_t)(((__int) >> 24) & 0xFF); \ - (__buffer)[4]= (uint8_t)(((__int) >> 32) & 0xFF); \ - (__buffer)[5]= (uint8_t)(((__int) >> 40) & 0xFF); \ - (__buffer)[6]= (uint8_t)(((__int) >> 48) & 0xFF); \ - (__buffer)[7]= (uint8_t)(((__int) >> 56) & 0xFF); } while (0) - -/* Multi-byte character macros. */ -#define drizzle_mb_char(__c) (((__c) & 0x80) != 0) -#define drizzle_mb_length(__c) \ - ((uint32_t)(__c) <= 0x7f ? 1 : \ - ((uint32_t)(__c) <= 0x7ff ? 2 : \ - ((uint32_t)(__c) <= 0xd7ff ? 3 : \ - ((uint32_t)(__c) <= 0xdfff || (uint32_t)(__c) > 0x10ffff ? 0 : \ - ((uint32_t)(__c) <= 0xffff ? 3 : 4))))) - -/** @} */ - -#ifdef __cplusplus -} -#endif diff --git a/utils/mysqlcl_idb/libdrizzle-2.0/deprecated_enum.h b/utils/mysqlcl_idb/libdrizzle-2.0/deprecated_enum.h deleted file mode 100644 index 5d90877a2..000000000 --- a/utils/mysqlcl_idb/libdrizzle-2.0/deprecated_enum.h +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Drizzle Client & Protocol Library - * - * Copyright (C) 2011 Brian Aker (brian@tangent.org) - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * - * * The names of its contributors may not be used to endorse or - * promote products derived from this software without specific prior - * written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -#pragma once - -/** - * @ingroup drizzle_query - * Options for drizzle_query_st. - */ -enum drizzle_query_options_t -{ - DRIZZLE_QUERY_NONE, - DRIZZLE_QUERY_ALLOCATED -}; - -#ifndef __cplusplus -typedef enum drizzle_query_options_t drizzle_query_options_t; -#endif - -/** - * @ingroup drizzle - * Options for drizzle_st. - */ -enum drizzle_options_t -{ - DRIZZLE_NON_BLOCKING, - DRIZZLE_FREE_OBJECTS, - DRIZZLE_ASSERT_DANGLING -}; - -#ifndef __cplusplus -typedef enum drizzle_options_t drizzle_options_t; -#endif - diff --git a/utils/mysqlcl_idb/libdrizzle-2.0/drizzle.h b/utils/mysqlcl_idb/libdrizzle-2.0/drizzle.h deleted file mode 100644 index 96bf17013..000000000 --- a/utils/mysqlcl_idb/libdrizzle-2.0/drizzle.h +++ /dev/null @@ -1,397 +0,0 @@ -/* - * Drizzle Client & Protocol Library - * - * Copyright (C) 2008 Eric Day (eday@oddments.org) - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * - * * The names of its contributors may not be used to endorse or - * promote products derived from this software without specific prior - * written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -#pragma once - -/** - * @file - * @brief Drizzle Declarations - */ - -#include - -#ifdef _WIN32 -# define WIN32_LEAN_AND_MEAN -# define NOMINMAX - -# include -# include -# include -# include - -# undef close -# define close _close -typedef unsigned int in_port_t; -//typedef long ssize_t; - -# define snprintf _snprintf - -struct sockaddr_un -{ - short int sun_family; - char sun_path[108]; -}; - -//# define poll WSAPoll -//# define pollfd WSAPOLLFD - -#if defined(__GNUC__) -# include -#else -# if !defined(__cplusplus) -typedef enum { false = 0, true = 1 } _Bool; -typedef _Bool bool; -#endif -#endif - -#else -# if !defined(__cplusplus) -# include -# endif -# include -# include -# include -# include -# include -# include -# include -#endif - -#include -#include - -#include -#include -#include -#include -#include -#include - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * @addtogroup drizzle Drizzle Declarations - * @ingroup drizzle_client_interface - * @ingroup drizzle_server_interface - * - * This is the core library structure that other structures (such as - * connections) are created from. - * - * There is no locking within a single drizzle_st structure, so for threaded - * applications you must either ensure isolation in the application or use - * multiple drizzle_st structures (for example, one for each thread). - * @{ - */ - -/** - * Get library version string. - * - * @return Pointer to static buffer in library that holds the version string. - */ -DRIZZLE_API -const char *drizzle_version(void); - -/** - * Get bug report URL. - * - * @return Bug report URL string. - */ -DRIZZLE_API -const char *drizzle_bugreport(void); - -/** - * Get string with the name of the given verbose level. - * - * @param[in] verbose Verbose logging level. - * @return String form of verbose level. - */ -DRIZZLE_API -const char *drizzle_verbose_name(drizzle_verbose_t verbose); - -/** - * Initialize a drizzle structure. Always check the return value even if passing - * in a pre-allocated structure. Some other initialization may have failed. - * - * @param[in] drizzle Caller allocated structure, or NULL to allocate one. - * @return On success, a pointer to the (possibly allocated) structure. On - * failure this will be NULL. - */ -DRIZZLE_API -drizzle_st *drizzle_create(); - -/** - * Clone a drizzle structure. - * - * @param[in] drizzle Caller allocated structure, or NULL to allocate one. - * @param[in] from Drizzle structure to use as a source to clone from. - * @return Same return as drizzle_create(). - */ -DRIZZLE_API -drizzle_st *drizzle_clone(const drizzle_st *from); - -/** - * Free a drizzle structure. - * - * @param[in] drizzle Drizzle structure previously initialized with - * drizzle_create() or drizzle_clone(). - */ -DRIZZLE_API -void drizzle_free(drizzle_st *drizzle); - -/** - * Return an error string for last error encountered. - * - * @param[in] drizzle Drizzle structure previously initialized with - * drizzle_create() or drizzle_clone(). - * @return Pointer to static buffer in library that holds an error string. - */ -DRIZZLE_API -const char *drizzle_error(const drizzle_st *drizzle); - -/** - * Value of errno in the case of a DRIZZLE_RETURN_ERRNO return value. - * - * @param[in] drizzle Drizzle structure previously initialized with - * drizzle_create() or drizzle_clone(). - * @return An errno value as defined in your system errno.h file. - */ -DRIZZLE_API -int drizzle_errno(const drizzle_st *drizzle); - -/** - * Get server defined error code for the last result read. - * - * @param[in] drizzle Drizzle structure previously initialized with - * drizzle_create() or drizzle_clone(). - * @return An error code given back in the server response. - */ -DRIZZLE_API -uint16_t drizzle_error_code(const drizzle_st *drizzle); - -/** - * Get SQL state code for the last result read. - * - * @param[in] drizzle Drizzle structure previously initialized with - * drizzle_create() or drizzle_clone(). - * @return A SQLSTATE code given back in the server response. - */ -DRIZZLE_API -const char *drizzle_sqlstate(const drizzle_st *drizzle); - -/** - * Get application context pointer. - * - * @param[in] drizzle Drizzle structure previously initialized with - * drizzle_create() or drizzle_clone(). - * @return Application context that was previously set, or NULL. - */ -DRIZZLE_API -void *drizzle_context(const drizzle_st *drizzle); - -/** - * Set application context pointer. - * - * @param[in] drizzle Drizzle structure previously initialized with - * drizzle_create() or drizzle_clone(). - * @param[in] context Application context to set. - */ -DRIZZLE_API -void drizzle_set_context(drizzle_st *drizzle, void *context); - -/** - * Set function to call when the drizzle structure is being cleaned up so - * the application can clean up the context pointer. - * - * @param[in] drizzle Drizzle structure previously initialized with - * drizzle_create() or drizzle_clone(). - * @param[in] function Function to call to clean up drizzle context. - */ -DRIZZLE_API -void drizzle_set_context_free_fn(drizzle_st *drizzle, - drizzle_context_free_fn *function); - -/** - * Get current socket I/O activity timeout value. - * - * @param[in] drizzle Drizzle structure previously initialized with - * drizzle_create() or drizzle_clone(). - * @return Timeout in milliseconds to wait for I/O activity. A negative value - * means an infinite timeout. - */ -DRIZZLE_API -int drizzle_timeout(const drizzle_st *drizzle); - -/** - * Set socket I/O activity timeout for connections in a Drizzle structure. - * - * @param[in] drizzle Drizzle structure previously initialized with - * drizzle_create() or drizzle_clone(). - * @param[in] timeout Milliseconds to wait for I/O activity. A negative value - * means an infinite timeout. - */ -DRIZZLE_API -void drizzle_set_timeout(drizzle_st *drizzle, int timeout); - -/** - * Get current verbosity threshold for logging messages. - * - * @param[in] drizzle Drizzle structure previously initialized with - * drizzle_create() or drizzle_clone(). - * @return Current verbosity threshold. - */ -DRIZZLE_API -drizzle_verbose_t drizzle_verbose(const drizzle_st *drizzle); - -/** - * Set verbosity threshold for logging messages. If this is set above - * DRIZZLE_VERBOSE_NEVER and the drizzle_set_log_fn() callback is set to NULL, - * messages are printed to STDOUT. - * - * @param[in] drizzle Drizzle structure previously initialized with - * drizzle_create() or drizzle_clone(). - * @param[in] verbose Verbosity threshold of what to log. - */ -DRIZZLE_API -void drizzle_set_verbose(drizzle_st *drizzle, drizzle_verbose_t verbose); - -/** - * Set logging function for a drizzle structure. This function is only called - * for log messages that are above the verbosity threshold set with - * drizzle_set_verbose(). - * - * @param[in] drizzle Drizzle structure previously initialized with - * drizzle_create() or drizzle_clone(). - * @param[in] function Function to call when there is a logging message. - * @param[in] context Argument to pass into the callback function. - */ -DRIZZLE_API -void drizzle_set_log_fn(drizzle_st *drizzle, drizzle_log_fn *function, - void *context); - -/** - * Set a custom I/O event watcher function for a drizzle structure. Used to - * integrate libdrizzle with a custom event loop. The callback will be invoked - * to register or deregister interest in events for a connection. When the - * events are triggered, drizzle_con_set_revents() should be called to - * indicate which events are ready. The event loop should stop waiting for - * these events, as libdrizzle will call the callback again if it is still - * interested. To resume processing, the libdrizzle function that returned - * DRIZZLE_RETURN_IO_WAIT should be called again. See drizzle_event_watch_fn(). - * - * @param[in] drizzle Drizzle structure previously initialized with - * drizzle_create() or drizzle_clone(). - * @param[in] function Function to call when there is an I/O event. - * @param[in] context Argument to pass into the callback function. - */ -DRIZZLE_API -void drizzle_set_event_watch_fn(drizzle_st *drizzle, - drizzle_event_watch_fn *function, - void *context); - -/** - * Initialize a connection structure. Always check the return value even if - * passing in a pre-allocated structure. Some other initialization may have - * failed. - * - * @param[in] drizzle Drizzle structure previously initialized with - * drizzle_create() or drizzle_clone(). - * @param[in] con Caller allocated structure, or NULL to allocate one. - * @return On success, a pointer to the (possibly allocated) structure. On - * failure this will be NULL. - */ -DRIZZLE_API -drizzle_con_st *drizzle_con_create(drizzle_st *drizzle); - -/** - * Clone a connection structure. - * - * @param[in] drizzle Drizzle structure previously initialized with - * drizzle_create() or drizzle_clone(). - * @param[in] con Caller allocated structure, or NULL to allocate one. - * @param[in] from Connection structure to use as a source to clone from. - * @return Same return as drizzle_con_create(). - */ -DRIZZLE_API -drizzle_con_st *drizzle_con_clone(drizzle_st *drizzle, drizzle_con_st *con); - -DRIZZLE_API -drizzle_return_t drizzle_set_option(drizzle_st *drizzle, drizzle_options_t arg, bool set); - -/** - * Free a connection structure. - * - * @param[in] con Connection structure previously initialized with - * drizzle_con_create(), drizzle_con_clone(), or related functions. - */ -DRIZZLE_API -void drizzle_con_free(drizzle_con_st *con); - -/** - * Free all connections in a drizzle structure. - * - * @param[in] drizzle Drizzle structure previously initialized with - * drizzle_create() or drizzle_clone(). - */ -DRIZZLE_API -void drizzle_con_free_all(drizzle_st *drizzle); - -/** - * Wait for I/O on connections. - * - * @param[in] drizzle Drizzle structure previously initialized with - * drizzle_create() or drizzle_clone(). - * @return Standard drizzle return value. - */ -DRIZZLE_API -drizzle_return_t drizzle_con_wait(drizzle_st *drizzle); - -/** - * Get next connection that is ready for I/O. - * - * @param[in] drizzle Drizzle structure previously initialized with - * drizzle_create() or drizzle_clone(). - * @return Connection that is ready for I/O, or NULL if there are none. - */ -DRIZZLE_API -drizzle_con_st *drizzle_con_ready(drizzle_st *drizzle); - -/** @} */ - -#ifdef __cplusplus -} -#endif diff --git a/utils/mysqlcl_idb/libdrizzle-2.0/drizzle_client.h b/utils/mysqlcl_idb/libdrizzle-2.0/drizzle_client.h deleted file mode 100644 index 41f80044a..000000000 --- a/utils/mysqlcl_idb/libdrizzle-2.0/drizzle_client.h +++ /dev/null @@ -1,113 +0,0 @@ -/* - * Drizzle Client & Protocol Library - * - * Copyright (C) 2008 Eric Day (eday@oddments.org) - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * - * * The names of its contributors may not be used to endorse or - * promote products derived from this software without specific prior - * written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -#pragma once - -/** - * @file - * @brief Drizzle Declarations for Clients - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * @defgroup drizzle_client_interface Drizzle Client Interface - */ - -/** - * @addtogroup drizzle_client Drizzle Declarations for Clients - * @ingroup drizzle_client_interface - * @{ - */ - -/** - * Add TCP (IPv4 or IPv6) connection with common arguments. - * - * @param[in] drizzle Drizzle structure previously initialized with - * drizzle_create() or drizzle_clone(). - * @param[in] con Caller allocated structure, or NULL to allocate one. - * @param[in] host Host to connect to. This may be a hostname to resolve, an - * IPv4 address, or an IPv6 address. This is passed directly to getaddrinfo(). - * @param[in] port Remote port to connect to. - * @param[in] user User to use while establishing the connection. - * @param[in] password Password to use while establishing the connection. - * @param[in] db Initial database to connect to. - * @param[in] options Drizzle connection options to add. - * @return Same return as drizzle_con_create(). - */ -DRIZZLE_API -drizzle_con_st *drizzle_con_add_tcp(drizzle_st *drizzle, - const char *host, in_port_t port, - const char *user, const char *password, - const char *db, - drizzle_con_options_t options); - -/** - * Add unix domain socket connection with common arguments. - * - * @param[in] drizzle Drizzle structure previously initialized with - * drizzle_create() or drizzle_clone(). - * @param[in] con Caller allocated structure, or NULL to allocate one. - * @param[in] uds Path to unix domain socket to use for connection. - * @param[in] user User to use while establishing the connection. - * @param[in] password Password to use while establishing the connection. - * @param[in] db Initial database to connect to. - * @param[in] options Drizzle connection options to add. - * @return Same return as drizzle_con_create(). - */ -DRIZZLE_API -drizzle_con_st *drizzle_con_add_uds(drizzle_st *drizzle, - const char *uds, const char *user, - const char *password, const char *db, - drizzle_con_options_t options); - -/** @} */ - -#ifdef __cplusplus -} -#endif diff --git a/utils/mysqlcl_idb/libdrizzle-2.0/drizzle_local.h b/utils/mysqlcl_idb/libdrizzle-2.0/drizzle_local.h deleted file mode 100644 index c404d81be..000000000 --- a/utils/mysqlcl_idb/libdrizzle-2.0/drizzle_local.h +++ /dev/null @@ -1,163 +0,0 @@ -/* - * Drizzle Client & Protocol Library - * - * Copyright (C) 2008 Eric Day (eday@oddments.org) - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * - * * The names of its contributors may not be used to endorse or - * promote products derived from this software without specific prior - * written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -#pragma once - -/** - * @file - * @brief Local Drizzle Declarations - */ - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * @addtogroup drizzle_local Local Drizzle Declarations - * @ingroup drizzle - * @{ - */ - -/** - * Set the error string. - * - * @param[in] drizzle Drizzle structure previously initialized with - * drizzle_create() or drizzle_clone(). - * @param[in] function Name of function the error happened in. - * @param[in] format Format and variable argument list of message. - */ -DRIZZLE_LOCAL -void drizzle_set_error(drizzle_st *drizzle, const char *function, - const char *format, ...); - -/** - * Log a message. - * - * @param[in] drizzle Drizzle structure previously initialized with - * drizzle_create() or drizzle_clone(). - * @param[in] verbose Logging level of the message. - * @param[in] format Format and variable argument list of message. - * @param[in] args Variable argument list that has been initialized. - */ -DRIZZLE_LOCAL -void drizzle_log(drizzle_st *drizzle, drizzle_verbose_t verbose, - const char *format, va_list args); - -/** - * Log a fatal message, see drizzle_log() for argument details. - */ -static inline void drizzle_log_fatal(drizzle_st *drizzle, const char *format, - ...) -{ - va_list args; - - if (drizzle->verbose >= DRIZZLE_VERBOSE_FATAL) - { - va_start(args, format); - drizzle_log(drizzle, DRIZZLE_VERBOSE_FATAL, format, args); - va_end(args); - } -} - -/** - * Log an error message, see drizzle_log() for argument details. - */ -static inline void drizzle_log_error(drizzle_st *drizzle, const char *format, - ...) -{ - va_list args; - - if (drizzle->verbose >= DRIZZLE_VERBOSE_ERROR) - { - va_start(args, format); - drizzle_log(drizzle, DRIZZLE_VERBOSE_ERROR, format, args); - va_end(args); - } -} - -/** - * Log an info message, see drizzle_log() for argument details. - */ -static inline void drizzle_log_info(drizzle_st *drizzle, const char *format, - ...) -{ - va_list args; - - if (drizzle->verbose >= DRIZZLE_VERBOSE_INFO) - { - va_start(args, format); - drizzle_log(drizzle, DRIZZLE_VERBOSE_INFO, format, args); - va_end(args); - } -} - -/** - * Log a debug message, see drizzle_log() for argument details. - */ -static inline void drizzle_log_debug(drizzle_st *drizzle, const char *format, - ...) -{ - va_list args; - - if (drizzle->verbose >= DRIZZLE_VERBOSE_DEBUG) - { - va_start(args, format); - drizzle_log(drizzle, DRIZZLE_VERBOSE_DEBUG, format, args); - va_end(args); - } -} - -/** - * Log a crazy message, see drizzle_log() for argument details. - */ -static inline void drizzle_log_crazy(drizzle_st *drizzle, const char *format, - ...) -{ - va_list args; - - if (drizzle->verbose >= DRIZZLE_VERBOSE_CRAZY) - { - va_start(args, format); - drizzle_log(drizzle, DRIZZLE_VERBOSE_CRAZY, format, args); - va_end(args); - } -} - -/** @} */ - -#ifdef __cplusplus -} -#endif diff --git a/utils/mysqlcl_idb/libdrizzle-2.0/drizzle_server.h b/utils/mysqlcl_idb/libdrizzle-2.0/drizzle_server.h deleted file mode 100644 index 8b2a98c83..000000000 --- a/utils/mysqlcl_idb/libdrizzle-2.0/drizzle_server.h +++ /dev/null @@ -1,127 +0,0 @@ -/* - * Drizzle Client & Protocol Library - * - * Copyright (C) 2008 Eric Day (eday@oddments.org) - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * - * * The names of its contributors may not be used to endorse or - * promote products derived from this software without specific prior - * written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -#pragma once - -/** - * @file - * @brief Drizzle Declarations for Servers - */ - -#include -#include -#include -#include -#include -#include -#include -#include - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * @defgroup drizzle_server_interface Drizzle Server Interface - */ - -/** - * @addtogroup drizzle_server Drizzle Declarations for Servers - * @ingroup drizzle_server_interface - * @{ - */ - -/** - * Add TCP (IPv4 or IPv6) connection for listening with common arguments. - * - * @param[in] drizzle Drizzle structure previously initialized with - * drizzle_create() or drizzle_clone(). - * @param[in] con Caller allocated structure, or NULL to allocate one. - * @param[in] host Host to listen on. This may be a hostname to resolve, an - * IPv4 address, or an IPv6 address. This is passed directly to getaddrinfo(). - * @param[in] port Port to connect to. - * @param[in] backlog Number of backlog connections passed to listen(). - * @param[in] options Drizzle connection options to add. - * @return Same return as drizzle_con_create(). - */ -DRIZZLE_API -drizzle_con_st *drizzle_con_add_tcp_listen(drizzle_st *drizzle, - const char *host, in_port_t port, - int backlog, - drizzle_con_options_t options); - -/** - * Add unix domain socket connection for listening with common arguments. - * - * @param[in] drizzle Drizzle structure previously initialized with - * drizzle_create() or drizzle_clone(). - * @param[in] uds Path to unix domain socket to use for listening. - * @param[in] backlog Number of backlog connections passed to listen(). - * @param[in] options Drizzle connection options to add. - * @return Same return as drizzle_con_create(). - */ -DRIZZLE_API -drizzle_con_st *drizzle_con_add_uds_listen(drizzle_st *drizzle, - const char *uds, int backlog, - drizzle_con_options_t options); - -/** - * Get next connection marked for listening that is ready for I/O. - * - * @param[in] drizzle Drizzle structure previously initialized with - * drizzle_create() or drizzle_clone(). - * @return Connection that is ready to accept, or NULL if there are none. - */ -DRIZZLE_API -drizzle_con_st *drizzle_con_ready_listen(drizzle_st *drizzle); - -/** - * Accept a new connection and initialize the connection structure for it. - * - * @param[in] drizzle Drizzle structure previously initialized with - * drizzle_create() or drizzle_clone(). - * @param[out] ret_ptr Standard drizzle return value. - * @return Same return as drizzle_con_create(). - */ -DRIZZLE_API -drizzle_con_st *drizzle_con_accept(drizzle_st *drizzle, - drizzle_return_t *ret_ptr); - -/** @} */ - -#ifdef __cplusplus -} -#endif diff --git a/utils/mysqlcl_idb/libdrizzle-2.0/field_client.h b/utils/mysqlcl_idb/libdrizzle-2.0/field_client.h deleted file mode 100644 index c182103c9..000000000 --- a/utils/mysqlcl_idb/libdrizzle-2.0/field_client.h +++ /dev/null @@ -1,85 +0,0 @@ -/* - * Drizzle Client & Protocol Library - * - * Copyright (C) 2008 Eric Day (eday@oddments.org) - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * - * * The names of its contributors may not be used to endorse or - * promote products derived from this software without specific prior - * written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -#pragma once - -/** - * @file - * @brief Field Declarations for Clients - */ - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * @addtogroup drizzle_field_client Field Declarations for Clients - * @ingroup drizzle_client_interface - * - * These functions allow you to access fields in a result set if the result is - * unbuffered. If the result is buffered, you can access the fields through the - * row functions. - * @{ - */ - -/** - * Read field for unbuffered result, possibly in parts. This is especially - * useful for blob streaming, since the client does not need to buffer the - * entire blob. - */ -DRIZZLE_API -drizzle_field_t drizzle_field_read(drizzle_result_st *result, size_t *offset, - size_t *size, size_t *total, - drizzle_return_t *ret_ptr); - -/** - * Buffer one field. - */ -DRIZZLE_API -drizzle_field_t drizzle_field_buffer(drizzle_result_st *result, size_t *total, - drizzle_return_t *ret_ptr); - -/** - * Free a buffered field. - */ -DRIZZLE_API -void drizzle_field_free(drizzle_field_t field); - -/** @} */ - -#ifdef __cplusplus -} -#endif diff --git a/utils/mysqlcl_idb/libdrizzle-2.0/field_server.h b/utils/mysqlcl_idb/libdrizzle-2.0/field_server.h deleted file mode 100644 index 494126797..000000000 --- a/utils/mysqlcl_idb/libdrizzle-2.0/field_server.h +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Drizzle Client & Protocol Library - * - * Copyright (C) 2008 Eric Day (eday@oddments.org) - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * - * * The names of its contributors may not be used to endorse or - * promote products derived from this software without specific prior - * written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -#pragma once - -/** - * @file - * @brief Field Declarations for Servers - */ - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * @addtogroup drizzle_field_server Field Declarations for Servers - * @ingroup drizzle_server_interface - * - * These functions allow you to send a field over a connection. - * @{ - */ - -DRIZZLE_API -drizzle_return_t drizzle_field_write(drizzle_result_st *result, - const drizzle_field_t field, size_t size, - size_t total); - -/** @} */ - -#ifdef __cplusplus -} -#endif diff --git a/utils/mysqlcl_idb/libdrizzle-2.0/handshake_client.h b/utils/mysqlcl_idb/libdrizzle-2.0/handshake_client.h deleted file mode 100644 index 25eac7461..000000000 --- a/utils/mysqlcl_idb/libdrizzle-2.0/handshake_client.h +++ /dev/null @@ -1,82 +0,0 @@ -/* - * Drizzle Client & Protocol Library - * - * Copyright (C) 2008 Eric Day (eday@oddments.org) - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * - * * The names of its contributors may not be used to endorse or - * promote products derived from this software without specific prior - * written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -#pragma once - -/** - * @file - * @brief Handshake Declarations for Clients - */ - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * @addtogroup drizzle_handshake_client Handshake Declarations for Clients - * @ingroup drizzle_client_interface - * - * These functions are used to send and receive handshake packets for a client. - * These are only used by low-level clients when the DRIZZLE_CON_RAW_PACKET - * option is set, so most applications will never need to use these. - * @{ - */ - -/** - * Read handshake packet from the server in a client. - * - * @param[in] con Connection structure previously initialized with - * drizzle_con_create(), drizzle_con_clone(), or related functions. - * @return Standard drizzle return value. - */ -DRIZZLE_API -drizzle_return_t drizzle_handshake_server_read(drizzle_con_st *con); - -/** - * Write client handshake packet to a server. - * - * @param[in] con Connection structure previously initialized with - * drizzle_con_create(), drizzle_con_clone(), or related functions. - * @return Standard drizzle return value. - */ -DRIZZLE_API -drizzle_return_t drizzle_handshake_client_write(drizzle_con_st *con); - -/** @} */ - -#ifdef __cplusplus -} -#endif diff --git a/utils/mysqlcl_idb/libdrizzle-2.0/handshake_server.h b/utils/mysqlcl_idb/libdrizzle-2.0/handshake_server.h deleted file mode 100644 index 715f4bb56..000000000 --- a/utils/mysqlcl_idb/libdrizzle-2.0/handshake_server.h +++ /dev/null @@ -1,80 +0,0 @@ -/* - * Drizzle Client & Protocol Library - * - * Copyright (C) 2008 Eric Day (eday@oddments.org) - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * - * * The names of its contributors may not be used to endorse or - * promote products derived from this software without specific prior - * written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -#pragma once - -/** - * @file - * @brief Handshake Declarations for Servers - */ - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * @addtogroup drizzle_handshake_server Handshake Declarations for Servers - * @ingroup drizzle_server_interface - * - * These functions are used to send and receive handshake packets in a server. - * @{ - */ - -/** - * Write server handshake packet to a client. - * - * @param[in] con Connection structure previously initialized with - * drizzle_con_create(), drizzle_con_clone(), or related functions. - * @return Standard drizzle return value. - */ -DRIZZLE_API -drizzle_return_t drizzle_handshake_server_write(drizzle_con_st *con); - -/** - * Read handshake packet from the client in a server. - * - * @param[in] con Connection structure previously initialized with - * drizzle_con_create(), drizzle_con_clone(), or related functions. - * @return Standard drizzle return value. - */ -DRIZZLE_API -drizzle_return_t drizzle_handshake_client_read(drizzle_con_st *con); - -/** @} */ - -#ifdef __cplusplus -} -#endif diff --git a/utils/mysqlcl_idb/libdrizzle-2.0/libdrizzle.h b/utils/mysqlcl_idb/libdrizzle-2.0/libdrizzle.h deleted file mode 100644 index d19a85683..000000000 --- a/utils/mysqlcl_idb/libdrizzle-2.0/libdrizzle.h +++ /dev/null @@ -1,36 +0,0 @@ -/* Drizzle Client Library - * Copyright (C) 2011 Olaf van der Spek - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * - * * The names of its contributors may not be used to endorse or - * promote products derived from this software without specific prior - * written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#pragma once - -#include diff --git a/utils/mysqlcl_idb/libdrizzle-2.0/libdrizzle.hpp b/utils/mysqlcl_idb/libdrizzle-2.0/libdrizzle.hpp deleted file mode 100644 index 36bd2ddf3..000000000 --- a/utils/mysqlcl_idb/libdrizzle-2.0/libdrizzle.hpp +++ /dev/null @@ -1,385 +0,0 @@ -/* Drizzle Client Library - * Copyright (C) 2011 Olaf van der Spek - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * - * * The names of its contributors may not be used to endorse or - * promote products derived from this software without specific prior - * written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#pragma once - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -namespace drizzle { - -class bad_query : public std::runtime_error -{ -public: - bad_query(const std::string& v) : std::runtime_error(v) - { - } -}; - -class noncopyable -{ -protected: - noncopyable() - { - } -private: - noncopyable(const noncopyable&); - void operator=(const noncopyable&); -}; - -class drizzle_c : noncopyable -{ -public: - drizzle_c() - { - b_= drizzle_create(); - } - - ~drizzle_c() - { - drizzle_free(b_); - } - - operator drizzle_st*() - { - return b_; - } -private: - drizzle_st *b_; -}; - -class result_c -{ -public: - operator drizzle_result_st*() - { - if (!b_) - b_.reset(new drizzle_result_st, drizzle_result_free); - return b_.get(); - } - - const char* error() - { - return drizzle_result_error(*this); - } - - uint16_t error_code() - { - return drizzle_result_error_code(*this); - } - - uint16_t column_count() - { - return drizzle_result_column_count(*this); - } - - uint64_t row_count() - { - return drizzle_result_row_count(*this); - } - - drizzle_column_st* column_next() - { - return drizzle_column_next(*this); - } - - drizzle_row_t row_next() - { - return drizzle_row_next(*this); - } - - void column_seek(uint16_t i) - { - drizzle_column_seek(*this, i); - } - - void row_seek(uint64_t i) - { - drizzle_row_seek(*this, i); - } - - size_t* row_field_sizes() - { - return drizzle_row_field_sizes(*this); - } -private: - boost::shared_ptr b_; -}; - -class connection_c : noncopyable -{ -public: - explicit connection_c(drizzle_c& drizzle) - { - b_= drizzle_con_create(drizzle); - - if (b_ == NULL) - { - throw "drizzle_con_create() failed"; - } - read_conf_files(); - } - - ~connection_c() - { - drizzle_con_free(b_); - } - - operator drizzle_con_st*() - { - return b_; - } - - const char* error() - { - return drizzle_con_error(b_); - } - - void set_tcp(const char* host, in_port_t port) - { - drizzle_con_set_tcp(b_, host, port); - } - - void set_auth(const char* user, const char* password) - { - drizzle_con_set_auth(b_, user, password); - } - - void set_db(const char* db) - { - drizzle_con_set_db(b_, db); - } - - drizzle_return_t query(result_c& result, const char* str, size_t str_size) - { - drizzle_return_t ret; - - drizzle_query(*this, result, str, str_size, &ret); - - if (!ret) - { - ret = drizzle_result_buffer(result); - } - - return ret; - } - - drizzle_return_t query(result_c& result, const std::string& str) - { - return query(result, str.data(), str.size()); - } - - drizzle_return_t query(result_c& result, const char* str) - { - return query(result, str, strlen(str)); - } - - result_c query(const char* str, size_t str_size) - { - result_c result; - if (query(result, str, str_size)) - { - throw bad_query(error()); - } - - return result; - } - - result_c query(const std::string& str) - { - return query(str.data(), str.size()); - } - - result_c query(const char* str) - { - return query(str, strlen(str)); - } -private: - void read_conf_files(); - - drizzle_con_st *b_; -}; - -class query_c -{ -public: - query_c(connection_c& con, const std::string& in = "") : - con_(con), - in_(in) - { - } - - void operator=(const std::string& v) - { - in_ = v; - out_.clear(); - } - - void operator+=(const std::string& v) - { - in_ += v; - } - - query_c& p_name(const std::string& v) - { - std::vector r(2 * v.size() + 2); - r.resize(drizzle_escape_string(&r.front() + 1, r.size(), v.data(), v.size()) + 2); - r.front() = '`'; - r.back() = '`'; - p_raw(&r.front(), r.size()); - return *this; - } - - query_c& p_raw(const char* v, size_t sz) - { - size_t i = in_.find('?'); - assert(i != std::string::npos); - if (i == std::string::npos) - return *this; - out_.append(in_.substr(0, i)); - in_.erase(0, i + 1); - out_.append(v, sz); - return *this; - } - - query_c& p_raw(const std::string& v) - { - return p_raw(v.data(), v.size()); - } - - query_c& p(const std::string& v) - { - std::vector r(2 * v.size() + 2); - r.resize(drizzle_escape_string(&r.front() + 1, r.size(), v.data(), v.size()) + 2); - r.front() = '\''; - r.back() = '\''; - p_raw(&r.front(), r.size()); - return *this; - } - - query_c& p(long long v) - { - std::stringstream ss; - ss << v; - p_raw(ss.str()); - return *this; - } - - drizzle_return_t execute(result_c& result) - { - return con_.query(result, read()); - } - - result_c execute() - { - return con_.query(read()); - } - - std::string read() const - { - return out_ + in_; - } -private: - connection_c& con_; - std::string in_; - std::string out_; -}; - -template -const char* get_conf(const T& c, const std::string& v) -{ - typename T::const_iterator i = c.find(v); - return i == c.end() ? NULL : i->second.c_str(); -} - -void connection_c::read_conf_files() -{ - using namespace std; - - vector conf_files; -#ifdef WIN32 - { - boost::array d; - GetWindowsDirectoryA(d.data(), d.size()); - conf_files.push_back(string(d.data()) + "/my.cnf"); - conf_files.push_back(string(d.data()) + "/drizzle.cnf"); - conf_files.push_back(string(d.data()) + "/drizzle.conf"); - } -#else - conf_files.push_back("/etc/mysql/my.cnf"); - conf_files.push_back("/etc/drizzle/drizzle.cnf"); - conf_files.push_back("/etc/drizzle/drizzle.conf"); -#endif - if (const char* d = getenv("HOME")) - { - conf_files.push_back(string(d) + "/.my.cnf"); - conf_files.push_back(string(d) + "/.drizzle.conf"); - } - - map conf; - BOOST_FOREACH(string& it, conf_files) - { - ifstream is(it.c_str()); - bool client_section = false; - for (string s; getline(is, s); ) - { - size_t i = s.find('#'); - if (i != string::npos) - s.erase(i); - boost::trim(s); - if (boost::starts_with(s, "[")) - { - client_section = s == "[client]"; - continue; - } - else if (!client_section) - continue; - i = s.find('='); - if (i != string::npos) - conf[boost::trim_copy(s.substr(0, i))] = boost::trim_copy(s.substr(i + 1)); - } - } - if (conf.count("host") || conf.count("port")) - set_tcp(get_conf(conf, "host"), atoi(get_conf(conf, "port"))); - if (conf.count("user") || conf.count("password")) - set_auth(get_conf(conf, "user"), get_conf(conf, "password")); -} - -} diff --git a/utils/mysqlcl_idb/libdrizzle-2.0/limits.h b/utils/mysqlcl_idb/libdrizzle-2.0/limits.h deleted file mode 100644 index 2cfdcd10b..000000000 --- a/utils/mysqlcl_idb/libdrizzle-2.0/limits.h +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Drizzle Client & Protocol Library - * - * Copyright (C) 2011 Brian Aker (brian@tangent.org) - * Copyright (C) 2008 Eric Day (eday@oddments.org) - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * - * * The names of its contributors may not be used to endorse or - * promote products derived from this software without specific prior - * written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -#pragma once - -#define DRIZZLE_MAX_BUFFER_SIZE 32768 -#define DRIZZLE_MAX_CATALOG_SIZE 128 -#define DRIZZLE_MAX_COLUMN_NAME_SIZE 2048 -#define DRIZZLE_MAX_DB_SIZE DRIZZLE_MAX_SCHEMA_SIZE -#define DRIZZLE_MAX_DEFAULT_VALUE_SIZE 2048 -#define DRIZZLE_MAX_ERROR_SIZE 2048 -#define DRIZZLE_MAX_INFO_SIZE 2048 -#define DRIZZLE_MAX_PACKET_SIZE UINT32_MAX -#define DRIZZLE_MAX_PASSWORD_SIZE 32 -#define DRIZZLE_MAX_SCHEMA_SIZE 64 -#define DRIZZLE_MAX_SCRAMBLE_SIZE 20 -#define DRIZZLE_MAX_SERVER_EXTRA_SIZE 32 -#define DRIZZLE_MAX_SERVER_VERSION_SIZE 32 -#define DRIZZLE_MAX_SQLSTATE_SIZE 5 -#define DRIZZLE_MAX_TABLE_SIZE 128 -#define DRIZZLE_MAX_USER_SIZE 64 - diff --git a/utils/mysqlcl_idb/libdrizzle-2.0/pack.h b/utils/mysqlcl_idb/libdrizzle-2.0/pack.h deleted file mode 100644 index 90dfe65f2..000000000 --- a/utils/mysqlcl_idb/libdrizzle-2.0/pack.h +++ /dev/null @@ -1,93 +0,0 @@ -/* - * Drizzle Client & Protocol Library - * - * Copyright (C) 2008 Eric Day (eday@oddments.org) - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * - * * The names of its contributors may not be used to endorse or - * promote products derived from this software without specific prior - * written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -#pragma once - -/** - * @file - * @brief Packing Declarations - */ - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * @addtogroup drizzle_pack Packing Declarations - * - * These functions are used internally to pack various parts of the protocol. - * Not all functions are defined in pack.c, they are in the most appropriate - * source file (for example, handshake.c for drizzle_pack_client_handshake). - * @{ - */ - -/** - * Pack length-encoded number. - */ -DRIZZLE_API -uint8_t *drizzle_pack_length(uint64_t number, uint8_t *ptr); - -/** - * Unpack length-encoded number. - */ -DRIZZLE_API -uint64_t drizzle_unpack_length(drizzle_con_st *con, drizzle_return_t *ret_ptr); - -/** - * Pack length-encoded string. - */ -DRIZZLE_API -uint8_t *drizzle_pack_string(char *string, uint8_t *ptr); - -/** - * Unpack length-encoded string. - */ -DRIZZLE_API -drizzle_return_t drizzle_unpack_string(drizzle_con_st *con, char *buffer, - uint64_t max_size); - -/** - * Pack user, scramble, and db. - */ -DRIZZLE_API -uint8_t *drizzle_pack_auth(drizzle_con_st *con, uint8_t *ptr, - drizzle_return_t *ret_ptr); - -/** @} */ - -#ifdef __cplusplus -} -#endif diff --git a/utils/mysqlcl_idb/libdrizzle-2.0/query.h b/utils/mysqlcl_idb/libdrizzle-2.0/query.h deleted file mode 100644 index 564a2b1c1..000000000 --- a/utils/mysqlcl_idb/libdrizzle-2.0/query.h +++ /dev/null @@ -1,239 +0,0 @@ -/* - * Drizzle Client & Protocol Library - * - * Copyright (C) 2008 Eric Day (eday@oddments.org) - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * - * * The names of its contributors may not be used to endorse or - * promote products derived from this software without specific prior - * written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -#pragma once - -/** - * @file - * @brief Query Declarations - */ - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * @addtogroup drizzle_query Query Declarations - * - * @ingroup drizzle_client_interface - * These functions are used to issue queries on a connection. Single queries are - * made using the drizzle_query function, or you can queue multiple queries and - * run them concurrently using the other query functions. - * @{ - */ - -/** - * Send query to server. A \ref drizzle_result_st will be created for the - * results. - * - * @param[in] con connection to use to send the query. - * @param[in,out] result pointer to an unused structure that will be used for - * the results, or NULL to allocate a new structure. - * @param[in] query query string to send. - * @param[in] size length of the query string in bytes. - * @param[out] ret_ptr pointer to the result code. - * @return result, a pointer to the newly allocated result structure, or NULL - * if the allocation failed. - */ -DRIZZLE_API -drizzle_result_st *drizzle_query(drizzle_con_st *con, drizzle_result_st *result, - const char *query, size_t size, - drizzle_return_t *ret_ptr); - -/** - * Send query to server, using strlen to get the size of query buffer.. - */ -DRIZZLE_API -drizzle_result_st *drizzle_query_str(drizzle_con_st *con, - drizzle_result_st *result, - const char *query, - drizzle_return_t *ret_ptr); - -/** - * Send query incrementally. - */ -DRIZZLE_API -drizzle_result_st *drizzle_query_inc(drizzle_con_st *con, - drizzle_result_st *result, - const char *query, size_t size, - size_t total, drizzle_return_t *ret_ptr); - -/** - * Add a query to be run concurrently. - */ -DRIZZLE_API -drizzle_query_st *drizzle_query_add(drizzle_st *drizzle, - drizzle_query_st *query, - drizzle_con_st *con, - drizzle_result_st *result, - const char *query_string, size_t size, - drizzle_query_options_t options, - void *context); - -/** - * Initialize a query structure. - */ -DRIZZLE_API -drizzle_query_st *drizzle_query_create(drizzle_st *drizzle, - drizzle_query_st *query); - -/** - * Free a query structure. - */ -DRIZZLE_API -void drizzle_query_free(drizzle_query_st *query); - -/** - * Free a query structure. - */ -DRIZZLE_API -void drizzle_query_free_all(drizzle_st *drizzle); - -/** - * Get connection struct for a query. - */ -DRIZZLE_API -drizzle_con_st *drizzle_query_con(drizzle_query_st *query); - -/** - * Set connection struct for a query. - */ -DRIZZLE_API -void drizzle_query_set_con(drizzle_query_st *query, drizzle_con_st *con); - -/** - * Get result struct for a query. - */ -DRIZZLE_API -drizzle_result_st *drizzle_query_result(drizzle_query_st *query); - -/** - * Set result struct for a query. - */ -DRIZZLE_API -void drizzle_query_set_result(drizzle_query_st *query, - drizzle_result_st *result); - -/** - * Get query string for a query. - */ -DRIZZLE_API -char *drizzle_query_string(drizzle_query_st *query, size_t *size); - -/** - * Set query string for a query. - */ -DRIZZLE_API -void drizzle_query_set_string(drizzle_query_st *query, const char *string, - size_t size); - -/** - * Get options for a query. - */ -DRIZZLE_API -int drizzle_query_options(drizzle_query_st *); - -/** - * Set options for a query. - */ -DRIZZLE_API -void drizzle_query_set_options(drizzle_query_st *, int); - -/** - * Add options for a query. - */ -DRIZZLE_API -void drizzle_query_add_options(drizzle_query_st *, int); - -/** - * Remove options for a query. - */ -DRIZZLE_API -void drizzle_query_remove_options(drizzle_query_st *, int); - -/** - * Get application context for a query. - */ -DRIZZLE_API -void *drizzle_query_context(drizzle_query_st *query); - -/** - * Set application context for a query. - */ -DRIZZLE_API -void drizzle_query_set_context(drizzle_query_st *query, void *context); - -/** - * Set callback function when the context pointer should be freed. - */ -DRIZZLE_API -void drizzle_query_set_context_free_fn(drizzle_query_st *query, - drizzle_query_context_free_fn *function); - -/** - * Run queries concurrently, returning when one is complete. - */ -DRIZZLE_API -drizzle_query_st *drizzle_query_run(drizzle_st *drizzle, - drizzle_return_t *ret_ptr); - -/** - * Run queries until they are all complete. Returns \ref DRIZZLE_RETURN_OK if - * all queries complete, even if some return errors. This returns immediately - * if some other error occurs, leaving some queries unprocessed. You must call - * drizzle_result_error_code() to check if each query succeeded. - */ -DRIZZLE_API -drizzle_return_t drizzle_query_run_all(drizzle_st *drizzle); - -/* - * Escape a string or encode a string in hexadecimal. The return value is the - * size of the output string in to. - */ -DRIZZLE_API -ssize_t drizzle_escape_string(char *to, size_t max_to_size, const char *from, size_t from_size); - -DRIZZLE_API -size_t drizzle_hex_string(char *to, const char *from, size_t from_size); - -DRIZZLE_API -void drizzle_mysql_password_hash(char *to, const char *from, size_t from_size); - -/** @} */ - -#ifdef __cplusplus -} -#endif diff --git a/utils/mysqlcl_idb/libdrizzle-2.0/result.h b/utils/mysqlcl_idb/libdrizzle-2.0/result.h deleted file mode 100644 index 5406d35bc..000000000 --- a/utils/mysqlcl_idb/libdrizzle-2.0/result.h +++ /dev/null @@ -1,155 +0,0 @@ -/* - * Drizzle Client & Protocol Library - * - * Copyright (C) 2008 Eric Day (eday@oddments.org) - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * - * * The names of its contributors may not be used to endorse or - * promote products derived from this software without specific prior - * written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -#pragma once - -/** - * @file - * @brief Result Declarations - */ - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * @addtogroup drizzle_result Result Declarations - * @ingroup drizzle_client_interface - * @ingroup drizzle_server_interface - * - * These are core result functions used by both clients and servers. - * @{ - */ - -/** - * Initialize a result structure. - */ -DRIZZLE_API -drizzle_result_st *drizzle_result_create(drizzle_con_st *con); - -drizzle_result_st *drizzle_result_create_with(drizzle_con_st *con, - drizzle_result_st *result); - -/** - * Clone a connection structure. - */ -DRIZZLE_API - drizzle_result_st *drizzle_result_clone(drizzle_con_st *con, - drizzle_result_st *source); - -/** - * Free a result structure. - */ -DRIZZLE_API -void drizzle_result_free(drizzle_result_st *result); - -/** - * Free all result structures. - */ -DRIZZLE_API -void drizzle_result_free_all(drizzle_con_st *con); - -/** - * Get the drizzle_con_st struct that the result belongs to. - */ -DRIZZLE_API -drizzle_con_st *drizzle_result_drizzle_con(drizzle_result_st *result); - -/** - * Get EOF flag for a result. - */ -DRIZZLE_API -bool drizzle_result_eof(drizzle_result_st *result); - -/** - * Get information string for a result. - */ -DRIZZLE_API -const char *drizzle_result_info(drizzle_result_st *result); - -/** - * Get error string for a result. - */ -DRIZZLE_API -const char *drizzle_result_error(drizzle_result_st *result); - -/** - * Get server defined error code for a result. - */ -DRIZZLE_API -uint16_t drizzle_result_error_code(drizzle_result_st *result); - -/** - * Get SQL state code for a result. - */ -DRIZZLE_API -const char *drizzle_result_sqlstate(drizzle_result_st *result); - -/** - * Get the number of warnings encounted during a command. - */ -DRIZZLE_API -uint16_t drizzle_result_warning_count(drizzle_result_st *result); - -/** - * Get inet ID of the last command, if any. - */ -DRIZZLE_API -uint64_t drizzle_result_insert_id(drizzle_result_st *result); - -/** - * Get the number of affected rows during the command. - */ -DRIZZLE_API -uint64_t drizzle_result_affected_rows(drizzle_result_st *result); - -/** - * Get the number of columns in a result set. - */ -DRIZZLE_API -uint16_t drizzle_result_column_count(drizzle_result_st *result); - -/** - * Get the number of rows returned for the command. - */ -DRIZZLE_API -uint64_t drizzle_result_row_count(drizzle_result_st *result); - -/** @} */ - -#ifdef __cplusplus -} -#endif diff --git a/utils/mysqlcl_idb/libdrizzle-2.0/result_client.h b/utils/mysqlcl_idb/libdrizzle-2.0/result_client.h deleted file mode 100644 index c083d8956..000000000 --- a/utils/mysqlcl_idb/libdrizzle-2.0/result_client.h +++ /dev/null @@ -1,80 +0,0 @@ -/* - * Drizzle Client & Protocol Library - * - * Copyright (C) 2008 Eric Day (eday@oddments.org) - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * - * * The names of its contributors may not be used to endorse or - * promote products derived from this software without specific prior - * written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -#pragma once - -/** - * @file - * @brief Result Declarations for Clients - */ - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * @addtogroup drizzle_result_client Result Declarations for Clients - * @ingroup drizzle_client_interface - * - * These functions read or buffer the result for a client command. - * @{ - */ - -/** - * Read result packet. - */ -DRIZZLE_API -drizzle_result_st *drizzle_result_read(drizzle_con_st *con, - drizzle_result_st *result, - drizzle_return_t *ret_ptr); - -/** - * Buffer all data for a result. - */ -DRIZZLE_API -drizzle_return_t drizzle_result_buffer(drizzle_result_st *result); - -/** - * Get result row packet size. - */ -DRIZZLE_API -size_t drizzle_result_row_size(drizzle_result_st *result); - -/** @} */ - -#ifdef __cplusplus -} -#endif diff --git a/utils/mysqlcl_idb/libdrizzle-2.0/result_server.h b/utils/mysqlcl_idb/libdrizzle-2.0/result_server.h deleted file mode 100644 index 3c589fef8..000000000 --- a/utils/mysqlcl_idb/libdrizzle-2.0/result_server.h +++ /dev/null @@ -1,141 +0,0 @@ -/* - * Drizzle Client & Protocol Library - * - * Copyright (C) 2008 Eric Day (eday@oddments.org) - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * - * * The names of its contributors may not be used to endorse or - * promote products derived from this software without specific prior - * written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -#pragma once - -/** - * @file - * @brief Result Declarations for Servers - */ - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * @addtogroup drizzle_result_server Result Declarations for Servers - * @ingroup drizzle_server_interface - * - * These functions allow you to send result packets over a connection. - * @{ - */ - -/** - * Write result packet. - */ -DRIZZLE_API -drizzle_return_t drizzle_result_write(drizzle_con_st *con, - drizzle_result_st *result, bool flush); - -/** - * Set result row packet size. - */ -DRIZZLE_API -void drizzle_result_set_row_size(drizzle_result_st *result, size_t size); - -/** - * Set result row packet size from field and size arrays. - */ -DRIZZLE_API -void drizzle_result_calc_row_size(drizzle_result_st *result, - const drizzle_field_t *field, - const size_t *size); - -/** - * Set information string for a result. - */ -DRIZZLE_API -void drizzle_result_set_eof(drizzle_result_st *result, bool eof); - -/** - * Set information string for a result. - */ -DRIZZLE_API -void drizzle_result_set_info(drizzle_result_st *result, const char *info); - -/** - * Set error string for a result. - */ -DRIZZLE_API -void drizzle_result_set_error(drizzle_result_st *result, const char *error); - -/** - * Set server defined error code for a result. - */ -DRIZZLE_API -void drizzle_result_set_error_code(drizzle_result_st *result, - uint16_t error_code); - -/** - * Set SQL state code for a result. - */ -DRIZZLE_API -void drizzle_result_set_sqlstate(drizzle_result_st *result, - const char *sqlstate); - -/** - * Set the number of warnings encounted during a command. - */ -DRIZZLE_API -void drizzle_result_set_warning_count(drizzle_result_st *result, - uint16_t warning_count); - -/** - * Set inet ID of the last command, if any. - */ -DRIZZLE_API -void drizzle_result_set_insert_id(drizzle_result_st *result, - uint64_t insert_id); - -/** - * Set the number of affected rows during the command. - */ -DRIZZLE_API -void drizzle_result_set_affected_rows(drizzle_result_st *result, - uint64_t affected_rows); - -/** - * Set the number of fields in a result set. - */ -DRIZZLE_API -void drizzle_result_set_column_count(drizzle_result_st *result, - uint16_t column_count); - -/** @} */ - -#ifdef __cplusplus -} -#endif diff --git a/utils/mysqlcl_idb/libdrizzle-2.0/return.h b/utils/mysqlcl_idb/libdrizzle-2.0/return.h deleted file mode 100644 index ab1d4f275..000000000 --- a/utils/mysqlcl_idb/libdrizzle-2.0/return.h +++ /dev/null @@ -1,78 +0,0 @@ -/* - * Drizzle Client & Protocol Library - * - * Copyright (C) 2011 Brian Aker (brian@tangent.org) - * Copyright (C) 2008 Eric Day (eday@oddments.org) - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * - * * The names of its contributors may not be used to endorse or - * promote products derived from this software without specific prior - * written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -#pragma once - -/** - * Return codes. - */ -enum drizzle_return_t -{ - DRIZZLE_RETURN_OK, - DRIZZLE_RETURN_IO_WAIT, - DRIZZLE_RETURN_PAUSE, - DRIZZLE_RETURN_ROW_BREAK, - DRIZZLE_RETURN_MEMORY, - DRIZZLE_RETURN_ERRNO, - DRIZZLE_RETURN_INTERNAL_ERROR, - DRIZZLE_RETURN_GETADDRINFO, - DRIZZLE_RETURN_NOT_READY, - DRIZZLE_RETURN_BAD_PACKET_NUMBER, - DRIZZLE_RETURN_BAD_HANDSHAKE_PACKET, - DRIZZLE_RETURN_BAD_PACKET, - DRIZZLE_RETURN_PROTOCOL_NOT_SUPPORTED, - DRIZZLE_RETURN_UNEXPECTED_DATA, - DRIZZLE_RETURN_NO_SCRAMBLE, - DRIZZLE_RETURN_AUTH_FAILED, - DRIZZLE_RETURN_NULL_SIZE, - DRIZZLE_RETURN_ERROR_CODE, - DRIZZLE_RETURN_TOO_MANY_COLUMNS, - DRIZZLE_RETURN_ROW_END, - DRIZZLE_RETURN_LOST_CONNECTION, - DRIZZLE_RETURN_COULD_NOT_CONNECT, - DRIZZLE_RETURN_NO_ACTIVE_CONNECTIONS, - DRIZZLE_RETURN_HANDSHAKE_FAILED, - DRIZZLE_RETURN_TIMEOUT, - DRIZZLE_RETURN_INVALID_ARGUMENT, - DRIZZLE_RETURN_MAX /* Always add new codes to the end before this one. */ -}; - -#ifndef __cplusplus -typedef enum drizzle_return_t drizzle_return_t -#endif - - diff --git a/utils/mysqlcl_idb/libdrizzle-2.0/row_client.h b/utils/mysqlcl_idb/libdrizzle-2.0/row_client.h deleted file mode 100644 index 9a5af8f97..000000000 --- a/utils/mysqlcl_idb/libdrizzle-2.0/row_client.h +++ /dev/null @@ -1,130 +0,0 @@ -/* - * Drizzle Client & Protocol Library - * - * Copyright (C) 2008 Eric Day (eday@oddments.org) - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * - * * The names of its contributors may not be used to endorse or - * promote products derived from this software without specific prior - * written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -#pragma once - -/** - * @file - * @brief Row Declarations for Clients - */ - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * @addtogroup drizzle_row_client Row Declarations for Clients - * @ingroup drizzle_client_interface - * - * These functions allow you to access rows in a result set. If the result is - * unbuffered, you can read and buffer rows one at a time. If the rows are - * buffered in the result, the drizzle_row_next() and related functions can be - * used. - * @{ - */ - -/** - * Get next row number for unbuffered results. Use the drizzle_field* functions - * to read individual fields after this function succeeds. - * - * @param[in,out] result pointer to the structure to read from. - * @param[out] ret_ptr Standard libdrizzle return value. May be set to - * DRIZZLE_RESULT_ERROR_CODE if the server return an error, such as a - * deadlock. - * @return the row id if there is a valid row, or 0 if there are no more rows or an error. - */ -DRIZZLE_API -uint64_t drizzle_row_read(drizzle_result_st *result, drizzle_return_t *ret_ptr); - -/** - * Read and buffer one row. The returned row must be freed by the caller with - * drizzle_row_free(). - * - * @param[in,out] result pointer to the result structure to read from. - * @param[out] ret_pointer Standard drizzle return value. - * @return the row that was read, or NULL if there are no more rows. - */ -DRIZZLE_API -drizzle_row_t drizzle_row_buffer(drizzle_result_st *result, - drizzle_return_t *ret_ptr); - -/** - * Free a row that was buffered with drizzle_row_buffer(). - */ -DRIZZLE_API -void drizzle_row_free(drizzle_result_st *result, drizzle_row_t row); - -/** - * Get an array of all field sizes for buffered rows. - */ -DRIZZLE_API -size_t *drizzle_row_field_sizes(drizzle_result_st *result); - -/** - * Get next buffered row from a fully buffered result. - */ -DRIZZLE_API -drizzle_row_t drizzle_row_next(drizzle_result_st *result); - -/** - * Get previous buffered row from a fully buffered result. - */ -DRIZZLE_API -drizzle_row_t drizzle_row_prev(drizzle_result_st *result); - -/** - * Seek to the given buffered row in a fully buffered result. - */ -DRIZZLE_API -void drizzle_row_seek(drizzle_result_st *result, uint64_t row); - -/** - * Get the given buffered row from a fully buffered result. - */ -DRIZZLE_API -drizzle_row_t drizzle_row_index(drizzle_result_st *result, uint64_t row); - -/** - * Get current row number. - */ -DRIZZLE_API -uint64_t drizzle_row_current(drizzle_result_st *result); - -/** @} */ - -#ifdef __cplusplus -} -#endif diff --git a/utils/mysqlcl_idb/libdrizzle-2.0/row_server.h b/utils/mysqlcl_idb/libdrizzle-2.0/row_server.h deleted file mode 100644 index 50d3da84c..000000000 --- a/utils/mysqlcl_idb/libdrizzle-2.0/row_server.h +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Drizzle Client & Protocol Library - * - * Copyright (C) 2008 Eric Day (eday@oddments.org) - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * - * * The names of its contributors may not be used to endorse or - * promote products derived from this software without specific prior - * written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -#pragma once - -/** - * @file - * @brief Row Declarations for Servers - */ - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * @addtogroup drizzle_row_server Row Declarations for Servers - * @ingroup drizzle_server_interface - * - * These functions allow you to send row information over a connection. - * @{ - */ - -/** - * Write next row. - */ -DRIZZLE_API -drizzle_return_t drizzle_row_write(drizzle_result_st *result); - -/** @} */ - -#ifdef __cplusplus -} -#endif diff --git a/utils/mysqlcl_idb/libdrizzle-2.0/sha1.h b/utils/mysqlcl_idb/libdrizzle-2.0/sha1.h deleted file mode 100644 index 324c9c570..000000000 --- a/utils/mysqlcl_idb/libdrizzle-2.0/sha1.h +++ /dev/null @@ -1,44 +0,0 @@ -#pragma once - -/** - * @file - * @brief SHA1 Declarations - */ - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * @addtogroup sha1 SHA-1 in C - * - * Copyright (C) 2010 nobody (this is public domain) - * - * This file is based on public domain code. - * Initial source code is in the public domain, - * so clarified by Steve Reid - * - * @{ - */ - -#define SHA1_BLOCK_LENGTH 64 -#define SHA1_DIGEST_LENGTH 20 -#define SHA1_DIGEST_STRING_LENGTH (SHA1_DIGEST_LENGTH * 2 + 1) - -typedef struct { - uint32_t state[5]; - uint64_t count; - uint8_t buffer[SHA1_BLOCK_LENGTH]; -} SHA1_CTX; - -void SHA1Init(SHA1_CTX *); -void SHA1Pad(SHA1_CTX *); -void SHA1Transform(uint32_t [5], const uint8_t [SHA1_BLOCK_LENGTH]); -void SHA1Update(SHA1_CTX *, const uint8_t *, size_t); -void SHA1Final(uint8_t [SHA1_DIGEST_LENGTH], SHA1_CTX *); - -/** @} */ - -#ifdef __cplusplus -} -#endif diff --git a/utils/mysqlcl_idb/libdrizzle-2.0/state.h b/utils/mysqlcl_idb/libdrizzle-2.0/state.h deleted file mode 100644 index e38315a0c..000000000 --- a/utils/mysqlcl_idb/libdrizzle-2.0/state.h +++ /dev/null @@ -1,108 +0,0 @@ -/* - * Drizzle Client & Protocol Library - * - * Copyright (C) 2008 Eric Day (eday@oddments.org) - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * - * * The names of its contributors may not be used to endorse or - * promote products derived from this software without specific prior - * written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -#pragma once - -/** - * @file - * @brief State Machine Declarations - */ - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * @addtogroup drizzle_state State Machine Declarations - * - * These functions are used in the protocol parsing state machine. Not all - * functions are defined in state.c, they are in the most appropriate source - * file (for example, handshake.c for drizzle_state_handshake_server_read). - * @{ - */ - -/** - * Main state loop for connections. - * - * @param[in] con Connection structure previously initialized with - * drizzle_con_create(), drizzle_con_clone(), or related functions. - * @return Standard drizzle return value. - */ -drizzle_return_t drizzle_state_loop(drizzle_con_st *con); - -/* Functions in state.c */ -drizzle_return_t drizzle_state_packet_read(drizzle_con_st *con); - -/* Functions in conn.c */ -drizzle_return_t drizzle_state_addrinfo(drizzle_con_st *con); -drizzle_return_t drizzle_state_connect(drizzle_con_st *con); -drizzle_return_t drizzle_state_connecting(drizzle_con_st *con); -drizzle_return_t drizzle_state_read(drizzle_con_st *con); -drizzle_return_t drizzle_state_write(drizzle_con_st *con); -drizzle_return_t drizzle_state_listen(drizzle_con_st *con); - -/* Functions in handshake.c */ -drizzle_return_t drizzle_state_handshake_server_read(drizzle_con_st *con); -drizzle_return_t drizzle_state_handshake_server_write(drizzle_con_st *con); -drizzle_return_t drizzle_state_handshake_client_read(drizzle_con_st *con); -drizzle_return_t drizzle_state_handshake_client_write(drizzle_con_st *con); -drizzle_return_t drizzle_state_handshake_result_read(drizzle_con_st *con); - -/* Functions in command.c */ -drizzle_return_t drizzle_state_command_read(drizzle_con_st *con); -drizzle_return_t drizzle_state_command_write(drizzle_con_st *con); - -/* Functions in result.c */ -drizzle_return_t drizzle_state_result_read(drizzle_con_st *con); -drizzle_return_t drizzle_state_result_write(drizzle_con_st *con); - -/* Functions in column.c */ -drizzle_return_t drizzle_state_column_read(drizzle_con_st *con); -drizzle_return_t drizzle_state_column_write(drizzle_con_st *con); - -/* Functions in row.c */ -drizzle_return_t drizzle_state_row_read(drizzle_con_st *con); -drizzle_return_t drizzle_state_row_write(drizzle_con_st *con); - -/* Functions in field.c */ -drizzle_return_t drizzle_state_field_read(drizzle_con_st *con); -drizzle_return_t drizzle_state_field_write(drizzle_con_st *con); - -/** @} */ - -#ifdef __cplusplus -} -#endif diff --git a/utils/mysqlcl_idb/libdrizzle-2.0/structs.h b/utils/mysqlcl_idb/libdrizzle-2.0/structs.h deleted file mode 100644 index ba7b7767b..000000000 --- a/utils/mysqlcl_idb/libdrizzle-2.0/structs.h +++ /dev/null @@ -1,403 +0,0 @@ -/* - * Drizzle Client & Protocol Library - * - * Copyright (C) 2008 Eric Day (eday@oddments.org) - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * - * * The names of its contributors may not be used to endorse or - * promote products derived from this software without specific prior - * written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -#pragma once - -/** - * @file - * @brief Struct Definitions - */ - -#include - -#ifndef NI_MAXHOST -# define NI_MAXHOST 1025 -#endif - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef __cplusplus -struct drizzle_st; -struct drizzle_con_tcp_st; -struct drizzle_con_uds_st; -struct drizzle_con_st; -struct drizzle_query_st; -struct drizzle_result_st; -struct drizzle_column_st; -#else - - -/** - * @ingroup drizzle - */ -class drizzle_st -{ -public: - uint16_t error_code; - struct options_t { - bool is_allocated; - bool is_non_blocking; - bool is_free_objects; - bool is_assert_dangling; - - options_t() : - is_allocated(false), - is_non_blocking(false), - is_free_objects(false), - is_assert_dangling(false) - { } - } options; - drizzle_verbose_t verbose; - uint32_t con_count; - uint32_t pfds_size; - uint32_t query_count; - uint32_t query_new; - uint32_t query_running; - int last_errno; - int timeout; - drizzle_con_st *con_list; - void *context; - drizzle_context_free_fn *context_free_fn; - drizzle_event_watch_fn *event_watch_fn; - void *event_watch_context; - drizzle_log_fn *log_fn; - void *log_context; - struct pollfd *pfds; - drizzle_query_st *query_list; - char sqlstate[DRIZZLE_MAX_SQLSTATE_SIZE + 1]; - char last_error[DRIZZLE_MAX_ERROR_SIZE]; - - drizzle_st() : - error_code(0), - options(), - verbose(DRIZZLE_VERBOSE_ERROR), - con_count(0), - pfds_size(0), - query_count(0), - query_new(0), - query_running(0), - last_errno(0), - timeout(-1), - con_list(NULL), - context(NULL), - context_free_fn(NULL), - event_watch_fn(NULL), - event_watch_context(NULL), - log_fn(NULL), - log_context(NULL), - pfds(NULL), - query_list(NULL) - { } -}; - -/** - * @ingroup drizzle_con - */ -class drizzle_con_tcp_st -{ -public: - in_port_t port; - struct addrinfo *addrinfo; - char *host; - char host_buffer[NI_MAXHOST]; -}; - -/** - * @ingroup drizzle_con - */ -class drizzle_con_uds_st -{ -public: - struct addrinfo addrinfo; - struct sockaddr_un sockaddr; -}; - -/** - * @ingroup drizzle_con - */ -class drizzle_con_st -{ -public: - uint8_t packet_number; - uint8_t protocol_version; - uint8_t state_current; - short events; - short revents; - int capabilities; - drizzle_charset_t charset; - drizzle_command_t command; - struct option_t { - bool is_allocated; - - option_t() : - is_allocated(false) - { } - } _options; - int options; - drizzle_con_socket_t socket_type; - drizzle_con_status_t status; - uint32_t max_packet_size; - uint32_t result_count; - uint32_t thread_id; - int backlog; - int fd; - size_t buffer_size; - size_t command_offset; - size_t command_size; - size_t command_total; - size_t packet_size; - struct addrinfo *addrinfo_next; - uint8_t *buffer_ptr; - uint8_t *command_buffer; - uint8_t *command_data; - void *context; - drizzle_con_context_free_fn *context_free_fn; - drizzle_st *drizzle; - drizzle_con_st *next; - drizzle_con_st *prev; - drizzle_query_st *query; - drizzle_result_st *result; - drizzle_result_st *result_list; - uint8_t *scramble; - union - { - drizzle_con_tcp_st tcp; - drizzle_con_uds_st uds; - } socket; - uint8_t buffer[DRIZZLE_MAX_BUFFER_SIZE]; - char schema[DRIZZLE_MAX_DB_SIZE]; - char password[DRIZZLE_MAX_PASSWORD_SIZE]; - uint8_t scramble_buffer[DRIZZLE_MAX_SCRAMBLE_SIZE]; - char server_version[DRIZZLE_MAX_SERVER_VERSION_SIZE]; - char server_extra[DRIZZLE_MAX_SERVER_EXTRA_SIZE]; - drizzle_state_fn *state_stack[DRIZZLE_STATE_STACK_SIZE]; - char user[DRIZZLE_MAX_USER_SIZE]; - - drizzle_con_st() : - packet_number(0), - protocol_version(0), - state_current(0), - events(0), - revents(0), - capabilities(DRIZZLE_CAPABILITIES_NONE), - options(DRIZZLE_CON_NONE), - max_packet_size(0), - result_count(0), - thread_id(0), - backlog(0), - fd(0), - buffer_size(0), - command_offset(0), - command_size(0), - command_total(0), - packet_size(0), - addrinfo_next(NULL), - buffer_ptr(NULL), - command_buffer(NULL), - command_data(NULL), - context(NULL), - context_free_fn(NULL), - drizzle(NULL), - next(NULL), - prev(NULL), - query(NULL), - result(NULL), - result_list(NULL), - scramble(NULL) - { } -}; - -/** - * @ingroup drizzle_query - */ -class drizzle_query_st -{ -private: -public: - drizzle_st *drizzle; - drizzle_query_st *next; - drizzle_query_st *prev; - struct option_t { - bool is_allocated; - - option_t() : - is_allocated(false) - { } - } options; - drizzle_query_state_t state; - drizzle_con_st *con; - drizzle_result_st *result; - const char *string; - size_t size; - void *context; - drizzle_query_context_free_fn *context_free_fn; - - drizzle_query_st() : - drizzle(NULL), - next(NULL), - prev(NULL), - con(NULL), - result(NULL), - string(NULL), - size(0), - context(NULL), - context_free_fn(NULL) - { } -}; - -/** - * @ingroup drizzle_result - */ -class drizzle_result_st -{ -public: - drizzle_con_st *con; - drizzle_result_st *next; - drizzle_result_st *prev; - struct option_t { - bool is_allocated; - - option_t() : - is_allocated(false) - { } - } _options; - int options; - - char info[DRIZZLE_MAX_INFO_SIZE]; - uint16_t error_code; - char sqlstate[DRIZZLE_MAX_SQLSTATE_SIZE + 1]; - uint64_t insert_id; - uint16_t warning_count; - uint64_t affected_rows; - - uint16_t column_count; - uint16_t column_current; - drizzle_column_st *column_list; - drizzle_column_st *column; - drizzle_column_st *column_buffer; - - uint64_t row_count; - uint64_t row_current; - - uint16_t field_current; - size_t field_total; - size_t field_offset; - size_t field_size; - drizzle_field_t field; - drizzle_field_t field_buffer; - - uint64_t row_list_size; - drizzle_row_t row; - drizzle_row_list_t *row_list; - size_t *field_sizes; - drizzle_field_sizes_list_t *field_sizes_list; - - drizzle_result_st() : - con(NULL), - next(NULL), - prev(NULL), - options(DRIZZLE_RESULT_NONE), - error_code(0), - insert_id(0), - warning_count(0), - affected_rows(0), - column_count(0), - column_current(0), - column_list(NULL), - column(NULL), - column_buffer(NULL), - row_count(0), - row_current(0), - field_current(0), - field_total(0), - field_offset(0), - field_size(0), - row_list_size(0), - row_list(NULL), - field_sizes(NULL), - field_sizes_list(NULL) - { } -}; - -/** - * @ingroup drizzle_column - */ -class drizzle_column_st -{ -public: - drizzle_result_st *result; - drizzle_column_st *next; - drizzle_column_st *prev; - struct options_t { - bool is_allocated; - - options_t() : - is_allocated(false) - { } - } options; - char catalog[DRIZZLE_MAX_CATALOG_SIZE]; - char schema[DRIZZLE_MAX_DB_SIZE]; - char table[DRIZZLE_MAX_TABLE_SIZE]; - char orig_table[DRIZZLE_MAX_TABLE_SIZE]; - char name[DRIZZLE_MAX_COLUMN_NAME_SIZE]; - char orig_name[DRIZZLE_MAX_COLUMN_NAME_SIZE]; - drizzle_charset_t charset; - uint32_t size; - size_t max_size; - drizzle_column_type_t type; - int flags; - uint8_t decimals; - uint8_t default_value[DRIZZLE_MAX_DEFAULT_VALUE_SIZE]; - size_t default_value_size; - - drizzle_column_st() : - result(NULL), - next(NULL), - prev(NULL), - size(0), - max_size(0), - flags(DRIZZLE_COLUMN_FLAGS_NONE), - decimals(0), - default_value_size(0) - { } -}; -#endif - -#ifdef __cplusplus -} -#endif diff --git a/utils/mysqlcl_idb/libdrizzle-2.0/verbose.h b/utils/mysqlcl_idb/libdrizzle-2.0/verbose.h deleted file mode 100644 index 5829a058c..000000000 --- a/utils/mysqlcl_idb/libdrizzle-2.0/verbose.h +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Drizzle Client & Protocol Library - * - * Copyright (C) 2011 Brian Aker (brian@tangent.org) - * Copyright (C) 2008 Eric Day (eday@oddments.org) - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * - * * The names of its contributors may not be used to endorse or - * promote products derived from this software without specific prior - * written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -#pragma once - - -/** - * Verbosity levels. - */ -enum drizzle_verbose_t -{ - DRIZZLE_VERBOSE_NEVER, - DRIZZLE_VERBOSE_FATAL, - DRIZZLE_VERBOSE_ERROR, - DRIZZLE_VERBOSE_INFO, - DRIZZLE_VERBOSE_DEBUG, - DRIZZLE_VERBOSE_CRAZY, - DRIZZLE_VERBOSE_MAX -}; - -#ifndef __cplusplus -typedef enum drizzle_verbose_t drizzle_verbose_t; -#endif - diff --git a/utils/mysqlcl_idb/libdrizzle-2.0/visibility.h b/utils/mysqlcl_idb/libdrizzle-2.0/visibility.h deleted file mode 100644 index 493ac2266..000000000 --- a/utils/mysqlcl_idb/libdrizzle-2.0/visibility.h +++ /dev/null @@ -1,78 +0,0 @@ -/* - * Drizzle Client & Protocol Library - * - * Copyright (C) 2008 Eric Day (eday@oddments.org) - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * - * * The names of its contributors may not be used to endorse or - * promote products derived from this software without specific prior - * written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - * - * Implementation drawn from visibility.texi in gnulib. - */ - -#pragma once - -/** - * @file - * @brief Visibility Control Macros - */ - -/** - * - * DRIZZLE_API is used for the public API symbols. It either DLL imports or - * DLL exports (or does nothing for static build). - * - * DRIZZLE_LOCAL is used for non-api symbols. - */ - -#if defined(_WIN32) -# define DRIZZLE_API -# define DRIZZLE_LOCAL -#else -#if defined(BUILDING_LIBDRIZZLE) -# if defined(HAVE_VISIBILITY) -# define DRIZZLE_API __attribute__ ((visibility("default"))) -# define DRIZZLE_LOCAL __attribute__ ((visibility("hidden"))) -# elif defined (__SUNPRO_C) && (__SUNPRO_C >= 0x550) -# define DRIZZLE_API __global -# define DRIZZLE_API __hidden -# elif defined(_MSC_VER) -# define DRIZZLE_API extern __declspec(dllexport) -# define DRIZZLE_LOCAL -# endif /* defined(HAVE_VISIBILITY) */ -#else /* defined(BUILDING_LIBDRIZZLE) */ -# if defined(_MSC_VER) -# define DRIZZLE_API extern __declspec(dllimport) -# define DRIZZLE_LOCAL -# else -# define DRIZZLE_API -# define DRIZZLE_LOCAL -# endif /* defined(_MSC_VER) */ -#endif /* defined(BUILDING_LIBDRIZZLE) */ -#endif /* _WIN32 */ diff --git a/utils/mysqlcl_idb/libmysqlcl_idb.vcxproj b/utils/mysqlcl_idb/libmysqlcl_idb.vcxproj deleted file mode 100644 index 451e94c02..000000000 --- a/utils/mysqlcl_idb/libmysqlcl_idb.vcxproj +++ /dev/null @@ -1,235 +0,0 @@ - - - - - Debug - Win32 - - - Debug - x64 - - - EnterpriseRelease - Win32 - - - EnterpriseRelease - x64 - - - Release - Win32 - - - Release - x64 - - - - {0BBAEACB-3336-4406-ACFB-255669A3B9CF} - libmysqlcl_idb - - - - StaticLibrary - v110 - - - StaticLibrary - v110 - MultiByte - true - - - StaticLibrary - v110 - MultiByte - - - StaticLibrary - v110 - - - StaticLibrary - v110 - MultiByte - true - - - StaticLibrary - v110 - MultiByte - - - - - - - - - - - - - - - - - - - - - - - - - <_ProjectFileVersion>11.0.50727.1 - - - $(SolutionDir)..\..\$(PlatformName)\$(ConfigurationName)\ - $(SolutionDir)..\..\obj\$(ProjectName)\$(PlatformName)\$(ConfigurationName)\ - - - $(SolutionDir)..\..\$(Platform)\$(Configuration)\ - $(SolutionDir)..\..\obj\$(ProjectName)\$(Platform)\$(Configuration)\ - - - $(SolutionDir)..\..\$(PlatformName)\$(ConfigurationName)\ - $(SolutionDir)..\..\obj\$(ProjectName)\$(PlatformName)\$(ConfigurationName)\ - - - $(SolutionDir)..\..\$(Platform)\$(Configuration)\ - $(SolutionDir)..\..\obj\$(ProjectName)\$(Platform)\$(Configuration)\ - - - $(SolutionDir)..\..\$(PlatformName)\$(ConfigurationName)\ - $(SolutionDir)..\..\obj\$(ProjectName)\$(PlatformName)\$(ConfigurationName)\ - - - $(SolutionDir)..\..\$(Platform)\$(Configuration)\ - $(SolutionDir)..\..\obj\$(ProjectName)\$(Platform)\$(Configuration)\ - - - - Disabled - $(SolutionDir)..\utils\mysqlcl_idb;$(SolutionDir)..\utils\configcpp;$(SolutionDir)..\utils\winport;$(SolutionDir)..\..\boost_1_54_0;%(AdditionalIncludeDirectories) - true - EnableFastChecks - MultiThreadedDebugDLL - Level3 - EditAndContinue - - - - - X64 - - - Disabled - $(SolutionDir)..\utils\mysqlcl_idb;$(SolutionDir)..\utils\configcpp;$(SolutionDir)..\utils\winport;$(SolutionDir)..\..\boost_1_54_0;%(AdditionalIncludeDirectories) - true - EnableFastChecks - MultiThreadedDebugDLL - Level3 - ProgramDatabase - - - - - MaxSpeed - true - $(SolutionDir)..\utils\mysqlcl_idb;$(SolutionDir)..\utils\configcpp;$(SolutionDir)..\utils\winport;$(SolutionDir)..\..\boost_1_54_0;%(AdditionalIncludeDirectories) - MultiThreadedDLL - true - Level3 - ProgramDatabase - - - - - X64 - - - MaxSpeed - true - $(SolutionDir)..\utils\mysqlcl_idb;$(SolutionDir)..\utils\configcpp;$(SolutionDir)..\utils\winport;$(SolutionDir)..\..\boost_1_54_0;%(AdditionalIncludeDirectories) - MultiThreadedDLL - true - Level3 - ProgramDatabase - - - - - $(SolutionDir)..\utils\mysqlcl_idb;$(SolutionDir)..\utils\configcpp;$(SolutionDir)..\utils\winport;$(SolutionDir)..\..\boost_1_54_0;%(AdditionalIncludeDirectories) - MultiThreadedDLL - true - - - - - $(SolutionDir)..\utils\mysqlcl_idb;$(SolutionDir)..\utils\configcpp;$(SolutionDir)..\utils\winport;$(SolutionDir)..\..\boost_1_54_0;%(AdditionalIncludeDirectories) - MultiThreadedDLL - true - false - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/utils/mysqlcl_idb/libmysqlcl_idb.vcxproj.filters b/utils/mysqlcl_idb/libmysqlcl_idb.vcxproj.filters deleted file mode 100644 index e22e260ef..000000000 --- a/utils/mysqlcl_idb/libmysqlcl_idb.vcxproj.filters +++ /dev/null @@ -1,171 +0,0 @@ - - - - - {4FC737F1-C7A5-4376-A066-2A32D752A2FF} - cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx - - - {93995380-89BD-4b04-88EB-625FBE52EBFB} - h;hpp;hxx;hm;inl;inc;xsd - - - {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} - rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav - - - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - \ No newline at end of file diff --git a/utils/mysqlcl_idb/mysqlcl_idb.vpj b/utils/mysqlcl_idb/mysqlcl_idb.vpj deleted file mode 100644 index e0db68404..000000000 --- a/utils/mysqlcl_idb/mysqlcl_idb.vpj +++ /dev/null @@ -1,153 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/utils/mysqlcl_idb/pack.cc b/utils/mysqlcl_idb/pack.cc deleted file mode 100644 index 2f56c9b1b..000000000 --- a/utils/mysqlcl_idb/pack.cc +++ /dev/null @@ -1,336 +0,0 @@ -/* - * Drizzle Client & Protocol Library - * - * Copyright (C) 2008 Eric Day (eday@oddments.org) - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * - * * The names of its contributors may not be used to endorse or - * promote products derived from this software without specific prior - * written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -/** - * @file - * @brief Packing definitions - */ - -#include - -/* - * Private declarations - */ - -/** - * @addtogroup drizzle_pack_private Private Packing Functions - * @ingroup drizzle_pack - * @{ - */ - -/** - * Compute hash from password and scramble. - */ -static drizzle_return_t _pack_scramble_hash(drizzle_con_st *con, - uint8_t *buffer); - -/** @} */ - -/* - * Public definitions - */ - -uint8_t *drizzle_pack_length(uint64_t number, uint8_t *ptr) -{ - if (number < 251) - { - ptr[0]= (uint8_t)number; - ptr++; - } - else if (number < 65536) - { - ptr[0]= 252; - ptr++; - drizzle_set_byte2(ptr, number); - ptr+= 2; - } - else if (number < 16777216) - { - ptr[0]= 253; - ptr++; - drizzle_set_byte3(ptr, number); - ptr+= 3; - } - else - { - ptr[0]= 254; - ptr++; - drizzle_set_byte8(ptr, number); - ptr+= 8; - } - - return ptr; -} - -uint64_t drizzle_unpack_length(drizzle_con_st *con, drizzle_return_t *ret_ptr) -{ - uint64_t length; - uint8_t bytes; - - if (con->buffer_ptr[0] < 251) - { - length= (uint64_t)(con->buffer_ptr[0]); - bytes= 1; - } - else if (con->buffer_ptr[0] == 251) - { - con->buffer_ptr++; - con->buffer_size--; - con->packet_size--; - - *ret_ptr= DRIZZLE_RETURN_NULL_SIZE; - return 0; - } - else if (con->buffer_ptr[0] == 252 && con->buffer_size > 2) - { - length= drizzle_get_byte2(con->buffer_ptr + 1); - bytes= 3; - } - else if (con->buffer_ptr[0] == 253 && con->buffer_size > 3) - { - length= drizzle_get_byte3(con->buffer_ptr + 1); - bytes= 4; - } - else if (con->buffer_size > 8) - { - length= drizzle_get_byte8(con->buffer_ptr + 1); - bytes= 9; - } - else - { - *ret_ptr= DRIZZLE_RETURN_IO_WAIT; - return 0; - } - - con->buffer_ptr+= bytes; - con->buffer_size-= bytes; - con->packet_size-= bytes; - - *ret_ptr= DRIZZLE_RETURN_OK; - return length; -} - -uint8_t *drizzle_pack_string(char *string, uint8_t *ptr) -{ - if (string == NULL) - { - return NULL; - } - - uint64_t size= strlen(string); - - ptr= drizzle_pack_length(size, ptr); - if (size > 0) - { - memcpy(ptr, string, (size_t)size); - ptr+= size; - } - - return ptr; -} - -drizzle_return_t drizzle_unpack_string(drizzle_con_st *con, char *buffer, - uint64_t max_length) -{ - drizzle_return_t ret= DRIZZLE_RETURN_OK; - uint64_t length; - - if (con == NULL) - { - return DRIZZLE_RETURN_INVALID_ARGUMENT; - } - - length= drizzle_unpack_length(con, &ret); - if (ret != DRIZZLE_RETURN_OK) - { - if (ret == DRIZZLE_RETURN_NULL_SIZE) - { - drizzle_set_error(con->drizzle, "drizzle_unpack_string", - "unexpected NULL length"); - } - - return ret; - } - - if (length < max_length) - { - if (length > 0) - { - memcpy(buffer, con->buffer_ptr, (size_t)length); - } - - buffer[length]= 0; - } - else - { - memcpy(buffer, con->buffer_ptr, (size_t)(max_length - 1)); - buffer[max_length - 1]= 0; - } - - con->buffer_ptr+= length; - con->buffer_size-= (size_t)length; - con->packet_size-= (size_t)length; - - return DRIZZLE_RETURN_OK; -} - -uint8_t *drizzle_pack_auth(drizzle_con_st *con, uint8_t *ptr, drizzle_return_t *ret_ptr) -{ - if (con == NULL) - { - return NULL; - } - - drizzle_return_t unused; - if (ret_ptr == NULL) - { - ret_ptr= &unused; - } - - if (con->user[0] != 0) - { - memcpy(ptr, con->user, strlen(con->user)); - ptr+= strlen(con->user); - } - - ptr[0]= 0; - ptr++; - - if (con->options & DRIZZLE_CON_RAW_SCRAMBLE && con->scramble != NULL) - { - ptr[0]= DRIZZLE_MAX_SCRAMBLE_SIZE; - ptr++; - - memcpy(ptr, con->scramble, DRIZZLE_MAX_SCRAMBLE_SIZE); - ptr+= DRIZZLE_MAX_SCRAMBLE_SIZE; - } - else if (con->password[0] == 0) - { - ptr[0]= 0; - ptr++; - con->packet_size-= DRIZZLE_MAX_SCRAMBLE_SIZE; - } - else - { - ptr[0]= DRIZZLE_MAX_SCRAMBLE_SIZE; - ptr++; - - if (con->options & DRIZZLE_CON_MYSQL && con->options & DRIZZLE_CON_AUTH_PLUGIN) - { - snprintf((char *)ptr, DRIZZLE_MAX_SCRAMBLE_SIZE, "%s", con->password); - ptr[DRIZZLE_MAX_SCRAMBLE_SIZE-1]= 0; - } - else if (con->options & DRIZZLE_CON_MYSQL) - { - *ret_ptr= _pack_scramble_hash(con, ptr); - if (*ret_ptr != DRIZZLE_RETURN_OK) - { - return ptr; - } - } - else // We assume Drizzle - { - snprintf((char *)ptr, DRIZZLE_MAX_SCRAMBLE_SIZE, "%s", con->password); - ptr[DRIZZLE_MAX_SCRAMBLE_SIZE-1]= 0; - } - - ptr+= DRIZZLE_MAX_SCRAMBLE_SIZE; - } - - if (con->schema[0] != 0) - { - memcpy(ptr, con->schema, strlen(con->schema)); - ptr+= strlen(con->schema); - } - - ptr[0]= 0; - ptr++; - - *ret_ptr= DRIZZLE_RETURN_OK; - - return ptr; -} - -/* - * Private definitions - */ - -static drizzle_return_t _pack_scramble_hash(drizzle_con_st *con, - uint8_t *buffer) -{ - SHA1_CTX ctx; - uint8_t hash_tmp1[SHA1_DIGEST_LENGTH]; - uint8_t hash_tmp2[SHA1_DIGEST_LENGTH]; - - if (SHA1_DIGEST_LENGTH != DRIZZLE_MAX_SCRAMBLE_SIZE) - { - drizzle_set_error(con->drizzle, "_pack_scramble_hash", - "SHA1 hash size mismatch:%u:%u", SHA1_DIGEST_LENGTH, - DRIZZLE_MAX_SCRAMBLE_SIZE); - return DRIZZLE_RETURN_INTERNAL_ERROR; - } - - if (con->scramble == NULL) - { - drizzle_set_error(con->drizzle, "_pack_scramble_hash", - "no scramble buffer"); - return DRIZZLE_RETURN_NO_SCRAMBLE; - } - - /* First hash the password. */ - SHA1Init(&ctx); - SHA1Update(&ctx, (uint8_t *)(con->password), strlen(con->password)); - SHA1Final(hash_tmp1, &ctx); - - /* Second, hash the password hash. */ - SHA1Init(&ctx); - SHA1Update(&ctx, hash_tmp1, SHA1_DIGEST_LENGTH); - SHA1Final(hash_tmp2, &ctx); - - /* Third, hash the scramble and the double password hash. */ - SHA1Init(&ctx); - SHA1Update(&ctx, con->scramble, SHA1_DIGEST_LENGTH); - SHA1Update(&ctx, hash_tmp2, SHA1_DIGEST_LENGTH); - SHA1Final(buffer, &ctx); - - /* Fourth, xor the last hash against the first password hash. */ - for (uint32_t x= 0; x < SHA1_DIGEST_LENGTH; x++) - { - buffer[x]= buffer[x] ^ hash_tmp1[x]; - } - - return DRIZZLE_RETURN_OK; -} diff --git a/utils/mysqlcl_idb/query.cc b/utils/mysqlcl_idb/query.cc deleted file mode 100644 index 3c50ff877..000000000 --- a/utils/mysqlcl_idb/query.cc +++ /dev/null @@ -1,545 +0,0 @@ -/* - * Drizzle Client & Protocol Library - * - * Copyright (C) 2008 Eric Day (eday@oddments.org) - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * - * * The names of its contributors may not be used to endorse or - * promote products derived from this software without specific prior - * written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -/** - * @file - * @brief Query definitions - */ - -#include - -drizzle_result_st *drizzle_query(drizzle_con_st *con, drizzle_result_st *result, - const char *query, size_t size, - drizzle_return_t *ret_ptr) -{ - return drizzle_con_command_write(con, result, DRIZZLE_COMMAND_QUERY, - (uint8_t *)query, size, size, ret_ptr); -} - -drizzle_result_st *drizzle_query_str(drizzle_con_st *con, - drizzle_result_st *result, - const char *query, - drizzle_return_t *ret_ptr) -{ - size_t size= strlen(query); - - return drizzle_con_command_write(con, result, DRIZZLE_COMMAND_QUERY, (uint8_t *)query, size, size, ret_ptr); -} - -drizzle_result_st *drizzle_query_inc(drizzle_con_st *con, - drizzle_result_st *result, - const char *query, size_t size, - size_t total, drizzle_return_t *ret_ptr) -{ - return drizzle_con_command_write(con, result, DRIZZLE_COMMAND_QUERY, (uint8_t *)query, size, total, ret_ptr); -} - -drizzle_query_st *drizzle_query_add(drizzle_st *drizzle, - drizzle_query_st *query, - drizzle_con_st *con, - drizzle_result_st *result, - const char *query_string, size_t size, - drizzle_query_options_t, - void *context) -{ - // @note drizzle_query_st handle the null drizzle case - query= drizzle_query_create(drizzle, query); - if (query == NULL) - { - return NULL; - } - - drizzle_query_set_con(query, con); - drizzle_query_set_result(query, result); - drizzle_query_set_string(query, query_string, size); - drizzle_query_set_context(query, context); - - return query; -} - -drizzle_query_st *drizzle_query_create(drizzle_st *drizzle, drizzle_query_st *query) -{ - if (drizzle == NULL) - { - return NULL; - } - - if (query == NULL) - { - query= new (std::nothrow) drizzle_query_st; - - if (query == NULL) - { - return NULL; - } - query->options.is_allocated= true; - } - else - { - query->prev= NULL; - query->state= DRIZZLE_QUERY_STATE_INIT; - query->con= NULL; - query->result= NULL; - query->string= NULL; - query->size= 0; - query->context= NULL; - query->context_free_fn= NULL; - query->options.is_allocated= false; - } - - query->drizzle= drizzle; - - if (drizzle->query_list) - { - drizzle->query_list->prev= query; - } - query->next= drizzle->query_list; - drizzle->query_list= query; - drizzle->query_count++; - drizzle->query_new++; - - return query; -} - -void drizzle_query_free(drizzle_query_st *query) -{ - if (query == NULL) - { - return; - } - - if (query->context != NULL && query->context_free_fn != NULL) - { - query->context_free_fn(query, query->context); - } - - if (query->drizzle->query_list == query) - { - query->drizzle->query_list= query->next; - } - - if (query->prev) - { - query->prev->next= query->next; - } - - if (query->next) - { - query->next->prev= query->prev; - } - - query->drizzle->query_count--; - - if (query->options.is_allocated) - { - delete query; - } -} - -void drizzle_query_free_all(drizzle_st *drizzle) -{ - while (drizzle->query_list != NULL) - { - drizzle_query_free(drizzle->query_list); - } -} - -drizzle_con_st *drizzle_query_con(drizzle_query_st *query) -{ - if (query == NULL) - { - return NULL; - } - - return query->con; -} - -void drizzle_query_set_con(drizzle_query_st *query, drizzle_con_st *con) -{ - if (query == NULL) - { - return; - } - - query->con= con; -} - -drizzle_result_st *drizzle_query_result(drizzle_query_st *query) -{ - if (query == NULL) - { - return NULL; - } - - return query->result; -} - -void drizzle_query_set_result(drizzle_query_st *query, - drizzle_result_st *result) -{ - if (query == NULL) - { - return; - } - - query->result= result; -} - -char *drizzle_query_string(drizzle_query_st *query, size_t *size) -{ - if (query == NULL) - { - return NULL; - } - - *size= query->size; - return (char *)(query->string); -} - -void drizzle_query_set_string(drizzle_query_st *query, const char *string, - size_t size) -{ - if (query == NULL) - { - return; - } - - query->string= string; - query->size= size; -} - -int drizzle_query_options(drizzle_query_st *) -{ - return 0; -} - -void drizzle_query_set_options(drizzle_query_st *, int) -{ -} - -void drizzle_query_add_options(drizzle_query_st *, int) -{ -} - -void drizzle_query_remove_options(drizzle_query_st *, int) -{ -} - -void *drizzle_query_context(drizzle_query_st *query) -{ - if (query == NULL) - { - return NULL; - } - - return query->context; -} - -void drizzle_query_set_context(drizzle_query_st *query, void *context) -{ - if (query == NULL) - { - return; - } - - query->context= context; -} - -void drizzle_query_set_context_free_fn(drizzle_query_st *query, - drizzle_query_context_free_fn *function) -{ - if (query == NULL) - { - return; - } - - query->context_free_fn= function; -} - -static void drizzle_query_run_state(drizzle_query_st* query, - drizzle_return_t* ret_ptr) -{ - if (query == NULL) - { - return; - } - - switch (query->state) - { - case DRIZZLE_QUERY_STATE_INIT: - query->state= DRIZZLE_QUERY_STATE_QUERY; - - case DRIZZLE_QUERY_STATE_QUERY: - query->result= drizzle_query(query->con, query->result, query->string, - query->size, ret_ptr); - if (*ret_ptr == DRIZZLE_RETURN_IO_WAIT) - { - return; - } - else if (*ret_ptr != DRIZZLE_RETURN_OK) - { - query->state= DRIZZLE_QUERY_STATE_DONE; - return; - } - - query->state= DRIZZLE_QUERY_STATE_RESULT; - - case DRIZZLE_QUERY_STATE_RESULT: - *ret_ptr= drizzle_result_buffer(query->result); - if (*ret_ptr == DRIZZLE_RETURN_IO_WAIT) - { - return; - } - - query->state= DRIZZLE_QUERY_STATE_DONE; - return; - - default: - case DRIZZLE_QUERY_STATE_DONE: - return; - } -} - -drizzle_query_st *drizzle_query_run(drizzle_st *drizzle, - drizzle_return_t *ret_ptr) -{ - drizzle_return_t unused; - if (ret_ptr == NULL) - { - ret_ptr= &unused; - } - - if (drizzle == NULL) - { - *ret_ptr= DRIZZLE_RETURN_INVALID_ARGUMENT; - return NULL; - } - - if (drizzle->query_new == 0 && drizzle->query_running == 0) - { - *ret_ptr= DRIZZLE_RETURN_OK; - return NULL; - } - - drizzle_st::options_t options= drizzle->options; - drizzle->options.is_non_blocking= false; - - /* Check to see if any queries need to be started. */ - if (drizzle->query_new > 0) - { - for (drizzle_query_st *query= drizzle->query_list; query != NULL; query= query->next) - { - if (query->state != DRIZZLE_QUERY_STATE_INIT) - { - continue; - } - - drizzle->query_new--; - drizzle->query_running++; - assert(query->con->query == NULL); - query->con->query= query; - - drizzle_query_run_state(query, ret_ptr); - if (*ret_ptr != DRIZZLE_RETURN_IO_WAIT) - { - assert(query->state == DRIZZLE_QUERY_STATE_DONE); - drizzle->query_running--; - drizzle->options= options; - query->con->query= NULL; - if (*ret_ptr == DRIZZLE_RETURN_ERROR_CODE || *ret_ptr == DRIZZLE_RETURN_OK) - { - return query; - } - return NULL; - } - } - assert(drizzle->query_new == 0); - } - - while (1) - { - drizzle_con_st *con; - - /* Loop through each active connection. */ - while ((con= drizzle_con_ready(drizzle)) != NULL) - { - drizzle_query_st *query= con->query; - drizzle_query_run_state(query, ret_ptr); - if (query->state == DRIZZLE_QUERY_STATE_DONE) - { - drizzle->query_running--; - drizzle->options= options; - con->query= NULL; - return query; - } - assert(*ret_ptr == DRIZZLE_RETURN_IO_WAIT); - } - - if (options.is_non_blocking) - { - *ret_ptr= DRIZZLE_RETURN_IO_WAIT; - return NULL; - } - - *ret_ptr= drizzle_con_wait(drizzle); - if (*ret_ptr != DRIZZLE_RETURN_OK) - { - drizzle->options= options; - return NULL; - } - } -} - -drizzle_return_t drizzle_query_run_all(drizzle_st *drizzle) -{ - if (drizzle == NULL) - { - return DRIZZLE_RETURN_INVALID_ARGUMENT; - } - - while (drizzle->query_new > 0 || drizzle->query_running > 0) - { - drizzle_return_t ret; - - (void)drizzle_query_run(drizzle, &ret); - if (ret != DRIZZLE_RETURN_OK && ret != DRIZZLE_RETURN_ERROR_CODE) - { - return ret; - } - } - - return DRIZZLE_RETURN_OK; -} - -ssize_t drizzle_escape_string(char *to, size_t max_to_size, const char *from, size_t from_size) -{ - ssize_t to_size= 0; - char newchar; - const char *end; - - for (end= from + from_size; from < end; from++) - { - newchar= 0; - /* All multi-byte UTF8 characters have the high bit set for all bytes. */ - if (!(*from & 0x80)) - { - switch (*from) - { - case 0: - newchar= '0'; - break; - case '\n': - newchar= 'n'; - break; - case '\r': - newchar= 'r'; - break; - case '\032': - newchar= 'Z'; - break; - case '\\': - newchar= '\\'; - break; - case '\'': - newchar= '\''; - break; - case '"': - newchar= '"'; - break; - default: - break; - } - } - if (newchar != '\0') - { - if ((size_t)to_size + 2 > max_to_size) - { - return -1; - } - - *to++= '\\'; - *to++= newchar; - to_size++; - } - else - { - if ((size_t)to_size + 1 > max_to_size) - { - return -1; - } - - *to++= *from; - } - to_size++; - } - - *to= 0; - - return to_size; -} - -size_t drizzle_hex_string(char *to, const char *from, size_t from_size) -{ - static const char hex_map[]= "0123456789ABCDEF"; - const char *from_end; - - for (from_end= from + from_size; from != from_end; from++) - { - *to++= hex_map[((unsigned char) *from) >> 4]; - *to++= hex_map[((unsigned char) *from) & 0xF]; - } - - *to= 0; - - return from_size * 2; -} - -void drizzle_mysql_password_hash(char *to, const char *from, size_t from_size) -{ - SHA1_CTX ctx; - uint8_t hash_tmp1[SHA1_DIGEST_LENGTH]; - uint8_t hash_tmp2[SHA1_DIGEST_LENGTH]; - - SHA1Init(&ctx); - SHA1Update(&ctx, (const uint8_t*)from, from_size); - SHA1Final(hash_tmp1, &ctx); - - SHA1Init(&ctx); - SHA1Update(&ctx, hash_tmp1, SHA1_DIGEST_LENGTH); - SHA1Final(hash_tmp2, &ctx); - - (void)drizzle_hex_string(to, (char*)hash_tmp2, SHA1_DIGEST_LENGTH); -} diff --git a/utils/mysqlcl_idb/result.cc b/utils/mysqlcl_idb/result.cc deleted file mode 100644 index 281a3dd5b..000000000 --- a/utils/mysqlcl_idb/result.cc +++ /dev/null @@ -1,803 +0,0 @@ -/* - * Drizzle Client & Protocol Library - * - * Copyright (C) 2008 Eric Day (eday@oddments.org) - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * - * * The names of its contributors may not be used to endorse or - * promote products derived from this software without specific prior - * written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -/** - * @file - * @brief Result definitions - */ - -#include -#include - -/* - * Common definitions - */ - -drizzle_result_st *drizzle_result_create(drizzle_con_st *con) -{ - return drizzle_result_create_with(con, NULL); -} - -drizzle_result_st *drizzle_result_create_with(drizzle_con_st *con, - drizzle_result_st *result) -{ - if (result == NULL) - { - result= new (std::nothrow) drizzle_result_st; - - if (result == NULL) - { - return NULL; - } - - result->row= NULL; - result->field_buffer= NULL; - result->_options.is_allocated= true; - } - else - { - result->prev= NULL; - result->options= 0; - - result->info[0]= '\0'; - result->error_code= 0; - result->sqlstate[0]= '\0'; - result->insert_id= 0; - result->warning_count= 0; - result->affected_rows= 0; - - result->column_count= 0; - result->column_current= 0; - result->column_list= NULL; - result->column= NULL; - result->column_buffer= NULL; - - result->row_count= 0; - result->row_current= 0; - - result->field_current= 0; - result->field_total= 0; - result->field_offset= 0; - result->field_size= 0; - result->field= NULL; - result->field_buffer= NULL; - - result->row_list_size= 0; - result->row= NULL; - result->row_list= NULL; - result->field_sizes= NULL; - result->field_sizes_list= NULL; - - result->_options.is_allocated= false; - } - - result->con= con; - con->result= result; - - if (con->result_list) - con->result_list->prev= result; - result->next= con->result_list; - con->result_list= result; - con->result_count++; - - return result; -} - -drizzle_result_st *drizzle_result_clone(drizzle_con_st *con, - drizzle_result_st *source) -{ - drizzle_result_st *result= drizzle_result_create(con); - if (result == NULL) - { - return NULL; - } - - result->options= source->options; - - drizzle_result_set_info(result, source->info); - result->error_code= source->error_code; - drizzle_result_set_sqlstate(result, source->sqlstate); - result->warning_count= source->warning_count; - result->insert_id= source->insert_id; - result->affected_rows= source->affected_rows; - result->column_count= source->column_count; - result->row_count= source->row_count; - - return result; -} - -void drizzle_result_free(drizzle_result_st *result) -{ - drizzle_column_st *column; - - if (result == NULL) - { - return; - } - - for (column= result->column_list; column != NULL; column= result->column_list) - { - drizzle_column_free(column); - } - - delete[] result->column_buffer; - - if (result->options & DRIZZLE_RESULT_BUFFER_ROW) - { - for (size_t x= 0; x < result->row_count; x++) - { - drizzle_row_free(result, result->row_list->at(x)); - } - - delete result->row_list; - delete result->field_sizes_list; - } - - if (result->con) - { - result->con->result_count--; - if (result->con->result_list == result) - result->con->result_list= result->next; - } - - if (result->prev) - result->prev->next= result->next; - - if (result->next) - result->next->prev= result->prev; - - if (result->_options.is_allocated) - { - delete result; - } -} - -void drizzle_result_free_all(drizzle_con_st *con) -{ - while (con->result_list != NULL) - { - drizzle_result_free(con->result_list); - } -} - -drizzle_con_st *drizzle_result_drizzle_con(drizzle_result_st *result) -{ - if (result == NULL) - { - return NULL; - } - - return result->con; -} - -bool drizzle_result_eof(drizzle_result_st *result) -{ - if (result == NULL) - { - return false; - } - - return (result->options & DRIZZLE_RESULT_EOF_PACKET) ? true : false; -} - -const char *drizzle_result_info(drizzle_result_st *result) -{ - if (result == NULL) - { - return NULL; - } - - return result->info; -} - -const char *drizzle_result_error(drizzle_result_st *result) -{ - if (result == NULL) - { - return NULL; - } - - return result->info; -} - -uint16_t drizzle_result_error_code(drizzle_result_st *result) -{ - if (result == NULL) - { - return 0; - } - - return result->error_code; -} - -const char *drizzle_result_sqlstate(drizzle_result_st *result) -{ - if (result == NULL) - { - return NULL; - } - - return result->sqlstate; -} - -uint16_t drizzle_result_warning_count(drizzle_result_st *result) -{ - if (result == NULL) - { - return 0; - } - - return result->warning_count; -} - -uint64_t drizzle_result_insert_id(drizzle_result_st *result) -{ - if (result == NULL) - { - return 0; - } - - return result->insert_id; -} - -uint64_t drizzle_result_affected_rows(drizzle_result_st *result) -{ - if (result == NULL) - { - return 0; - } - - return result->affected_rows; -} - -uint16_t drizzle_result_column_count(drizzle_result_st *result) -{ - if (result == NULL) - { - return 0; - } - - return result->column_count; -} - -uint64_t drizzle_result_row_count(drizzle_result_st *result) -{ - if (result == NULL) - { - return 0; - } - - return result->row_count; -} - -/* - * Client definitions - */ - -drizzle_result_st *drizzle_result_read(drizzle_con_st *con, - drizzle_result_st *result, - drizzle_return_t *ret_ptr) -{ - drizzle_return_t unused; - if (ret_ptr == NULL) - { - ret_ptr= &unused; - } - - if (con == NULL) - { - *ret_ptr= DRIZZLE_RETURN_INVALID_ARGUMENT; - return NULL; - } - - if (drizzle_state_none(con)) - { - con->result= drizzle_result_create_with(con, result); - if (con->result == NULL) - { - *ret_ptr= DRIZZLE_RETURN_MEMORY; - return NULL; - } - - drizzle_state_push(con, drizzle_state_result_read); - drizzle_state_push(con, drizzle_state_packet_read); - } - - *ret_ptr= drizzle_state_loop(con); - return con->result; -} - -drizzle_return_t drizzle_result_buffer(drizzle_result_st *result) -{ - if (result == NULL) - { - return DRIZZLE_RETURN_INVALID_ARGUMENT; - } - - if (!(result->options & DRIZZLE_RESULT_BUFFER_COLUMN)) - { - drizzle_return_t ret= drizzle_column_buffer(result); - if (ret != DRIZZLE_RETURN_OK) - { - return ret; - } - } - - if (result->column_count == 0) - { - result->options|= DRIZZLE_RESULT_BUFFER_ROW; - return DRIZZLE_RETURN_OK; - } - - while (1) - { - drizzle_return_t ret; - drizzle_row_t row= drizzle_row_buffer(result, &ret); - if (ret != DRIZZLE_RETURN_OK) - { - return ret; - } - - if (row == NULL) - { - break; - } - - if (result->row_list == NULL) - { - result->row_list= new (std::nothrow) drizzle_row_list_t; - - if (result->row_list == NULL) - { - return DRIZZLE_RETURN_MEMORY; - } - } - - - if (result->field_sizes_list == NULL) - { - result->field_sizes_list= new (std::nothrow) drizzle_field_sizes_list_t; - - if (result->field_sizes_list == NULL) - { - } - } - - result->row_list->push_back(row); - result->field_sizes_list->push_back(result->field_sizes); - } - - result->options|= DRIZZLE_RESULT_BUFFER_ROW; - - return DRIZZLE_RETURN_OK; -} - -size_t drizzle_result_row_size(drizzle_result_st *result) -{ - if (result == NULL) - { - return 0; - } - - return result->con->packet_size; -} - -/* - * Server definitions - */ - -drizzle_return_t drizzle_result_write(drizzle_con_st *con, - drizzle_result_st *result, bool flush) -{ - if (con == NULL) - { - return DRIZZLE_RETURN_INVALID_ARGUMENT; - } - - if (drizzle_state_none(con)) - { - con->result= result; - - if (flush) - drizzle_state_push(con, drizzle_state_write); - - drizzle_state_push(con, drizzle_state_result_write); - } - - return drizzle_state_loop(con); -} - -void drizzle_result_set_row_size(drizzle_result_st *result, size_t size) -{ - if (result == NULL) - { - return; - } - - result->con->packet_size= size; -} - -void drizzle_result_calc_row_size(drizzle_result_st *result, - const drizzle_field_t *field, - const size_t *size) -{ - if (result == NULL) - { - return; - } - - result->con->packet_size= 0; - - for (uint16_t x= 0; x < result->column_count; x++) - { - if (field[x] == NULL) - { - result->con->packet_size++; - } - else if (size[x] < 251) - { - result->con->packet_size+= (1 + size[x]); - } - else if (size[x] < 65536) - { - result->con->packet_size+= (3 + size[x]); - } - else if (size[x] < 16777216) - { - result->con->packet_size+= (4 + size[x]); - } - else - { - result->con->packet_size+= (9 + size[x]); - } - } -} - -void drizzle_result_set_eof(drizzle_result_st *result, bool is_eof) -{ - if (result == NULL) - { - return; - } - - if (is_eof) - { - result->options|= DRIZZLE_RESULT_EOF_PACKET; - } - else - { - result->options&= ~DRIZZLE_RESULT_EOF_PACKET; - } -} - -void drizzle_result_set_info(drizzle_result_st *result, const char *info) -{ - if (result == NULL) - { - return; - } - - if (info == NULL) - { - result->info[0]= 0; - } - else - { - strncpy(result->info, info, DRIZZLE_MAX_INFO_SIZE); - result->info[DRIZZLE_MAX_INFO_SIZE - 1]= 0; - } -} - -void drizzle_result_set_error(drizzle_result_st *result, const char *error) -{ - if (result == NULL) - { - return; - } - - drizzle_result_set_info(result, error); -} - -void drizzle_result_set_error_code(drizzle_result_st *result, - uint16_t error_code) -{ - if (result == NULL) - { - return; - } - - result->error_code= error_code; -} - -void drizzle_result_set_sqlstate(drizzle_result_st *result, - const char *sqlstate) -{ - if (result == NULL) - { - return; - } - - if (sqlstate == NULL) - { - result->sqlstate[0]= 0; - } - else - { - strncpy(result->sqlstate, sqlstate, DRIZZLE_MAX_SQLSTATE_SIZE + 1); - result->sqlstate[DRIZZLE_MAX_SQLSTATE_SIZE]= 0; - } -} - -void drizzle_result_set_warning_count(drizzle_result_st *result, - uint16_t warning_count) -{ - if (result == NULL) - { - return; - } - - result->warning_count= warning_count; -} - -void drizzle_result_set_insert_id(drizzle_result_st *result, - uint64_t insert_id) -{ - if (result == NULL) - { - return; - } - - result->insert_id= insert_id; -} - -void drizzle_result_set_affected_rows(drizzle_result_st *result, - uint64_t affected_rows) -{ - if (result == NULL) - { - return; - } - - result->affected_rows= affected_rows; -} - -void drizzle_result_set_column_count(drizzle_result_st *result, - uint16_t column_count) -{ - if (result == NULL) - { - return; - } - - result->column_count= column_count; -} - -/* - * Internal state functions. - */ - -drizzle_return_t drizzle_state_result_read(drizzle_con_st *con) -{ - drizzle_return_t ret; - - if (con == NULL) - { - return DRIZZLE_RETURN_INVALID_ARGUMENT; - } - - - drizzle_log_debug(con->drizzle, "drizzle_state_result_read"); - - /* Assume the entire result packet will fit in the buffer. */ - if (con->buffer_size < con->packet_size) - { - drizzle_state_push(con, drizzle_state_read); - - return DRIZZLE_RETURN_OK; - } - - if (con->buffer_ptr[0] == 0) - { - con->buffer_ptr++; - /* We can ignore the returns since we've buffered the entire packet. */ - con->result->affected_rows= drizzle_unpack_length(con, &ret); - con->result->insert_id= drizzle_unpack_length(con, &ret); - con->status= (drizzle_con_status_t)drizzle_get_byte2(con->buffer_ptr); - con->result->warning_count= drizzle_get_byte2(con->buffer_ptr + 2); - con->buffer_ptr+= 4; - con->buffer_size-= 5; - con->packet_size-= 5; - if (con->packet_size > 0) - { - /* Skip one byte for message size. */ - con->buffer_ptr+= 1; - con->buffer_size-= 1; - con->packet_size-= 1; - } - ret= DRIZZLE_RETURN_OK; - } - else if (con->buffer_ptr[0] == 254) - { - con->result->options= DRIZZLE_RESULT_EOF_PACKET; - con->result->warning_count= drizzle_get_byte2(con->buffer_ptr + 1); - con->status= (drizzle_con_status_t)drizzle_get_byte2(con->buffer_ptr + 3); - con->buffer_ptr+= 5; - con->buffer_size-= 5; - con->packet_size-= 5; - ret= DRIZZLE_RETURN_OK; - } - else if (con->buffer_ptr[0] == 255) - { - con->result->error_code= drizzle_get_byte2(con->buffer_ptr + 1); - con->drizzle->error_code= con->result->error_code; - /* Byte 3 is always a '#' character, skip it. */ - memcpy(con->result->sqlstate, con->buffer_ptr + 4, - DRIZZLE_MAX_SQLSTATE_SIZE); - con->result->sqlstate[DRIZZLE_MAX_SQLSTATE_SIZE]= 0; - memcpy(con->drizzle->sqlstate, con->result->sqlstate, - DRIZZLE_MAX_SQLSTATE_SIZE + 1); - con->buffer_ptr+= 9; - con->buffer_size-= 9; - con->packet_size-= 9; - ret= DRIZZLE_RETURN_ERROR_CODE; - } - else - { - /* We can ignore the return since we've buffered the entire packet. */ - con->result->column_count= (uint16_t)drizzle_unpack_length(con, &ret); - ret= DRIZZLE_RETURN_OK; - } - - if (con->packet_size > 0) - { - snprintf(con->drizzle->last_error, DRIZZLE_MAX_ERROR_SIZE, "%.*s", - (int32_t)con->packet_size, con->buffer_ptr); - con->drizzle->last_error[DRIZZLE_MAX_ERROR_SIZE-1]= 0; - snprintf(con->result->info, DRIZZLE_MAX_INFO_SIZE, "%.*s", - (int32_t)con->packet_size, con->buffer_ptr); - con->result->info[DRIZZLE_MAX_INFO_SIZE-1]= 0; - con->buffer_ptr+= con->packet_size; - con->buffer_size-= con->packet_size; - con->packet_size= 0; - } - - drizzle_state_pop(con); - - return ret; -} - -drizzle_return_t drizzle_state_result_write(drizzle_con_st *con) -{ - if (con == NULL) - { - return DRIZZLE_RETURN_INVALID_ARGUMENT; - } - - uint8_t *start= con->buffer_ptr + con->buffer_size; - uint8_t *ptr; - drizzle_result_st *result= con->result; - - drizzle_log_debug(con->drizzle, "drizzle_state_result_write"); - - /* Calculate max packet size. */ - con->packet_size= 1 /* OK/Field Count/EOF/Error */ - + 9 /* Affected rows */ - + 9 /* Insert ID */ - + 2 /* Status */ - + 2 /* Warning count */ - + strlen(result->info); /* Info/error message */ - - /* Assume the entire result packet will fit in the buffer. */ - if ((con->packet_size + 4) > DRIZZLE_MAX_BUFFER_SIZE) - { - drizzle_set_error(con->drizzle, "drizzle_state_result_write", "buffer too small:%zu", con->packet_size + 4); - - return DRIZZLE_RETURN_INTERNAL_ERROR; - } - - /* Flush buffer if there is not enough room. */ - if (((size_t)DRIZZLE_MAX_BUFFER_SIZE - (size_t)(start - con->buffer)) < - con->packet_size) - { - drizzle_state_push(con, drizzle_state_write); - - return DRIZZLE_RETURN_OK; - } - - /* Store packet size at the end since it may change. */ - ptr= start; - ptr[3]= con->packet_number; - con->packet_number++; - ptr+= 4; - - if (result->options & DRIZZLE_RESULT_EOF_PACKET) - { - ptr[0]= 254; - ptr++; - - drizzle_set_byte2(ptr, result->warning_count); - ptr+= 2; - - drizzle_set_byte2(ptr, con->status); - ptr+= 2; - } - else if (result->error_code != 0) - { - ptr[0]= 255; - ptr++; - - drizzle_set_byte2(ptr, result->error_code); - ptr+= 2; - - ptr[0]= '#'; - ptr++; - - memcpy(ptr, result->sqlstate, DRIZZLE_MAX_SQLSTATE_SIZE); - ptr+= DRIZZLE_MAX_SQLSTATE_SIZE; - - memcpy(ptr, result->info, strlen(result->info)); - ptr+= strlen(result->info); - } - else if (result->column_count == 0) - { - ptr[0]= 0; - ptr++; - - ptr= drizzle_pack_length(result->affected_rows, ptr); - ptr= drizzle_pack_length(result->insert_id, ptr); - - drizzle_set_byte2(ptr, con->status); - ptr+= 2; - - drizzle_set_byte2(ptr, result->warning_count); - ptr+= 2; - - memcpy(ptr, result->info, strlen(result->info)); - ptr+= strlen(result->info); - } - else - ptr= drizzle_pack_length(result->column_count, ptr); - - con->packet_size= ((size_t)(ptr - start) - 4); - con->buffer_size+= (4 + con->packet_size); - - /* Store packet size now. */ - drizzle_set_byte3(start, con->packet_size); - - drizzle_state_pop(con); - - return DRIZZLE_RETURN_OK; -} diff --git a/utils/mysqlcl_idb/row.cc b/utils/mysqlcl_idb/row.cc deleted file mode 100644 index 5df0ae646..000000000 --- a/utils/mysqlcl_idb/row.cc +++ /dev/null @@ -1,272 +0,0 @@ -/* - * Drizzle Client & Protocol Library - * - * Copyright (C) 2008 Eric Day (eday@oddments.org) - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * - * * The names of its contributors may not be used to endorse or - * promote products derived from this software without specific prior - * written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -#include -#include -using namespace std; - -/** - * @file - * @brief Row definitions - */ - -#include - -/* - * Client definitions - */ - -uint64_t drizzle_row_read(drizzle_result_st *result, drizzle_return_t *ret_ptr) -{ - if ((result->column_current != result->column_count) && (!(result->options & DRIZZLE_RESULT_BUFFER_COLUMN))) - { - drizzle_set_error(result->con->drizzle, "drizzle_row_read", "cannot retrieve rows until all columns are retrieved"); - *ret_ptr= DRIZZLE_RETURN_NOT_READY; - return 0; - } - - if (drizzle_state_none(result->con)) - { - drizzle_state_push(result->con, drizzle_state_row_read); - drizzle_state_push(result->con, drizzle_state_packet_read); - } - - *ret_ptr= drizzle_state_loop(result->con); - - return result->row_current; -} - -drizzle_row_t drizzle_row_buffer(drizzle_result_st *result, - drizzle_return_t *ret_ptr) -{ -//cout<<"drizzle_row_buffer: 0x" << hex << (ptrdiff_t)result << endl; - size_t total; - drizzle_row_t row; - - if (result == NULL) - { - return drizzle_row_t(); - } - - drizzle_return_t unused; - if (ret_ptr == NULL) - { - ret_ptr= &unused; - } - - if (result->row == NULL) - { - if (drizzle_row_read(result, ret_ptr) == 0 || *ret_ptr != DRIZZLE_RETURN_OK) - { - return NULL; - } - - result->row= new (std::nothrow) drizzle_row_t_type[result->column_count *2]; - - if (result->row == NULL) - { - *ret_ptr= DRIZZLE_RETURN_MEMORY; - return drizzle_row_t(); - } - result->field_sizes= reinterpret_cast(result->row + result->column_count); - } - - while (1) - { - drizzle_field_t field= drizzle_field_buffer(result, &total, ret_ptr); - if (*ret_ptr == DRIZZLE_RETURN_ROW_END) - { - break; - } - - if (*ret_ptr != DRIZZLE_RETURN_OK) - { - if (*ret_ptr != DRIZZLE_RETURN_IO_WAIT) - { - delete[] result->row; - result->row= NULL; - result->field_sizes= NULL; - } - - return NULL; - } - - result->row[result->field_current - 1]= field; - result->field_sizes[result->field_current - 1]= total; - } - - *ret_ptr= DRIZZLE_RETURN_OK; - row= result->row; - result->row= NULL; - - return row; -} - -void drizzle_row_free(drizzle_result_st *result, drizzle_row_t row) -{ - uint16_t x; - - for (x= 0; x < result->column_count; x++) - drizzle_field_free(row[x]); - - delete[] row; -} - -size_t *drizzle_row_field_sizes(drizzle_result_st *result) -{ - return result->field_sizes; -} - -drizzle_row_t drizzle_row_next(drizzle_result_st *result) -{ - if (result->row_current == result->row_count) - return NULL; - - result->field_sizes= result->field_sizes_list->at(static_cast(result->row_current)); - result->row_current++; - return result->row_list->at(static_cast(result->row_current) - 1); -} - -drizzle_row_t drizzle_row_prev(drizzle_result_st *result) -{ - if (result->row_current == 0) - return NULL; - - result->row_current--; - result->field_sizes= result->field_sizes_list->at(static_cast(result->row_current)); - return result->row_list->at(static_cast(result->row_current)); -} - -void drizzle_row_seek(drizzle_result_st *result, uint64_t row) -{ - if (row <= result->row_count) - result->row_current= row; -} - -drizzle_row_t drizzle_row_index(drizzle_result_st *result, uint64_t row) -{ - if (row >= result->row_count) - return NULL; - - return (*result->row_list)[static_cast(row)]; -} - -uint64_t drizzle_row_current(drizzle_result_st *result) -{ - return result->row_current; -} - -/* - * Server definitions - */ - -drizzle_return_t drizzle_row_write(drizzle_result_st *result) -{ - if (drizzle_state_none(result->con)) - drizzle_state_push(result->con, drizzle_state_row_write); - - return drizzle_state_loop(result->con); -} - -/* - * Internal state functions. - */ - -drizzle_return_t drizzle_state_row_read(drizzle_con_st *con) -{ - drizzle_log_debug(con->drizzle, "drizzle_state_row_read"); - - if (con->packet_size != 0 && con->buffer_size < con->packet_size && - con->buffer_size < 5) - { - drizzle_state_push(con, drizzle_state_read); - return DRIZZLE_RETURN_OK; - } - - if (con->packet_size == 5 && con->buffer_ptr[0] == 254) - { - /* Got EOF packet, no more rows. */ - con->result->row_current= 0; - con->result->warning_count= drizzle_get_byte2(con->buffer_ptr + 1); - con->status= (drizzle_con_status_t)drizzle_get_byte2(con->buffer_ptr + 3); - con->buffer_ptr+= 5; - con->buffer_size-= 5; - } - else if (con->buffer_ptr[0] == 255) - { - drizzle_state_pop(con); - drizzle_state_push(con, drizzle_state_result_read); - return DRIZZLE_RETURN_OK; - } - else if (con->result->options & DRIZZLE_RESULT_ROW_BREAK) - { - con->result->options&= ~DRIZZLE_RESULT_ROW_BREAK; - } - else - { - con->result->row_count++; - con->result->row_current++; - con->result->field_current= 0; - } - - drizzle_state_pop(con); - - return DRIZZLE_RETURN_OK; -} - -drizzle_return_t drizzle_state_row_write(drizzle_con_st *con) -{ - uint8_t *start= con->buffer_ptr + con->buffer_size; - - drizzle_log_debug(con->drizzle, "drizzle_state_row_write"); - - /* Flush buffer if there is not enough room. */ - if (((size_t)DRIZZLE_MAX_BUFFER_SIZE - (size_t)(start - con->buffer)) < 4) - { - drizzle_state_push(con, drizzle_state_write); - return DRIZZLE_RETURN_OK; - } - - drizzle_set_byte3(start, con->packet_size); - start[3]= con->packet_number; - con->packet_number++; - - con->buffer_size+= 4; - - drizzle_state_pop(con); - - return DRIZZLE_RETURN_OK; -} diff --git a/utils/mysqlcl_idb/sha1.cc b/utils/mysqlcl_idb/sha1.cc deleted file mode 100644 index 9cd39ed34..000000000 --- a/utils/mysqlcl_idb/sha1.cc +++ /dev/null @@ -1,179 +0,0 @@ -/** - * @file - * @brief SHA1 Definitions - */ - -/* - * SHA-1 in C - * - * Copyright (C) 2010 nobody (this is public domain) - * - * This file is based on public domain code. - * Initial source code is in the public domain, - * so clarified by Steve Reid - * - * Test Vectors (from FIPS PUB 180-1) - * "abc" - * A9993E36 4706816A BA3E2571 7850C26C 9CD0D89D - * "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq" - * 84983E44 1C3BD26E BAAE4AA1 F95129E5 E54670F1 - * A million repetitions of "a" - * 34AA973C D4C4DAA4 F61EEB2B DBAD2731 6534016F - */ - -#include - -#define rol(value, bits) (((value) << (bits)) | ((value) >> (32 - (bits)))) - -/* - * blk0() and blk() perform the initial expand. - * I got the idea of expanding during the round function from SSLeay - */ -#ifndef WORDS_BIGENDIAN -# define blk0(i) (block->l[i] = (rol(block->l[i],24)&0xFF00FF00) \ - |(rol(block->l[i],8)&0x00FF00FF)) -#else -# define blk0(i) block->l[i] -#endif -#define blk(i) (block->l[i&15] = rol(block->l[(i+13)&15]^block->l[(i+8)&15] \ - ^block->l[(i+2)&15]^block->l[i&15],1)) - -/* - * (R0+R1), R2, R3, R4 are the different operations (rounds) used in SHA1 - */ -#define R0(v,w,x,y,z,i) z+=((w&(x^y))^y)+blk0(i)+0x5A827999+rol(v,5);w=rol(w,30); -#define R1(v,w,x,y,z,i) z+=((w&(x^y))^y)+blk(i)+0x5A827999+rol(v,5);w=rol(w,30); -#define R2(v,w,x,y,z,i) z+=(w^x^y)+blk(i)+0x6ED9EBA1+rol(v,5);w=rol(w,30); -#define R3(v,w,x,y,z,i) z+=(((w|x)&y)|(w&x))+blk(i)+0x8F1BBCDC+rol(v,5);w=rol(w,30); -#define R4(v,w,x,y,z,i) z+=(w^x^y)+blk(i)+0xCA62C1D6+rol(v,5);w=rol(w,30); - -/* - * Hash a single 512-bit block. This is the core of the algorithm. - */ -void -SHA1Transform(uint32_t state[5], const uint8_t buffer[SHA1_BLOCK_LENGTH]) -{ - uint32_t a, b, c, d, e; - typedef union { - uint8_t c[64]; - uint32_t l[16]; - } CHAR64LONG16; - CHAR64LONG16 realBlock; - CHAR64LONG16 *block= &realBlock; - - (void)memcpy(block, buffer, SHA1_BLOCK_LENGTH); - - /* Copy context->state[] to working vars */ - a = state[0]; - b = state[1]; - c = state[2]; - d = state[3]; - e = state[4]; - - /* 4 rounds of 20 operations each. Loop unrolled. */ - R0(a,b,c,d,e, 0); R0(e,a,b,c,d, 1); R0(d,e,a,b,c, 2); R0(c,d,e,a,b, 3); - R0(b,c,d,e,a, 4); R0(a,b,c,d,e, 5); R0(e,a,b,c,d, 6); R0(d,e,a,b,c, 7); - R0(c,d,e,a,b, 8); R0(b,c,d,e,a, 9); R0(a,b,c,d,e,10); R0(e,a,b,c,d,11); - R0(d,e,a,b,c,12); R0(c,d,e,a,b,13); R0(b,c,d,e,a,14); R0(a,b,c,d,e,15); - R1(e,a,b,c,d,16); R1(d,e,a,b,c,17); R1(c,d,e,a,b,18); R1(b,c,d,e,a,19); - R2(a,b,c,d,e,20); R2(e,a,b,c,d,21); R2(d,e,a,b,c,22); R2(c,d,e,a,b,23); - R2(b,c,d,e,a,24); R2(a,b,c,d,e,25); R2(e,a,b,c,d,26); R2(d,e,a,b,c,27); - R2(c,d,e,a,b,28); R2(b,c,d,e,a,29); R2(a,b,c,d,e,30); R2(e,a,b,c,d,31); - R2(d,e,a,b,c,32); R2(c,d,e,a,b,33); R2(b,c,d,e,a,34); R2(a,b,c,d,e,35); - R2(e,a,b,c,d,36); R2(d,e,a,b,c,37); R2(c,d,e,a,b,38); R2(b,c,d,e,a,39); - R3(a,b,c,d,e,40); R3(e,a,b,c,d,41); R3(d,e,a,b,c,42); R3(c,d,e,a,b,43); - R3(b,c,d,e,a,44); R3(a,b,c,d,e,45); R3(e,a,b,c,d,46); R3(d,e,a,b,c,47); - R3(c,d,e,a,b,48); R3(b,c,d,e,a,49); R3(a,b,c,d,e,50); R3(e,a,b,c,d,51); - R3(d,e,a,b,c,52); R3(c,d,e,a,b,53); R3(b,c,d,e,a,54); R3(a,b,c,d,e,55); - R3(e,a,b,c,d,56); R3(d,e,a,b,c,57); R3(c,d,e,a,b,58); R3(b,c,d,e,a,59); - R4(a,b,c,d,e,60); R4(e,a,b,c,d,61); R4(d,e,a,b,c,62); R4(c,d,e,a,b,63); - R4(b,c,d,e,a,64); R4(a,b,c,d,e,65); R4(e,a,b,c,d,66); R4(d,e,a,b,c,67); - R4(c,d,e,a,b,68); R4(b,c,d,e,a,69); R4(a,b,c,d,e,70); R4(e,a,b,c,d,71); - R4(d,e,a,b,c,72); R4(c,d,e,a,b,73); R4(b,c,d,e,a,74); R4(a,b,c,d,e,75); - R4(e,a,b,c,d,76); R4(d,e,a,b,c,77); R4(c,d,e,a,b,78); R4(b,c,d,e,a,79); - - /* Add the working vars back into context.state[] */ - state[0] += a; - state[1] += b; - state[2] += c; - state[3] += d; - state[4] += e; - - /* Wipe variables */ - a = b = c = d = e = 0; -} - - -/* - * SHA1Init - Initialize new context - */ -void -SHA1Init(SHA1_CTX *context) -{ - - /* SHA1 initialization constants */ - context->count = 0; - context->state[0] = 0x67452301; - context->state[1] = 0xEFCDAB89; - context->state[2] = 0x98BADCFE; - context->state[3] = 0x10325476; - context->state[4] = 0xC3D2E1F0; -} - - -/* - * Run your data through this. - */ -void -SHA1Update(SHA1_CTX *context, const uint8_t *data, size_t len) -{ - size_t i, j; - - j = (size_t)((context->count >> 3) & 63); - context->count += (len << 3); - if ((j + len) > 63) { - (void)memcpy(&context->buffer[j], data, (i = 64-j)); - SHA1Transform(context->state, context->buffer); - for ( ; i + 63 < len; i += 64) - SHA1Transform(context->state, (uint8_t *)&data[i]); - j = 0; - } else { - i = 0; - } - (void)memcpy(&context->buffer[j], &data[i], len - i); -} - - -/* - * Add padding and return the message digest. - */ -void -SHA1Pad(SHA1_CTX *context) -{ - uint8_t finalcount[8]; - u_int i; - - for (i = 0; i < 8; i++) { - finalcount[i] = (uint8_t)((context->count >> - ((7 - (i & 7)) * 8)) & 255); /* Endian independent */ - } - SHA1Update(context, (uint8_t *)"\200", 1); - while ((context->count & 504) != 448) - SHA1Update(context, (uint8_t *)"\0", 1); - SHA1Update(context, finalcount, 8); /* Should cause a SHA1Transform() */ -} - -void -SHA1Final(uint8_t digest[SHA1_DIGEST_LENGTH], SHA1_CTX *context) -{ - u_int i; - - SHA1Pad(context); - if (digest) { - for (i = 0; i < SHA1_DIGEST_LENGTH; i++) { - digest[i] = (uint8_t) - ((context->state[i>>2] >> ((3-(i & 3)) * 8) ) & 255); - } - memset(context, 0, sizeof(*context)); - } -} diff --git a/utils/mysqlcl_idb/state.cc b/utils/mysqlcl_idb/state.cc deleted file mode 100644 index 34b476ee2..000000000 --- a/utils/mysqlcl_idb/state.cc +++ /dev/null @@ -1,100 +0,0 @@ -/* - * Drizzle Client & Protocol Library - * - * Copyright (C) 2008 Eric Day (eday@oddments.org) - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * - * * The names of its contributors may not be used to endorse or - * promote products derived from this software without specific prior - * written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -/** - * @file - * @brief State machine definitions - */ - -#include - -drizzle_return_t drizzle_state_loop(drizzle_con_st *con) -{ - while (drizzle_state_none(con) == false) - { - drizzle_return_t ret= con->state_stack[con->state_current - 1](con); - if (ret != DRIZZLE_RETURN_OK) - { - if (ret != DRIZZLE_RETURN_IO_WAIT && ret != DRIZZLE_RETURN_PAUSE && - ret != DRIZZLE_RETURN_ERROR_CODE) - { - drizzle_con_close(con); - } - - return ret; - } - } - - return DRIZZLE_RETURN_OK; -} - -drizzle_return_t drizzle_state_packet_read(drizzle_con_st *con) -{ - drizzle_log_debug(con->drizzle, "drizzle_state_packet_read"); - - if (con->buffer_size < 4) - { - drizzle_state_push(con, drizzle_state_read); - return DRIZZLE_RETURN_OK; - } - - con->packet_size= drizzle_get_byte3(con->buffer_ptr); - - if (con->buffer_size < con->packet_size + 4) - { - drizzle_state_push(con, drizzle_state_read); - return DRIZZLE_RETURN_OK; - } - - if (con->packet_number != con->buffer_ptr[3]) - { - drizzle_set_error(con->drizzle, "drizzle_state_packet_read", - "bad packet number:%u:%u", con->packet_number, - con->buffer_ptr[3]); - return DRIZZLE_RETURN_BAD_PACKET_NUMBER; - } - - drizzle_log_debug(con->drizzle, "packet_size= %zu, packet_number= %u", - con->packet_size, con->packet_number); - - con->packet_number++; - - con->buffer_ptr+= 4; - con->buffer_size-= 4; - - drizzle_state_pop(con); - return DRIZZLE_RETURN_OK; -} diff --git a/utils/mysqlcl_idb/tdriver-works.cpp b/utils/mysqlcl_idb/tdriver-works.cpp deleted file mode 100644 index 67f4b2225..000000000 --- a/utils/mysqlcl_idb/tdriver-works.cpp +++ /dev/null @@ -1,122 +0,0 @@ -/* - * Drizzle Client & Protocol Library - * - * Copyright (C) 2008 Eric Day (eday@oddments.org) - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following disclaimer - * in the documentation and/or other materials provided with the - * distribution. - * - * * The names of its contributors may not be used to endorse or - * promote products derived from this software without specific prior - * written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -#include -#include -#include -#include -#include -#include -#include - -using namespace std; - -int main(int argc, char *argv[]) -{ - const char* host= NULL; - const char* user= NULL; - const char* password= NULL; - in_port_t port= 0; - - for (int c; (c = getopt(argc, argv, "d:h:mp:u:P:q:v")) != -1; ) - { - switch (c) - { - case 'h': - host= optarg; - break; - - case 'p': - port= static_cast(atoi(optarg)); - break; - - case 'u': - user= optarg; - break; - - case 'P': - password = optarg; - break; - - default: - cout << - "usage:\n" - "\t-h - Host to connect to\n" - "\t-p - Port to connect to\n" - "\t-u - User\n" - "\t-P - Password\n"; - return 1; - } - } -host="127.0.0.1"; -port=13306; -user="rjd"; -password=""; - - drizzle::drizzle_c drizzle; - drizzle_set_verbose((drizzle_st*)drizzle, DRIZZLE_VERBOSE_DEBUG); - drizzle::connection_c* con= new drizzle::connection_c(drizzle); - if (host || port) - con->set_tcp(host, port); - if (user || password) - con->set_auth(user, password); - //con->set_db("information_schema"); - //drizzle::query_c q(*con, "select table_schema, table_name from tables where table_name like ?"); - con->set_db("tpch1"); - drizzle::query_c q(*con, "select n_nationkey from nation"); - //q.p("%"); - try - { - drizzle::result_c result= q.execute(); - cout << q.read() << endl; - while (drizzle_row_t row= result.row_next()) - { - for (int x= 0; x < result.column_count(); x++) - { - if (x) - cout << ", "; - cout << (row[x] ? row[x] : "NULL"); - } - cout << endl; - } - } - catch (const drizzle::bad_query& e) - { - cerr << e.what() << endl; - return 1; - } - return 0; -} diff --git a/utils/mysqlcl_idb/tdriver.cpp b/utils/mysqlcl_idb/tdriver.cpp deleted file mode 100644 index ea5daf42d..000000000 --- a/utils/mysqlcl_idb/tdriver.cpp +++ /dev/null @@ -1,114 +0,0 @@ -#include -//#define NDEBUG -#include -using namespace std; - -#include "libdrizzle-2.0/drizzle.h" -#include "libdrizzle-2.0/drizzle_client.h" - -namespace -{ -int doit() -{ - drizzle_st* drzp=0; - drzp = drizzle_create(); - assert(drzp); - - //drizzle_set_verbose(drzp, DRIZZLE_VERBOSE_DEBUG); - - drizzle_con_st* drzcp=0; - drzcp = drizzle_con_add_tcp(drzp, "127.0.0.1", 13306, "rjd", "", "tpch1", DRIZZLE_CON_MYSQL); - - drizzle_return_t drztr; - drztr = drizzle_con_connect(drzcp); - assert(drztr==0); - - //const char* query = "select * from nation"; - const char* query = "select * from region"; - drizzle_return_t* drztrp=0; - drztrp = &drztr; - drizzle_result_st* drzrp=0; - //drzrp=drizzle_result_create(drzcp); - //assert(drzrp); - drzrp = drizzle_query_str(drzcp, drzrp, query, drztrp); - assert(drzrp); - cout << "return_t = " << drztr << endl; - - drztr = drizzle_result_buffer(drzrp); - cout << "return_t = " << drztr << endl; - - drizzle_row_t row; - row = drizzle_row_next(drzrp); - while (row) - { - //cout << "got row: " << row[0] << ',' << row[1] << ',' << row[2] << '.' << row[3] << endl; - cout << "got row: " << row[0] << ',' << row[1] << ',' << row[2] << endl; - //drizzle_row_free(drzrp, row); - row = drizzle_row_next(drzrp); - } - drizzle_result_free(drzrp); - drzrp = 0; - - drizzle_con_close(drzcp); - drizzle_con_free(drzcp); - drzcp = 0; - drizzle_free(drzp); - drzp = 0; - - return 0; -} - -int insertit() -{ - drizzle_st* drzp=0; - drzp = drizzle_create(); - assert(drzp); - - //drizzle_set_verbose(drzp, DRIZZLE_VERBOSE_DEBUG); - - drizzle_con_st* drzcp=0; - drzcp = drizzle_con_add_tcp(drzp, "127.0.0.1", 13306, "rjd", "", "tpch1", DRIZZLE_CON_MYSQL); - - drizzle_return_t drztr; - drztr = drizzle_con_connect(drzcp); - assert(drztr==0); - - //const char* query = "select * from nation"; - const char* query = "insert into foo values (1)"; - drizzle_return_t* drztrp=0; - drztrp = &drztr; - drizzle_result_st* drzrp=0; - //drzrp=drizzle_result_create(drzcp); - //assert(drzrp); - drzrp = drizzle_query_str(drzcp, drzrp, query, drztrp); - assert(drzrp); - cout << "return_t = " << drztr << endl; - - drztr = drizzle_result_buffer(drzrp); - cout << "return_t = " << drztr << endl; - - drizzle_result_free(drzrp); - drzrp = 0; - - drizzle_con_close(drzcp); - drizzle_con_free(drzcp); - drzcp = 0; - drizzle_free(drzp); - drzp = 0; - - return 0; -} - -} - -int main(int argc, char** argv) -{ - doit(); - //doit(); - //doit(); - //doit(); - insertit(); - - return 0; -} - diff --git a/utils/mysqlcl_idb/tdriver1.cpp b/utils/mysqlcl_idb/tdriver1.cpp deleted file mode 100644 index e1a992af4..000000000 --- a/utils/mysqlcl_idb/tdriver1.cpp +++ /dev/null @@ -1,53 +0,0 @@ -#include -//#define NDEBUG -#include -using namespace std; - -#include "libdrizzle-2.0/drizzle.h" -#include "libdrizzle-2.0/drizzle_client.h" - -int main(int argc, char** argv) -{ - drizzle_st* drzp=0; - drzp = drizzle_create(); - assert(drzp); - - drizzle_set_verbose(drzp, DRIZZLE_VERBOSE_DEBUG); - - drizzle_con_st* drzcp=0; - drzcp = drizzle_con_create(drzp); - assert(drzcp); - - //drizzle_con_add_tcp(drzp, "127.0.0.1", 13306, "rjd", "", "tpch1", DRIZZLE_CON_MYSQL); - drizzle_con_set_tcp(drzcp, "127.0.0.1", 13306); - drizzle_con_set_auth(drzcp, "rjd", ""); - drizzle_con_set_db(drzcp, "tpch1"); - drizzle_con_add_options(drzcp, DRIZZLE_CON_MYSQL); - - drizzle_con_connect(drzcp); - - drizzle_result_st* drzrp=0; - drzrp = drizzle_result_create(drzcp); - assert(drzrp); - - const char* query = "select n_nationkey from nation"; - drizzle_return_t drztr; - drizzle_return_t* drztrp=0; - drztrp = &drztr; - drzrp = drizzle_query_str(drzcp, drzrp, query, drztrp); - assert(drzrp); - cout << "return_t = " << drztr << endl; - - uint64_t nrows=0; - nrows = drizzle_row_read(drzrp, drztrp); - cout << "return_t = " << drztr << endl; - cout << "rows returned = " << nrows << endl; - - nrows = drizzle_result_row_count(drzrp); - cout << "rows returned = " << nrows << endl; - - drizzle_con_close(drzcp); - - return 0; -} - diff --git a/utils/querystats/CMakeLists.txt b/utils/querystats/CMakeLists.txt index 940749a6b..001211834 100644 --- a/utils/querystats/CMakeLists.txt +++ b/utils/querystats/CMakeLists.txt @@ -8,6 +8,8 @@ set(querystats_LIB_SRCS querystats.cpp) add_library(querystats SHARED ${querystats_LIB_SRCS}) +target_link_libraries(querystats -L${SERVER_SOURCE_ROOT_DIR}/libmysql/ libmysqlclient_r.so) + set_target_properties(querystats PROPERTIES VERSION 1.0.0 SOVERSION 1) install(TARGETS querystats DESTINATION ${ENGINE_LIBDIR} COMPONENT libs) diff --git a/utils/querystats/querystats.cpp b/utils/querystats/querystats.cpp index 2494646d5..8c2b18c10 100644 --- a/utils/querystats/querystats.cpp +++ b/utils/querystats/querystats.cpp @@ -21,6 +21,8 @@ * ***********************************************************************/ +#include +#include #include using namespace std; @@ -37,28 +39,24 @@ using namespace logging; #include "querystats.h" -#include "libdrizzle-2.0/drizzle.h" -#include "libdrizzle-2.0/drizzle_client.h" - namespace querystats { const string SCHEMA = "infinidb_querystats"; -struct IDB_Drizzle +struct IDB_MySQL { - IDB_Drizzle(): drzp(NULL), drzcp(NULL), drzrp(NULL) {} - ~IDB_Drizzle() + IDB_MySQL(): fCon(NULL), fRes(NULL) {} + ~IDB_MySQL() { - // The following API all checks NULL in the implementation. - drizzle_result_free(drzrp); - drizzle_con_close(drzcp); - drizzle_con_free(drzcp); - drizzle_free(drzp); + if (fRes) + mysql_free_result(fRes); + + if (fCon) + mysql_close(fCon); } - drizzle_st* drzp; - drizzle_con_st* drzcp; - drizzle_result_st* drzrp; + MYSQL* fCon; + MYSQL_RES* fRes; }; QueryStats::QueryStats() @@ -206,25 +204,19 @@ void QueryStats::insert() ERR_CROSS_ENGINE_CONFIG); // insert stats to querystats table - IDB_Drizzle drizzle; + IDB_MySQL mysql; - drizzle.drzp = drizzle_create(); - if (drizzle.drzp == 0) + mysql.fCon = mysql_init(NULL); + if (mysql.fCon == NULL) handleMySqlError("fatal error initializing querystats lib", -1); - drizzle.drzcp = drizzle_con_add_tcp(drizzle.drzp, host.c_str(), port, user.c_str(), pwd.c_str(), - SCHEMA.c_str(), DRIZZLE_CON_MYSQL); - if (drizzle.drzcp == 0) - handleMySqlError("fatal error setting up parms in querystats lib", -1); - - drizzle_return_t drzret; - drzret = drizzle_con_connect(drizzle.drzcp); - if (drzret != 0) - handleMySqlError("fatal error connecting to InfiniDB in querystats lib", drzret); + if (mysql_real_connect(mysql.fCon, host.c_str(), user.c_str(), pwd.c_str(), + SCHEMA.c_str(), port, NULL, 0) == NULL) + handleMySqlError("fatal error setting up parms in querystats lib", mysql_errno(mysql.fCon)); // escape quote characters boost::scoped_array query(new char[fQuery.length()*2+1]); - drizzle_escape_string(query.get(), fQuery.length()*2, fQuery.c_str(), fQuery.length()); + mysql_real_escape_string(mysql.fCon, query.get(), fQuery.c_str(), fQuery.length()); ostringstream insert; insert << "insert delayed into querystats values (0, "; @@ -248,14 +240,10 @@ void QueryStats::insert() insert << fBlocksChanged << ", "; insert << fNumFiles << ", "; insert << fFileBytes << ")"; // the last 2 fields are not populated yet - - drizzle.drzrp = drizzle_query_str(drizzle.drzcp, drizzle.drzrp, insert.str().c_str(), &drzret); - if (drzret != 0 || drizzle.drzrp == 0) - handleMySqlError("fatal error executing query in querystats lib", drzret); - drzret = drizzle_result_buffer(drizzle.drzrp); - if (drzret != 0) - handleMySqlError("fatal error reading results from InfiniDB in querystats lib", drzret); + int ret = mysql_query(mysql.fCon, insert.str().c_str()); + if (ret != 0) + handleMySqlError("fatal error executing query in querystats lib", ret); } void QueryStats::handleMySqlError(const char* errStr, unsigned int errCode) @@ -294,19 +282,14 @@ uint32_t QueryStats::userPriority(string _host, const string _user) ERR_CROSS_ENGINE_CONFIG); // get user priority - IDB_Drizzle drizzle; - drizzle.drzp = drizzle_create(); - if (drizzle.drzp == 0) + IDB_MySQL mysql; + mysql.fCon = mysql_init(NULL); + if (mysql.fCon == NULL) handleMySqlError("fatal error initializing querystats lib", -1); - drizzle.drzcp = drizzle_con_add_tcp(drizzle.drzp, host.c_str(), port, user.c_str(), pwd.c_str(), - SCHEMA.c_str(), DRIZZLE_CON_MYSQL); - if (drizzle.drzcp == 0) - handleMySqlError("fatal error setting up parms in querystats lib", -1); - drizzle_return_t drzret; - drzret = drizzle_con_connect(drizzle.drzcp); - if (drzret != 0) - handleMySqlError("fatal error connecting to InfiniDB in querystats lib", drzret); + if (mysql_real_connect(mysql.fCon, host.c_str(), user.c_str(), pwd.c_str(), + SCHEMA.c_str(), port, NULL, 0) == NULL) + handleMySqlError("fatal error connecting to InfiniDB in querystats lib", mysql_errno(mysql.fCon)); // get the part of host string befor ':' if there is. size_t pos = _host.find(':', 0); @@ -324,16 +307,18 @@ uint32_t QueryStats::userPriority(string _host, const string _user) << _user << "') and upper(a.priority) = upper(b.priority)"; - drizzle.drzrp = drizzle_query_str(drizzle.drzcp, drizzle.drzrp, query.str().c_str(), &drzret); - if (drzret != 0 || drizzle.drzrp == 0) - handleMySqlError("fatal error executing query in querystats lib", drzret); - drzret = drizzle_result_buffer(drizzle.drzrp); - if (drzret != 0) - handleMySqlError("fatal error reading results from InfiniDB in querystats lib", drzret); + int ret =mysql_query(mysql.fCon, query.str().c_str()); + if (ret != 0) + handleMySqlError("fatal error executing query in querystats lib", ret); + // Using mysql_store_result here as for mysql_use_result we would need to get every row + // Maybe limit 1 on the query in the future? + mysql.fRes = mysql_store_result(mysql.fCon); + if (mysql.fRes == NULL) + handleMySqlError("fatal error reading results from InfiniDB in querystats lib", mysql_errno(mysql.fCon)); // only fetch one row. if duplicate user name in the table, the first one will be got. - drizzle_row_t row; - row = drizzle_row_next(drizzle.drzrp); + MYSQL_ROW row; + row = mysql_fetch_row(mysql.fRes); if (row) { fPriority = row[0]; From 95e76a8e2614bf11c9f19d3ca26e85865212cb53 Mon Sep 17 00:00:00 2001 From: david hill Date: Tue, 24 Jan 2017 09:15:01 -0600 Subject: [PATCH 14/35] commit from develop, MCOL-455, MCOL-527, AND MCOL-528 --- oam/etc/ConsoleCmds.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/oam/etc/ConsoleCmds.xml b/oam/etc/ConsoleCmds.xml index b5ee9b85d..01f6001cc 100644 --- a/oam/etc/ConsoleCmds.xml +++ b/oam/etc/ConsoleCmds.xml @@ -29,7 +29,7 @@ redistributeData Redistribute table data accross all dbroots to balance disk usage START to begin a redistribution - START REMOVE [dbroots] to redistribute to all but the enumerated dbroots, leaving those empty + START REMOVE n to being a redistribution where data is removed from dbroot 'n' STOP to stop redistribution before completion STATUS to to view statistics and progress From 854a07f7b28c5489ecedd2351051b8095ced6190 Mon Sep 17 00:00:00 2001 From: Andrew Hutchings Date: Wed, 25 Jan 2017 11:03:03 +0000 Subject: [PATCH 15/35] MCOL-533 fix the table_usage() procedure The old procedure could be wildly incorrect when there were multiple extents for a dictionary column. The new one uses tables so that columnstore_files doesn't get hammered too hard. They can't be temporary tables due to the reuse restriction on temporary tables. --- dbcon/mysql/columnstore_info.sql | 48 +++++++++++++++++++++++--------- 1 file changed, 35 insertions(+), 13 deletions(-) diff --git a/dbcon/mysql/columnstore_info.sql b/dbcon/mysql/columnstore_info.sql index be8c70167..d8a9cba4b 100644 --- a/dbcon/mysql/columnstore_info.sql +++ b/dbcon/mysql/columnstore_info.sql @@ -1,6 +1,8 @@ -CREATE DATABASE columnstore_info; +CREATE DATABASE IF NOT EXISTS columnstore_info; USE columnstore_info; +DROP FUNCTION IF EXISTS `format_filesize`; + DELIMITER // CREATE FUNCTION `format_filesize`(filesize FLOAT) RETURNS varchar(20) CHARSET utf8 DETERMINISTIC BEGIN @@ -21,6 +23,7 @@ END LOOP; END // +DROP PROCEDURE IF EXISTS `total_usage` // CREATE PROCEDURE total_usage () BEGIN @@ -29,26 +32,45 @@ BEGIN (SELECT format_filesize(sum(file_size)) TOTAL_DISK_USAGE FROM INFORMATION_SCHEMA.COLUMNSTORE_FILES) TOTAL_DISK_USAGE; END // +DROP PROCEDURE IF EXISTS `table_usage` // + CREATE PROCEDURE table_usage (IN t_schema char(64), IN t_name char(64)) BEGIN + DROP TABLE IF EXISTS columnstore_info.columnstore_columns; + DROP TABLE IF EXISTS columnstore_info.columnstore_files; + CREATE TABLE columnstore_info.columnstore_columns engine=myisam as (select * from information_schema.columnstore_columns); + ALTER TABLE columnstore_info.columnstore_columns ADD INDEX `object_id` (`object_id`); + ALTER TABLE columnstore_info.columnstore_columns ADD INDEX `dictionary_object_id` (`dictionary_object_id`); + CREATE TABLE columnstore_info.columnstore_files engine=myisam as (select * from information_schema.columnstore_files); + ALTER TABLE columnstore_info.columnstore_files ADD INDEX `object_id` (`object_id`); IF t_name IS NOT NULL THEN - SELECT TABLE_SCHEMA, TABLE_NAME, format_filesize(sum(cf.file_size)) DATA_DISK_USAGE, format_filesize(sum(IFNULL(ccf.file_size, 0))) DICT_DISK_USAGE, format_filesize(sum(cf.file_size) + sum(IFNULL(ccf.file_size, 0))) TOTAL_USAGE FROM INFORMATION_SCHEMA.COLUMNSTORE_COLUMNS cc -JOIN INFORMATION_SCHEMA.COLUMNSTORE_FILES cf ON cc.object_id = cf.object_id -LEFT JOIN INFORMATION_SCHEMA.COLUMNSTORE_FILES ccf ON cc.dictionary_object_id = ccf.object_id -WHERE table_name = t_name and (table_schema = t_schema or t_schema IS NULL) GROUP BY table_schema, table_name; +SELECT TABLE_SCHEMA, TABLE_NAME, data as DATA_DISK_USAGE, dict as DICT_DISK_USAGE, data + dict as TOTAL_USAGE FROM ( +SELECT TABLE_SCHEMA, TABLE_NAME, (SELECT sum(cf.file_size) as data FROM columnstore_info.columnstore_columns cc JOIN columnstore_info.columnstore_files cf ON cc.object_id = cf.object_id WHERE table_name = ics.table_name and table_schema = ics.table_schema) as data, (SELECT sum(cf.file_size) as dict FROM columnstore_info.columnstore_columns cc JOIN columnstore_info.columnstore_files cf ON cc.dictionary_object_id = cf.object_id WHERE table_name = ics.table_name and table_schema = ics.table_schema GROUP BY table_schema, table_name) as dict +FROM +columnstore_info.columnstore_columns ics where table_name = t_name and (table_schema = t_schema or t_schema IS NULL) +group by table_schema, table_name +) q; ELSEIF t_schema IS NOT NULL THEN - SELECT TABLE_SCHEMA, TABLE_NAME, format_filesize(sum(cf.file_size)) DATA_DISK_USAGE, format_filesize(sum(IFNULL(ccf.file_size, 0))) DICT_DISK_USAGE, format_filesize(sum(cf.file_size) + sum(IFNULL(ccf.file_size, 0))) TOTAL_USAGE FROM INFORMATION_SCHEMA.COLUMNSTORE_COLUMNS cc -JOIN INFORMATION_SCHEMA.COLUMNSTORE_FILES cf ON cc.object_id = cf.object_id -LEFT JOIN INFORMATION_SCHEMA.COLUMNSTORE_FILES ccf ON cc.dictionary_object_id = ccf.object_id -WHERE table_schema = t_schema GROUP BY table_schema, table_name; +SELECT TABLE_SCHEMA, TABLE_NAME, data as DATA_DISK_USAGE, dict as DICT_DISK_USAGE, data + dict as TOTAL_USAGE FROM ( +SELECT TABLE_SCHEMA, TABLE_NAME, (SELECT sum(cf.file_size) as data FROM columnstore_info.columnstore_columns cc JOIN columnstore_info.columnstore_files cf ON cc.object_id = cf.object_id WHERE table_name = ics.table_name and table_schema = ics.table_schema) as data, (SELECT sum(cf.file_size) as dict FROM columnstore_info.columnstore_columns cc JOIN columnstore_info.columnstore_files cf ON cc.dictionary_object_id = cf.object_id WHERE table_name = ics.table_name and table_schema = ics.table_schema GROUP BY table_schema, table_name) as dict +FROM +columnstore_info.columnstore_columns ics where table_schema = t_schema +group by table_schema, table_name +) q; ELSE - SELECT TABLE_SCHEMA, TABLE_NAME, format_filesize(sum(cf.file_size)) DATA_DISK_USAGE, format_filesize(sum(IFNULL(ccf.file_size, 0))) DICT_DISK_USAGE, format_filesize(sum(cf.file_size) + sum(IFNULL(ccf.file_size, 0))) TOTAL_USAGE FROM INFORMATION_SCHEMA.COLUMNSTORE_COLUMNS cc -JOIN INFORMATION_SCHEMA.COLUMNSTORE_FILES cf ON cc.object_id = cf.object_id -LEFT JOIN INFORMATION_SCHEMA.COLUMNSTORE_FILES ccf ON cc.dictionary_object_id = ccf.object_id -GROUP BY table_schema, table_name; +SELECT TABLE_SCHEMA, TABLE_NAME, data as DATA_DISK_USAGE, dict as DICT_DISK_USAGE, data + dict as TOTAL_USAGE FROM ( +SELECT TABLE_SCHEMA, TABLE_NAME, (SELECT sum(cf.file_size) as data FROM columnstore_info.columnstore_columns cc JOIN columnstore_info.columnstore_files cf ON cc.object_id = cf.object_id WHERE table_name = ics.table_name and table_schema = ics.table_schema) as data, (SELECT sum(cf.file_size) as dict FROM columnstore_info.columnstore_columns cc JOIN columnstore_info.columnstore_files cf ON cc.dictionary_object_id = cf.object_id WHERE table_name = ics.table_name and table_schema = ics.table_schema GROUP BY table_schema, table_name) as dict +FROM +columnstore_info.columnstore_columns ics +group by table_schema, table_name +) q; END IF; + DROP TABLE IF EXISTS columnstore_info.columnstore_columns; + DROP TABLE IF EXISTS columnstore_info.columnstore_files; END // +DROP PROCEDURE IF EXISTS `compression_ratio` // + CREATE PROCEDURE compression_ratio() BEGIN SELECT CONCAT(((sum(compressed_data_size) / sum(data_size)) * 100), '%') COMPRESSION_RATIO FROM INFORMATION_SCHEMA.COLUMNSTORE_EXTENTS ce From 4b2b83acd99a9be2f9d03614733dd924834f0e29 Mon Sep 17 00:00:00 2001 From: david hill Date: Wed, 25 Jan 2017 12:28:20 -0600 Subject: [PATCH 16/35] no change, buildbot test check-in --- build/build_rpms | 1 + 1 file changed, 1 insertion(+) diff --git a/build/build_rpms b/build/build_rpms index b3f4ea951..673363bf1 100755 --- a/build/build_rpms +++ b/build/build_rpms @@ -4,6 +4,7 @@ # verbose=0 + prefix=/usr/local/mariadb/columnstore #mysqldir=$prefix/mariadb-columnstore/mysql columnstoredir=$prefix From 106a62222ca0d4bad13e7f4f68588332a1cbe8ad Mon Sep 17 00:00:00 2001 From: Andrew Hutchings Date: Wed, 25 Jan 2017 19:34:46 +0000 Subject: [PATCH 17/35] MCOL-533 Add lock to table_usage Calling from multiple connections simultaneously is bad. This adds a lock preventing that. --- dbcon/mysql/columnstore_info.sql | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/dbcon/mysql/columnstore_info.sql b/dbcon/mysql/columnstore_info.sql index d8a9cba4b..63c669500 100644 --- a/dbcon/mysql/columnstore_info.sql +++ b/dbcon/mysql/columnstore_info.sql @@ -35,7 +35,15 @@ END // DROP PROCEDURE IF EXISTS `table_usage` // CREATE PROCEDURE table_usage (IN t_schema char(64), IN t_name char(64)) -BEGIN +`table_usage`: BEGIN + + DECLARE `locker` TINYINT UNSIGNED DEFAULT IS_USED_LOCK('table_usage'); + + IF `locker` IS NOT NULL THEN + SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = 'Error acuqiring table_usage lock'; + LEAVE `table_usage`; + END IF; + DO GET_LOCK('table_usage', 0); DROP TABLE IF EXISTS columnstore_info.columnstore_columns; DROP TABLE IF EXISTS columnstore_info.columnstore_files; CREATE TABLE columnstore_info.columnstore_columns engine=myisam as (select * from information_schema.columnstore_columns); @@ -67,6 +75,7 @@ group by table_schema, table_name END IF; DROP TABLE IF EXISTS columnstore_info.columnstore_columns; DROP TABLE IF EXISTS columnstore_info.columnstore_files; + DO RELEASE_LOCK('table_usage'); END // DROP PROCEDURE IF EXISTS `compression_ratio` // From 00adccdcaaa965b4b57afd65ed8f716d54da1ef0 Mon Sep 17 00:00:00 2001 From: Andrew Hutchings Date: Wed, 25 Jan 2017 21:32:11 +0000 Subject: [PATCH 18/35] MCOL-317 Fix out of tree builds Make linking with libmysqlclient work with out of tree builds --- dbcon/joblist/CMakeLists.txt | 2 +- utils/querystats/CMakeLists.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/dbcon/joblist/CMakeLists.txt b/dbcon/joblist/CMakeLists.txt index bebe6584a..7fac3a859 100644 --- a/dbcon/joblist/CMakeLists.txt +++ b/dbcon/joblist/CMakeLists.txt @@ -61,7 +61,7 @@ set(joblist_LIB_SRCS add_library(joblist SHARED ${joblist_LIB_SRCS}) -target_link_libraries(joblist ${NETSNMP_LIBRARIES} -L${SERVER_SOURCE_ROOT_DIR}/libmysql/ libmysqlclient_r.so) +target_link_libraries(joblist ${NETSNMP_LIBRARIES} -L${SERVER_BUILD_INCLUDE_DIR}/../libmysql/ libmysqlclient_r.so) set_target_properties(joblist PROPERTIES VERSION 1.0.0 SOVERSION 1) diff --git a/utils/querystats/CMakeLists.txt b/utils/querystats/CMakeLists.txt index 001211834..935898818 100644 --- a/utils/querystats/CMakeLists.txt +++ b/utils/querystats/CMakeLists.txt @@ -8,7 +8,7 @@ set(querystats_LIB_SRCS querystats.cpp) add_library(querystats SHARED ${querystats_LIB_SRCS}) -target_link_libraries(querystats -L${SERVER_SOURCE_ROOT_DIR}/libmysql/ libmysqlclient_r.so) +target_link_libraries(querystats -L${SERVER_BUILD_INCLUDE_DIR}/../libmysql/ libmysqlclient_r.so) set_target_properties(querystats PROPERTIES VERSION 1.0.0 SOVERSION 1) From 5cd07838f0cc0dedaac793fd5e816508cc3ca55d Mon Sep 17 00:00:00 2001 From: Andrew Hutchings Date: Thu, 26 Jan 2017 16:20:45 +0000 Subject: [PATCH 19/35] MCOL-317 fix RPM building Removed lib needs to be removed from RPM file list too --- cpackEngineRPM.cmake | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/cpackEngineRPM.cmake b/cpackEngineRPM.cmake index 6df8f1a21..e284458a3 100644 --- a/cpackEngineRPM.cmake +++ b/cpackEngineRPM.cmake @@ -81,7 +81,7 @@ IF (EXISTS "/etc/redhat-release") set(REDHAT_VERSION_NUMBER "${CMAKE_MATCH_1}") ENDIF () if (${REDHAT_VERSION_NUMBER} EQUAL 6) - SETA(CPACK_RPM_platform_PACKAGE_REQUIRES "expect" "mariadb-columnstore-libs") + SETA(CPACK_RPM_platform_PACKAGE_REQUIRES "expect" "mariadb-columnstore-libs" "snappy") # Disable auto require as this will also try to pull Boost via RPM SET(CPACK_RPM_PACKAGE_AUTOREQPROV " no") else () @@ -291,9 +291,6 @@ SET(CPACK_RPM_libs_USER_FILELIST "/usr/local/mariadb/columnstore/lib/libbatchloader.so.1.0.0" "/usr/local/mariadb/columnstore/lib/libbatchloader.so.1" "/usr/local/mariadb/columnstore/lib/libbatchloader.so" -"/usr/local/mariadb/columnstore/lib/libmysqlcl_idb.so.1.0.0" -"/usr/local/mariadb/columnstore/lib/libmysqlcl_idb.so.1" -"/usr/local/mariadb/columnstore/lib/libmysqlcl_idb.so" "/usr/local/mariadb/columnstore/lib/libquerystats.so.1.0.0" "/usr/local/mariadb/columnstore/lib/libquerystats.so.1" "/usr/local/mariadb/columnstore/lib/libquerystats.so" From 130526477703cb7ee13fe18ccf84d7dd1b45c6df Mon Sep 17 00:00:00 2001 From: david hill Date: Wed, 1 Feb 2017 16:49:45 -0600 Subject: [PATCH 20/35] buildbot check test --- build/mini-tests.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/build/mini-tests.sh b/build/mini-tests.sh index e270a7ddc..af4f02afd 100755 --- a/build/mini-tests.sh +++ b/build/mini-tests.sh @@ -1,5 +1,6 @@ #!/bin/bash + prefix=/usr/local for arg in "$@"; do if [ `expr -- "$arg" : '--prefix='` -eq 9 ]; then From 5413ea56aff40b8002b446ae86d9add1afb77b87 Mon Sep 17 00:00:00 2001 From: David Hill Date: Mon, 6 Feb 2017 08:32:33 -0600 Subject: [PATCH 21/35] buildbot kickoff test --- build/build_rpms | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build/build_rpms b/build/build_rpms index 673363bf1..7af7e689b 100755 --- a/build/build_rpms +++ b/build/build_rpms @@ -1,6 +1,6 @@ #!/bin/bash # -# $Id: build_rpms 1734 2012-10-25 18:07:16Z dhill $ +# $Id: build_rpms 1734 2012-10-25 18:07:16Z dlhill $ # verbose=0 From 29785cf20273d55455e18e99d24d6ce37e4e0ea3 Mon Sep 17 00:00:00 2001 From: David Hall Date: Mon, 6 Feb 2017 12:05:49 -0600 Subject: [PATCH 22/35] MCOL-480 remove the annoying warning log message. This code path is normal and shouldn't log anyything. --- utils/messageqcpp/inetstreamsocket.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/utils/messageqcpp/inetstreamsocket.cpp b/utils/messageqcpp/inetstreamsocket.cpp index 57c863aea..bfbb291b3 100644 --- a/utils/messageqcpp/inetstreamsocket.cpp +++ b/utils/messageqcpp/inetstreamsocket.cpp @@ -436,15 +436,15 @@ const SBS InetStreamSocket::read(const struct ::timespec* timeout, bool* isTimeO uint8_t* msglenp = reinterpret_cast(&msglen); size_t mlread = 0; - bool myIsTimeOut = false; - if (readToMagic(msecs, &myIsTimeOut, stats) == false) //indicates a timeout or EOF + if (readToMagic(msecs, isTimeOut, stats) == false) //indicates a timeout or EOF { - if (!myIsTimeOut) - logIoError("InetStreamSocket::read: EOF during readToMagic", 0); - if (isTimeOut) - { - *isTimeOut = myIsTimeOut; - } + // MCOL-480 The connector calls with timeout in a loop so that + // it can check a killed flag. This means that for a long running query, + // the following fills the warning log. +// if (isTimeOut && *isTimeOut) +// { +// logIoError("InetStreamSocket::read: timeout during readToMagic", 0); +// } return SBS(new ByteStream(0)); } From c2344accc95ce84b9a489b0b4b33d3644346c5db Mon Sep 17 00:00:00 2001 From: David Hall Date: Thu, 9 Feb 2017 17:54:18 -0600 Subject: [PATCH 23/35] MCOL-513 clean up and test thread pool for ExeMgr --- dbcon/joblist/joblist.cpp | 5 +-- dbcon/joblist/jobstep.cpp | 2 +- dbcon/joblist/jobstep.h | 2 +- dbcon/joblist/pdictionary.cpp | 2 + dbcon/joblist/primitivestep.h | 6 +-- dbcon/joblist/tupleaggregatestep.cpp | 19 +++++--- dbcon/mysql/ha_calpont_execplan.cpp | 2 +- exemgr/main.cpp | 10 ++++- utils/threadpool/threadpool.cpp | 66 +++++++++++++++++++++++----- utils/threadpool/threadpool.h | 37 +++++++++++++++- 10 files changed, 121 insertions(+), 30 deletions(-) diff --git a/dbcon/joblist/joblist.cpp b/dbcon/joblist/joblist.cpp index 833c4447d..286c733bf 100644 --- a/dbcon/joblist/joblist.cpp +++ b/dbcon/joblist/joblist.cpp @@ -81,7 +81,7 @@ JobList::~JobList() { JobStepVector::iterator iter; JobStepVector::iterator end; - +#if 0 iter = fQuery.begin(); end = fQuery.end(); @@ -108,7 +108,7 @@ JobList::~JobList() joiners[i]->join(); delete joiners[i]; } -#if 0 +#endif // Stop all the query steps end = fQuery.end(); for (iter = fQuery.begin(); iter != end; ++iter) @@ -136,7 +136,6 @@ JobList::~JobList() { (*iter)->join(); } -#endif } } catch (exception& ex) diff --git a/dbcon/joblist/jobstep.cpp b/dbcon/joblist/jobstep.cpp index a84d665f8..825512219 100644 --- a/dbcon/joblist/jobstep.cpp +++ b/dbcon/joblist/jobstep.cpp @@ -20,6 +20,7 @@ #include using namespace std; +#include #include #include #include @@ -102,7 +103,6 @@ JobStep::JobStep(const JobInfo& j) : fQtc.serverParms(tsp); //fStepUuid = bu::random_generator()(); fStepUuid = QueryTeleClient::genUUID(); - jobstepThreadPool.setDebug(true); } //------------------------------------------------------------------------------ diff --git a/dbcon/joblist/jobstep.h b/dbcon/joblist/jobstep.h index 899a131d7..5763ce782 100644 --- a/dbcon/joblist/jobstep.h +++ b/dbcon/joblist/jobstep.h @@ -234,8 +234,8 @@ public: bool onClauseFilter() const { return fOnClauseFilter; } void onClauseFilter(bool b) { fOnClauseFilter = b; } -protected: static ThreadPool jobstepThreadPool; +protected: //@bug6088, for telemetry posting static const int64_t STEP_TELE_INTERVAL = 5000; // now, this is the browser refresh rate diff --git a/dbcon/joblist/pdictionary.cpp b/dbcon/joblist/pdictionary.cpp index 5397974c0..c85240064 100644 --- a/dbcon/joblist/pdictionary.cpp +++ b/dbcon/joblist/pdictionary.cpp @@ -105,6 +105,8 @@ pDictionaryStep::pDictionaryStep( recvWaiting(false), ridCount(0), fColType(ct), + pThread(0), + cThread(0), fFilterCount(0), requestList(0), fInterval(jobInfo.flushInterval), diff --git a/dbcon/joblist/primitivestep.h b/dbcon/joblist/primitivestep.h index 5e1006e2c..a0f48c3c4 100644 --- a/dbcon/joblist/primitivestep.h +++ b/dbcon/joblist/primitivestep.h @@ -636,8 +636,8 @@ private: uint32_t recvWaiting; int64_t ridCount; execplan::CalpontSystemCatalog::ColType fColType; - boost::shared_ptr pThread; //producer thread - boost::shared_ptr cThread; //producer thread + uint64_t pThread; //producer thread + uint64_t cThread; //producer thread messageqcpp::ByteStream fFilterString; uint32_t fFilterCount; @@ -1331,7 +1331,7 @@ private: bool isDictColumn; bool isEM; - boost::thread* fPTThd; +// boost::thread* fPTThd; // @bug 663 - Added fSwallowRows for calpont.caltrace(16) which is TRACE_FLAGS::TRACE_NO_ROWS4. // Running with this one will swallow rows at projection. diff --git a/dbcon/joblist/tupleaggregatestep.cpp b/dbcon/joblist/tupleaggregatestep.cpp index ced92856d..6b355c59b 100644 --- a/dbcon/joblist/tupleaggregatestep.cpp +++ b/dbcon/joblist/tupleaggregatestep.cpp @@ -4211,12 +4211,14 @@ void TupleAggregateStep::threadedAggregateRowGroups(uint32_t threadID) // and if there is more data to read, the // first thread will start another thread until the // maximum number is reached. +#if 0 if (threadID == 0 && fFirstPhaseThreadCount < fNumOfThreads && - dlIn->more(fInputIter)) { + dlIn->more(fInputIter)) + { fFirstPhaseRunners.push_back(jobstepThreadPool.invoke(ThreadedAggregator(this, fFirstPhaseThreadCount))); fFirstPhaseThreadCount++; } - +#endif fRowGroupIns[threadID].setData(&rgData); fMemUsage[threadID] += fRowGroupIns[threadID].getSizeWithStrings(); if (!fRm->getMemory(fRowGroupIns[threadID].getSizeWithStrings(), fSessionMemLimit)) @@ -4479,22 +4481,25 @@ uint64_t TupleAggregateStep::doThreadedAggregate(ByteStream& bs, RowGroupDL* dlp if (!fDoneAggregate) { initializeMultiThread(); -/* -// This block of code starts all threads at the start + +// This block of code starts all threads at the start fFirstPhaseThreadCount = fNumOfThreads; - boost::shared_ptr runner; + fFirstPhaseRunners.clear(); + fFirstPhaseRunners.reserve(fNumOfThreads); // to prevent a resize during use for (i = 0; i < fNumOfThreads; i++) { - fFirstPhaseRunners.push_back(jobstepThreadPool.invoke(ThreadedAggregator(this, i))) + fFirstPhaseRunners.push_back(jobstepThreadPool.invoke(ThreadedAggregator(this, i))); } -*/ +#if 0 // This block of code starts one thread, relies on doThreadedAggregation() +// For reasons unknown, this doesn't work right with threadpool // to start more as needed fFirstPhaseRunners.clear(); fFirstPhaseRunners.reserve(fNumOfThreads); // to prevent a resize during use fFirstPhaseThreadCount = 1; fFirstPhaseRunners.push_back(jobstepThreadPool.invoke(ThreadedAggregator(this, 0))); +#endif // Now wait for that thread plus all the threads it may have spawned jobstepThreadPool.join(fFirstPhaseRunners); diff --git a/dbcon/mysql/ha_calpont_execplan.cpp b/dbcon/mysql/ha_calpont_execplan.cpp index 22aa4742b..27ee355ff 100755 --- a/dbcon/mysql/ha_calpont_execplan.cpp +++ b/dbcon/mysql/ha_calpont_execplan.cpp @@ -6355,7 +6355,7 @@ int getSelectPlan(gp_walk_info& gwi, SELECT_LEX& select_lex, SCSEP& csep, bool i // select * from derived table case if (gwi.selectCols.empty()) sel_cols_in_create = " * "; - create_query = "create temporary table " + vtb.str() + " as select " + sel_cols_in_create + " from "; + create_query = "create temporary table " + vtb.str() + " engine = aria as select " + sel_cols_in_create + " from "; TABLE_LIST* table_ptr = select_lex.get_table_list(); bool firstTb = true; diff --git a/exemgr/main.cpp b/exemgr/main.cpp index 2f6a6d431..b2862e875 100644 --- a/exemgr/main.cpp +++ b/exemgr/main.cpp @@ -1433,13 +1433,19 @@ int main(int argc, char* argv[]) } } +// if (!JobStep::jobstepThreadPool.debug()) +// { +// JobStep::jobstepThreadPool.setName("ExeMgr"); +// JobStep::jobstepThreadPool.setDebug(true); +// JobStep::jobstepThreadPool.invoke(ThreadPoolMonitor(&JobStep::jobstepThreadPool)); +// } + threadpool::ThreadPool exeMgrThreadPool(serverThreads, serverQueueSize); for (;;) { IOSocket ios; ios = mqs->accept(); - boost::thread thd(SessionThread(ios, ec, rm)); - //exeMgrThreadPool.invoke(SessionThread(ios, ec, rm)); + exeMgrThreadPool.invoke(SessionThread(ios, ec, rm)); } exeMgrThreadPool.wait(); diff --git a/utils/threadpool/threadpool.cpp b/utils/threadpool/threadpool.cpp index 644e9d098..d180dc4cb 100644 --- a/utils/threadpool/threadpool.cpp +++ b/utils/threadpool/threadpool.cpp @@ -27,10 +27,9 @@ using namespace std; #include "messagelog.h" using namespace logging; -#define THREADPOOL_DLLEXPORT #include "threadpool.h" -#undef THREADPOOL_DLLEXPORT - +#include +#include namespace threadpool { @@ -69,6 +68,7 @@ void ThreadPool::init() fFunctorErrors = 0; waitingFunctorsSize = 0; issued = 0; + fDebug = false; fStop = false; // fThreadCreated = new NoOp(); fNextFunctor = fWaitingFunctors.end(); @@ -213,14 +213,12 @@ uint64_t ThreadPool::invoke(const Functor_T &threadfunc) if (fDebug) { + ostringstream oss; + oss << "invoke: Starting thread " << fThreadCount << " max " << fMaxThreads + << " queue " << fQueueSize; logging::Message::Args args; - logging::Message message(5); - args.add("invoke: Starting thread "); - args.add(fThreadCount); - args.add(" max "); - args.add(fMaxThreads); - args.add(" queue "); - args.add(fQueueSize); + logging::Message message(0); + args.add(oss.str()); message.format( args ); logging::LoggingID lid(22); logging::MessageLog ml(lid); @@ -255,8 +253,8 @@ uint64_t ThreadPool::invoke(const Functor_T &threadfunc) logging::LoggingID lid(22); logging::MessageLog ml(lid); ml.logWarningMessage( message ); - fThreadAvailable.wait(lock1); } + fThreadAvailable.wait(lock1); } catch(...) { @@ -414,4 +412,50 @@ void ThreadPool::dump() std::cout << "Waiting functors: " << fWaitingFunctors.size() << std::endl; } + +void ThreadPoolMonitor::operator()() +{ + ostringstream filename; + filename << "/var/log/mariadb/columnstore/trace/ThreadPool_" << fPool->name() << ".log"; + fLog = new ofstream(filename.str().c_str()); + for (;;) + { + if (!fLog || !fLog->is_open()) + { + ostringstream oss; + oss << "ThreadPoolMonitor " << fPool->name() << " has no file "; + logging::Message::Args args; + logging::Message message(0); + args.add(oss.str()); + message.format( args ); + logging::LoggingID lid(22); + logging::MessageLog ml(lid); + ml.logWarningMessage( message ); + return; + } + // Get a timestamp for output. + struct tm tm; + struct timeval tv; + + gettimeofday(&tv, 0); + localtime_r(&tv.tv_sec, &tm); + + (*fLog) << setfill('0') + << setw(2) << tm.tm_hour << ':' + << setw(2) << tm.tm_min << ':' + << setw(2) << tm.tm_sec + << '.' + << setw(4) << tv.tv_usec/100 + << " Name " << fPool->fName + << " Active " << fPool->waitingFunctorsSize + << " Most " << fPool->fThreadCount + << " Max " << fPool->fMaxThreads + << " Q " << fPool->fQueueSize + << endl; + +// struct timespec req = { 0, 1000 * 100 }; //100 usec +// nanosleep(&req, 0); + sleep(2); + } +} } // namespace threadpool diff --git a/utils/threadpool/threadpool.h b/utils/threadpool/threadpool.h index 7616090fe..22c138e0b 100644 --- a/utils/threadpool/threadpool.h +++ b/utils/threadpool/threadpool.h @@ -31,7 +31,7 @@ #define THREADPOOL_H #include -#include +#include #include #include #include @@ -153,8 +153,16 @@ public: */ EXPORT void dump(); + EXPORT std::string& name() {return fName;} + + EXPORT void setName(std::string name) {fName = name;} + EXPORT void setName(const char* name) {fName = name;} + + EXPORT bool debug() {return fDebug;} + EXPORT void setDebug(bool d) {fDebug = d;} + friend class ThreadPoolMonitor; protected: private: @@ -224,9 +232,36 @@ private: uint32_t waitingFunctorsSize; uint64_t fNextHandle; + std::string fName; // Optional to add a name to the pool for debugging. bool fDebug; }; +// This class, if instantiated, will continuously log details about the indicated threadpool +// The log will end up in /var/log/mariadb/columnstore/trace/threadpool_.log +class ThreadPoolMonitor +{ +public: + ThreadPoolMonitor(ThreadPool* pool) : fPool(pool), fLog(NULL) + { + } + + ~ThreadPoolMonitor() + { + if (fLog) + { + delete fLog; + } + } + + void operator()(); +private: + //defaults okay + //ThreadPoolMonitor(const ThreadPoolMonitor& rhs); + //ThreadPoolMonitor& operator=(const ThreadPoolMonitor& rhs); + ThreadPool* fPool; + std::ofstream* fLog; +}; + } // namespace threadpool #undef EXPORT From e09b7e10c5338b11d32783697e80c10e80275449 Mon Sep 17 00:00:00 2001 From: David Hall Date: Mon, 13 Feb 2017 11:56:28 -0600 Subject: [PATCH 24/35] MCOL-513 Threadpool to unlimited threads when queuesize = 0. Idle down after 10 minutes --- dbcon/joblist/joblist.cpp | 2 +- dbcon/joblist/jobstep.cpp | 2 +- dbcon/joblist/resourcemanager.h | 13 +- exemgr/main.cpp | 21 +- oam/etc/Columnstore.xml | 5 +- oam/etc/Columnstore.xml.singleserver | 9 +- utils/threadpool/threadpool.cpp | 375 ++++++++++++++------------- utils/threadpool/threadpool.h | 13 +- 8 files changed, 236 insertions(+), 204 deletions(-) diff --git a/dbcon/joblist/joblist.cpp b/dbcon/joblist/joblist.cpp index 286c733bf..6e9607209 100644 --- a/dbcon/joblist/joblist.cpp +++ b/dbcon/joblist/joblist.cpp @@ -74,7 +74,7 @@ JobList::JobList(bool isEM) : JobList::~JobList() { vector joiners; - boost::thread *tmp; +// boost::thread *tmp; try { if (fIsRunning) diff --git a/dbcon/joblist/jobstep.cpp b/dbcon/joblist/jobstep.cpp index 825512219..94229871a 100644 --- a/dbcon/joblist/jobstep.cpp +++ b/dbcon/joblist/jobstep.cpp @@ -56,7 +56,7 @@ namespace joblist { boost::mutex JobStep::fLogMutex; //=PTHREAD_MUTEX_INITIALIZER; -ThreadPool JobStep::jobstepThreadPool(100,200); +ThreadPool JobStep::jobstepThreadPool(defaultJLThreadPoolSize, 0); ostream& operator<<(ostream& os, const JobStep* rhs) { diff --git a/dbcon/joblist/resourcemanager.h b/dbcon/joblist/resourcemanager.h index 8d31ba1c3..42ee6e569 100644 --- a/dbcon/joblist/resourcemanager.h +++ b/dbcon/joblist/resourcemanager.h @@ -60,7 +60,8 @@ namespace joblist const uint64_t defaultHUATotalMem = 8 * 1024 * 1024 * 1024ULL; const uint32_t defaultTupleDLMaxSize = 64 * 1024; - const uint32_t defaultTupleMaxBuckets = 256; + + const uint32_t defaultJLThreadPoolSize = 100; //pcolscan.cpp const uint32_t defaultScanLbidReqLimit = 10000; @@ -160,7 +161,7 @@ namespace joblist unsigned getHjNumThreads() const { return fHjNumThreads; } //getUintVal(fHashJoinStr, "NumThreads", defaultNumThreads); } uint64_t getHjMaxElems() const { return getUintVal(fHashJoinStr, "MaxElems", defaultHJMaxElems); } uint32_t getHjFifoSizeLargeSide() const { return getUintVal(fHashJoinStr, "FifoSizeLargeSide", defaultHJFifoSizeLargeSide); } - uint32_t getHjCPUniqueLimit() const { return getUintVal(fHashJoinStr, "CPUniqueLimit", defaultHjCPUniqueLimit); } + uint32_t getHjCPUniqueLimit() const { return getUintVal(fHashJoinStr, "CPUniqueLimit", defaultHjCPUniqueLimit); } uint64_t getPMJoinMemLimit() const { return pmJoinMemLimit; } uint32_t getJLFlushInterval() const { return getUintVal(fJobListStr, "FlushInterval", defaultFlushInterval); } @@ -168,6 +169,10 @@ namespace joblist uint32_t getJlScanLbidReqLimit() const { return getUintVal(fJobListStr, "ScanLbidReqLimit",defaultScanLbidReqLimit); } uint32_t getJlScanLbidReqThreshold() const { return getUintVal(fJobListStr,"ScanLbidReqThreshold", defaultScanLbidReqThreshold); } + // @MCOL-513 - Added threadpool to JobSteps + uint32_t getJLThreadPoolSize() const { return getUintVal(fJobListStr, "ThreadPoolSize", defaultJLThreadPoolSize); } + std::string getJlThreadPoolDebug() const { return getStringVal(fJobListStr, "ThreadPoolDebug", "N"); } + // @bug 1264 - Added LogicalBlocksPerScan configurable which determines the number of blocks contained in each BPS scan request. uint32_t getJlLogicalBlocksPerScan() const { return getUintVal(fJobListStr,"LogicalBlocksPerScan", defaultLogicalBlocksPerScan); } uint32_t getJlProjectBlockReqLimit() const { return getUintVal(fJobListStr, "ProjectBlockReqLimit", defaultProjectBlockReqLimit ); } @@ -180,9 +185,9 @@ namespace joblist uint32_t getJlMaxOutstandingRequests() const { return getUintVal(fJobListStr,"MaxOutstandingRequests", defaultMaxOutstandingRequests);} uint32_t getJlJoinerChunkSize() const { return getUintVal(fJobListStr,"JoinerChunkSize", defaultJoinerChunkSize);} - int getPsCount() const { return getUintVal(fPrimitiveServersStr, "Count", defaultPSCount ); } + int getPsCount() const { return getUintVal(fPrimitiveServersStr, "Count", defaultPSCount ); } int getPsConnectionsPerPrimProc() const { return getUintVal(fPrimitiveServersStr, "ConnectionsPerPrimProc", defaultConnectionsPerPrimProc); } - uint32_t getPsLBID_Shift() const { return getUintVal(fPrimitiveServersStr, "LBID_Shift", defaultLBID_Shift ); } + uint32_t getPsLBID_Shift() const { return getUintVal(fPrimitiveServersStr, "LBID_Shift", defaultLBID_Shift ); } std::string getScTempDiskPath() const { return getStringVal(fSystemConfigStr, "TempDiskPath", defaultTempDiskPath ); } uint64_t getScTempSaveSize() const { return getUintVal(fSystemConfigStr, "TempSaveSize", defaultTempSaveSize); } diff --git a/exemgr/main.cpp b/exemgr/main.cpp index b2862e875..0d97394a7 100644 --- a/exemgr/main.cpp +++ b/exemgr/main.cpp @@ -1393,6 +1393,20 @@ int main(int argc, char* argv[]) } } + // It's possible that PM modules use this threadpool. Only ExeMgr creates + // massive amounts of threads and needs to be settable. It's also possible that + // other process on this UM module use this threadpool. In this case, they share. + // We can't call rm functions during the static creation because rm has a isExeMgr + // flag that is set upon first creation. For the pool, who has no idea if it is ExeMgr, + // to create the singleton rm would be wrong, no matter which way we set the flag. + JobStep::jobstepThreadPool.setMaxThreads(rm->getJLThreadPoolSize()); + JobStep::jobstepThreadPool.setName("ExeMgr"); + if (rm->getJlThreadPoolDebug() == "Y" || rm->getJlThreadPoolDebug() == "y") + { + JobStep::jobstepThreadPool.setDebug(true); + JobStep::jobstepThreadPool.invoke(ThreadPoolMonitor(&JobStep::jobstepThreadPool)); + } + int serverThreads = rm->getEmServerThreads(); int serverQueueSize = rm->getEmServerQueueSize(); int maxPct = rm->getEmMaxPct(); @@ -1433,13 +1447,6 @@ int main(int argc, char* argv[]) } } -// if (!JobStep::jobstepThreadPool.debug()) -// { -// JobStep::jobstepThreadPool.setName("ExeMgr"); -// JobStep::jobstepThreadPool.setDebug(true); -// JobStep::jobstepThreadPool.invoke(ThreadPoolMonitor(&JobStep::jobstepThreadPool)); -// } - threadpool::ThreadPool exeMgrThreadPool(serverThreads, serverQueueSize); for (;;) { diff --git a/oam/etc/Columnstore.xml b/oam/etc/Columnstore.xml index f9ecbc116..1c68ca5cf 100644 --- a/oam/etc/Columnstore.xml +++ b/oam/etc/Columnstore.xml @@ -503,6 +503,7 @@ as many threads are available across all PMs. --> 20 + 100 1M @@ -515,9 +516,9 @@ - unassigned + 127.0.0.1 3306 - unassigned + root diff --git a/oam/etc/Columnstore.xml.singleserver b/oam/etc/Columnstore.xml.singleserver index 5324cb892..ff466c398 100644 --- a/oam/etc/Columnstore.xml.singleserver +++ b/oam/etc/Columnstore.xml.singleserver @@ -495,8 +495,9 @@ is 20 extents worth of work for the PMs to process at any given time. ProcessorThreadsPerScan * MaxOutstandingRequests should be at least as many threads are available across all PMs. --> - - 20 + + 20 + 100 1M @@ -509,9 +510,9 @@ - unassigned + 127.0.0.1 3306 - unassigned + root diff --git a/utils/threadpool/threadpool.cpp b/utils/threadpool/threadpool.cpp index d180dc4cb..41ab57065 100644 --- a/utils/threadpool/threadpool.cpp +++ b/utils/threadpool/threadpool.cpp @@ -30,35 +30,34 @@ using namespace logging; #include "threadpool.h" #include #include +#include "boost/date_time/posix_time/posix_time_types.hpp" + namespace threadpool { ThreadPool::ThreadPool() - :fMaxThreads( 0 ), fQueueSize( 0 ) +:fMaxThreads( 0 ), fQueueSize( 0 ) { init(); } ThreadPool::ThreadPool( size_t maxThreads, size_t queueSize ) - :fMaxThreads( maxThreads ), fQueueSize( queueSize ) + :fMaxThreads( maxThreads ), fQueueSize( queueSize ) { init(); - - if (fQueueSize == 0) - fQueueSize = fMaxThreads*2; } ThreadPool::~ThreadPool() throw() { -// delete fThreadCreated; try { stop(); } - catch(...) - {} + catch (...) + { + } } void ThreadPool::init() @@ -66,13 +65,12 @@ void ThreadPool::init() fThreadCount = 0; fGeneralErrors = 0; fFunctorErrors = 0; - waitingFunctorsSize = 0; - issued = 0; - fDebug = false; + waitingFunctorsSize = 0; + fIssued = 0; + fDebug = false; fStop = false; -// fThreadCreated = new NoOp(); fNextFunctor = fWaitingFunctors.end(); - fNextHandle=1; + fNextHandle=1; } void ThreadPool::setQueueSize(size_t queueSize) @@ -88,11 +86,6 @@ void ThreadPool::setMaxThreads(size_t maxThreads) fMaxThreads = maxThreads; } -void ThreadPool::setThreadCreatedListener(const Functor_T &f) -{ -// fThreadCreated = f; -} - void ThreadPool::stop() { boost::mutex::scoped_lock lock1(fMutex); @@ -111,7 +104,7 @@ void ThreadPool::wait() while (waitingFunctorsSize > 0) { fThreadAvailable.wait(lock1); - //cerr << "woke!" << endl; + //cerr << "woke!" << endl; } } @@ -121,22 +114,22 @@ void ThreadPool::join(uint64_t thrHandle) while (waitingFunctorsSize > 0) { - Container_T::iterator iter; - Container_T::iterator end = fWaitingFunctors.end(); - bool foundit = false; - for (iter = fWaitingFunctors.begin(); iter != end; ++iter) - { - foundit = false; - if (iter->hndl == thrHandle) - { - foundit = true; - break; - } - } - if (!foundit) - { - break; - } + Container_T::iterator iter; + Container_T::iterator end = fWaitingFunctors.end(); + bool foundit = false; + for (iter = fWaitingFunctors.begin(); iter != end; ++iter) + { + foundit = false; + if (iter->hndl == thrHandle) + { + foundit = true; + break; + } + } + if (!foundit) + { + break; + } fThreadAvailable.wait(lock1); } } @@ -147,32 +140,32 @@ void ThreadPool::join(std::vector thrHandle) while (waitingFunctorsSize > 0) { - Container_T::iterator iter; - Container_T::iterator end = fWaitingFunctors.end(); - bool foundit = false; - for (iter = fWaitingFunctors.begin(); iter != end; ++iter) - { - foundit = false; - std::vector::iterator thrIter; - std::vector::iterator thrEnd = thrHandle.end(); - for (thrIter = thrHandle.begin(); thrIter != thrEnd; ++thrIter) - { - if (iter->hndl == *thrIter) - { - foundit = true; - break; - } - } - if (foundit == true) - { - break; - } - } - // If we didn't find any of the handles, then all are complete - if (!foundit) - { - break; - } + Container_T::iterator iter; + Container_T::iterator end = fWaitingFunctors.end(); + bool foundit = false; + for (iter = fWaitingFunctors.begin(); iter != end; ++iter) + { + foundit = false; + std::vector::iterator thrIter; + std::vector::iterator thrEnd = thrHandle.end(); + for (thrIter = thrHandle.begin(); thrIter != thrEnd; ++thrIter) + { + if (iter->hndl == *thrIter) + { + foundit = true; + break; + } + } + if (foundit == true) + { + break; + } + } + // If we didn't find any of the handles, then all are complete + if (!foundit) + { + break; + } fThreadAvailable.wait(lock1); } } @@ -180,13 +173,12 @@ void ThreadPool::join(std::vector thrHandle) uint64_t ThreadPool::invoke(const Functor_T &threadfunc) { boost::mutex::scoped_lock lock1(fMutex); - uint64_t thrHandle=0; - for(;;) + uint64_t thrHandle=0; + for (;;) { - try { - if ( waitingFunctorsSize < fThreadCount) + if (waitingFunctorsSize < fThreadCount) { // Don't create a thread unless it's needed. There // is a thread available to service this request. @@ -197,33 +189,34 @@ uint64_t ThreadPool::invoke(const Functor_T &threadfunc) bool bAdded = false; - if ( waitingFunctorsSize < fQueueSize) + if (waitingFunctorsSize < fQueueSize || fQueueSize == 0) { // Don't create a thread unless you have to thrHandle = addFunctor(threadfunc); bAdded = true; } - if ( fThreadCount < fMaxThreads) + // fQueueSize = 0 disables the queue and is an indicator to allow any number of threads to actually run. + if (fThreadCount < fMaxThreads || fQueueSize == 0) { ++fThreadCount; lock1.unlock(); fThreads.create_thread(beginThreadFunc(*this)); - - if (fDebug) - { - ostringstream oss; - oss << "invoke: Starting thread " << fThreadCount << " max " << fMaxThreads - << " queue " << fQueueSize; - logging::Message::Args args; - logging::Message message(0); - args.add(oss.str()); - message.format( args ); - logging::LoggingID lid(22); - logging::MessageLog ml(lid); - ml.logWarningMessage( message ); - } + + if (fDebug) + { + ostringstream oss; + oss << "invoke: Starting thread " << fThreadCount << " max " << fMaxThreads + << " queue " << fQueueSize; + logging::Message::Args args; + logging::Message message(0); + args.add(oss.str()); + message.format( args ); + logging::LoggingID lid(22); + logging::MessageLog ml(lid); + ml.logWarningMessage( message ); + } if (bAdded) break; @@ -241,22 +234,22 @@ uint64_t ThreadPool::invoke(const Functor_T &threadfunc) break; } - if (fDebug) - { - logging::Message::Args args; - logging::Message message(5); - args.add("invoke: Blocked waiting for thread. Count "); - args.add(fThreadCount); - args.add("max "); - args.add(fMaxThreads); - message.format( args ); - logging::LoggingID lid(22); - logging::MessageLog ml(lid); - ml.logWarningMessage( message ); - } - fThreadAvailable.wait(lock1); + if (fDebug) + { + logging::Message::Args args; + logging::Message message(5); + args.add("invoke: Blocked waiting for thread. Count "); + args.add(fThreadCount); + args.add("max "); + args.add(fMaxThreads); + message.format( args ); + logging::LoggingID lid(22); + logging::MessageLog ml(lid); + ml.logWarningMessage( message ); + } + fThreadAvailable.wait(lock1); } - catch(...) + catch (...) { ++fGeneralErrors; throw; @@ -264,18 +257,16 @@ uint64_t ThreadPool::invoke(const Functor_T &threadfunc) } fNeedThread.notify_one(); - return thrHandle; + return thrHandle; } void ThreadPool::beginThread() throw() { try { -// fThreadCreated(); - boost::mutex::scoped_lock lock1(fMutex); - - for(;;) + boost::system_time timeout = boost::get_system_time()+boost::posix_time::minutes(10); + for (;;) { if (fStop) break; @@ -283,51 +274,80 @@ void ThreadPool::beginThread() throw() if (fNextFunctor == fWaitingFunctors.end()) { // Wait until someone needs a thread - fNeedThread.wait(lock1); + // Add the timed waait for queueSize == 0 so we can idle away threads + // over fMaxThreads + if (fQueueSize > 0) + { + fNeedThread.wait(lock1); + } + else + { + // Wait no more than 10 minutes + if (fNeedThread.timed_wait(lock1, timeout) == boost::cv_status::timeout) + { + if (fThreadCount > fMaxThreads) + { + --fThreadCount; + return; + } + } + } } else { - /* Need to tune these magic #s */ + /* Need to tune these magic #s */ + vector todoList; + int i, num; + Container_T::const_iterator iter; - vector todoList; - int i, num; - Container_T::const_iterator iter; + /* Use num to control how many jobs are issued to a single thread + should you want to batch more than one */ + num = (waitingFunctorsSize - fIssued >= 1 ? 1 : 0); - /* Use this to control how many jobs are issued to a single thread */ - num = (waitingFunctorsSize - issued >= 1 ? 1 : 0); + for (i = 0; i < num; i++) + todoList.push_back(fNextFunctor++); - for (i = 0; i < num; i++) - todoList.push_back(fNextFunctor++); - - issued += num; + fIssued += num; // cerr << "got " << num << " jobs." << endl; // cerr << "got " << num << " jobs. waitingFunctorsSize=" << -// waitingFunctorsSize << " issued=" << issued << " fThreadCount=" << +// waitingFunctorsSize << " fIssued=" << fIssued << " fThreadCount=" << // fThreadCount << endl; lock1.unlock(); - for (i = 0; i < num; i++) { - try { - (*todoList[i]).functor(); - } - catch(exception &e) { - ++fFunctorErrors; - cerr << e.what() << endl; - } - } - lock1.lock(); + for (i = 0; i < num; i++) + { + try + { + (*todoList[i]).functor(); + } + catch (exception &e) + { + ++fFunctorErrors; +#ifndef NOLOGGING + logging::Message::Args args; + logging::Message message(5); + args.add("ThreadPool: Caught exception during execution: "); + args.add(e.what()); + message.format( args ); + logging::LoggingID lid(22); + logging::MessageLog ml(lid); + ml.logErrorMessage( message ); +#endif + } + } + lock1.lock(); - issued -= num; - waitingFunctorsSize -= num; - for (i = 0; i < num; i++) - fWaitingFunctors.erase(todoList[i]); + fIssued -= num; + waitingFunctorsSize -= num; + for (i = 0; i < num; i++) + fWaitingFunctors.erase(todoList[i]); /* - if (waitingFunctorsSize != fWaitingFunctors.size()) - cerr << "size mismatch! fake size=" << waitingFunctorsSize << - " real size=" << fWaitingFunctors.size() << endl; + if (waitingFunctorsSize != fWaitingFunctors.size()) + cerr << "size mismatch! fake size=" << waitingFunctorsSize << + " real size=" << fWaitingFunctors.size() << endl; */ + timeout = boost::get_system_time()+boost::posix_time::minutes(10); fThreadAvailable.notify_all(); - } } } @@ -353,12 +373,12 @@ void ThreadPool::beginThread() throw() ml.logErrorMessage( message ); #endif } - catch(...) + catch (...) { } } - catch(...) + catch (...) { ++fGeneralErrors; @@ -379,7 +399,7 @@ void ThreadPool::beginThread() throw() ml.logErrorMessage( message ); #endif } - catch(...) + catch (...) { } } @@ -393,16 +413,16 @@ uint64_t ThreadPool::addFunctor(const Functor_T &func) bAtEnd = true; // PoolFunction_T poolFunction(fNextHandle, func); - PoolFunction_T poolFunction; - poolFunction.hndl = fNextHandle; - poolFunction.functor = func; - fWaitingFunctors.push_back(poolFunction); - waitingFunctorsSize++; + PoolFunction_T poolFunction; + poolFunction.hndl = fNextHandle; + poolFunction.functor = func; + fWaitingFunctors.push_back(poolFunction); + waitingFunctorsSize++; if (bAtEnd) { --fNextFunctor; } - return fNextHandle++; + return fNextHandle++; } void ThreadPool::dump() @@ -415,47 +435,48 @@ void ThreadPool::dump() void ThreadPoolMonitor::operator()() { - ostringstream filename; - filename << "/var/log/mariadb/columnstore/trace/ThreadPool_" << fPool->name() << ".log"; - fLog = new ofstream(filename.str().c_str()); - for (;;) - { - if (!fLog || !fLog->is_open()) - { - ostringstream oss; - oss << "ThreadPoolMonitor " << fPool->name() << " has no file "; - logging::Message::Args args; - logging::Message message(0); - args.add(oss.str()); - message.format( args ); - logging::LoggingID lid(22); - logging::MessageLog ml(lid); - ml.logWarningMessage( message ); - return; - } - // Get a timestamp for output. - struct tm tm; - struct timeval tv; + ostringstream filename; + filename << "/var/log/mariadb/columnstore/trace/ThreadPool_" << fPool->name() << ".log"; + fLog = new ofstream(filename.str().c_str()); + for (;;) + { + if (!fLog || !fLog->is_open()) + { + ostringstream oss; + oss << "ThreadPoolMonitor " << fPool->name() << " has no file "; + logging::Message::Args args; + logging::Message message(0); + args.add(oss.str()); + message.format( args ); + logging::LoggingID lid(22); + logging::MessageLog ml(lid); + ml.logWarningMessage( message ); + return; + } + // Get a timestamp for output. + struct tm tm; + struct timeval tv; - gettimeofday(&tv, 0); - localtime_r(&tv.tv_sec, &tm); + gettimeofday(&tv, 0); + localtime_r(&tv.tv_sec, &tm); - (*fLog) << setfill('0') - << setw(2) << tm.tm_hour << ':' - << setw(2) << tm.tm_min << ':' - << setw(2) << tm.tm_sec - << '.' - << setw(4) << tv.tv_usec/100 - << " Name " << fPool->fName - << " Active " << fPool->waitingFunctorsSize - << " Most " << fPool->fThreadCount - << " Max " << fPool->fMaxThreads - << " Q " << fPool->fQueueSize - << endl; + (*fLog) << setfill('0') + << setw(2) << tm.tm_hour << ':' + << setw(2) << tm.tm_min << ':' + << setw(2) << tm.tm_sec + << '.' + << setw(4) << tv.tv_usec/100 + << " Name " << fPool->fName + << " Active " << fPool->waitingFunctorsSize + << " Most " << fPool->fThreadCount + << " Max " << fPool->fMaxThreads + << " Q " << fPool->fQueueSize + << endl; // struct timespec req = { 0, 1000 * 100 }; //100 usec // nanosleep(&req, 0); - sleep(2); - } + sleep(2); + } } + } // namespace threadpool diff --git a/utils/threadpool/threadpool.h b/utils/threadpool/threadpool.h index 22c138e0b..a000f060b 100644 --- a/utils/threadpool/threadpool.h +++ b/utils/threadpool/threadpool.h @@ -74,7 +74,10 @@ public: * @param maxThreads the maximum number of threads in this pool. This is the maximum number * of simultaneuous operations that can go on. * @param queueSize the maximum number of work tasks in the queue. This is the maximum - * number of jobs that can queue up in the work list before invoke() blocks. + * number of jobs that can queue up in the work list before invoke() blocks. + * If 0, then threads never block and total threads may + * exceed maxThreads. Nothing waits. Thread count will + * idle down to maxThreads when less work is required. */ EXPORT explicit ThreadPool( size_t maxThreads, size_t queueSize ); @@ -108,11 +111,6 @@ public: */ inline size_t getMaxThreads() const { return fMaxThreads; } - /** @brief register a functor to be called when a new thread - * is created - */ - EXPORT void setThreadCreatedListener(const Functor_T &f) ; - /** @brief queue size accessor * */ @@ -218,9 +216,8 @@ private: typedef std::list Container_T; Container_T fWaitingFunctors; Container_T::iterator fNextFunctor; -// Functor_T * fThreadCreated; - uint32_t issued; + uint32_t fIssued; boost::mutex fMutex; boost::condition fThreadAvailable; // triggered when a thread is available boost::condition fNeedThread; // triggered when a thread is needed From 4f8e3b0f6e634f95b28a9efd4f482e38ae172bc4 Mon Sep 17 00:00:00 2001 From: Ben Thompson Date: Fri, 20 Jan 2017 17:05:50 -0600 Subject: [PATCH 25/35] MCOL-468: remove slave-skip-errors=all from default settings --- dbcon/mysql/my.cnf | 1 - procmon/processmonitor.cpp | 5 ----- 2 files changed, 6 deletions(-) diff --git a/dbcon/mysql/my.cnf b/dbcon/mysql/my.cnf index 3793e8baa..9d9907daa 100644 --- a/dbcon/mysql/my.cnf +++ b/dbcon/mysql/my.cnf @@ -84,7 +84,6 @@ plugin_dir = /usr/local/mariadb/columnstore/mysql/lib/plugi # defaults to 1 if master-host # uses to 2+ if slave-host server-id = 1 -slave-skip-errors=all # Replication Slave (comment out master section to use this) # diff --git a/procmon/processmonitor.cpp b/procmon/processmonitor.cpp index e474c69d5..af7f4dd2d 100644 --- a/procmon/processmonitor.cpp +++ b/procmon/processmonitor.cpp @@ -4835,11 +4835,6 @@ int ProcessMonitor::changeMyCnf(std::string type) } } - pos = buf.find("slave-skip-errors=all",0); - if ( pos != string::npos ) { - buf = "# slave-skip-errors=all"; - } - //output to temp file lines.push_back(buf); } From aa9a158ed525037f7cccc0427913c11cb94df5f5 Mon Sep 17 00:00:00 2001 From: david Date: Thu, 9 Feb 2017 15:29:44 +0000 Subject: [PATCH 26/35] MCOL-105 - add suse boost-devel package check --- cpackEngineRPM.cmake | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/cpackEngineRPM.cmake b/cpackEngineRPM.cmake index e284458a3..b427afbfc 100644 --- a/cpackEngineRPM.cmake +++ b/cpackEngineRPM.cmake @@ -81,13 +81,18 @@ IF (EXISTS "/etc/redhat-release") set(REDHAT_VERSION_NUMBER "${CMAKE_MATCH_1}") ENDIF () if (${REDHAT_VERSION_NUMBER} EQUAL 6) - SETA(CPACK_RPM_platform_PACKAGE_REQUIRES "expect" "mariadb-columnstore-libs" "snappy") + SETA(CPACK_RPM_platform_PACKAGE_REQUIRES "expect" "mariadb-columnstore-libs") # Disable auto require as this will also try to pull Boost via RPM SET(CPACK_RPM_PACKAGE_AUTOREQPROV " no") else () - SETA(CPACK_RPM_platform_PACKAGE_REQUIRES "expect" "boost >= 1.53.0" "mariadb-columnstore-libs" "snappy") + if (${REDHAT_VERSION_NUMBER} EQUAL 7) + SETA(CPACK_RPM_platform_PACKAGE_REQUIRES "expect" "boost >= 1.53.0" "mariadb-columnstore-libs") + else () + SETA(CPACK_RPM_platform_PACKAGE_REQUIRES "expect" "boost-devel" "mariadb-columnstore-libs") + endif() endif() + SETA(CPACK_RPM_storage-engine_PACKAGE_REQUIRES "mariadb-columnstore-libs") SET(CPACK_RPM_platform_POST_INSTALL_SCRIPT_FILE ${CMAKE_SOURCE_DIR}/build/postInstall_platform.sh) @@ -291,6 +296,9 @@ SET(CPACK_RPM_libs_USER_FILELIST "/usr/local/mariadb/columnstore/lib/libbatchloader.so.1.0.0" "/usr/local/mariadb/columnstore/lib/libbatchloader.so.1" "/usr/local/mariadb/columnstore/lib/libbatchloader.so" +"/usr/local/mariadb/columnstore/lib/libmysqlcl_idb.so.1.0.0" +"/usr/local/mariadb/columnstore/lib/libmysqlcl_idb.so.1" +"/usr/local/mariadb/columnstore/lib/libmysqlcl_idb.so" "/usr/local/mariadb/columnstore/lib/libquerystats.so.1.0.0" "/usr/local/mariadb/columnstore/lib/libquerystats.so.1" "/usr/local/mariadb/columnstore/lib/libquerystats.so" From 1072d0abf8fb82ef72944b20a2c7b977e8ea0ea2 Mon Sep 17 00:00:00 2001 From: David Hill Date: Thu, 9 Feb 2017 15:44:31 -0600 Subject: [PATCH 27/35] MCOL-105 - change suse boost-devel package check --- cpackEngineRPM.cmake | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/cpackEngineRPM.cmake b/cpackEngineRPM.cmake index b427afbfc..e5030c4fb 100644 --- a/cpackEngineRPM.cmake +++ b/cpackEngineRPM.cmake @@ -75,24 +75,27 @@ SETA(CPACK_RPM_storage-engine_PACKAGE_PROVIDES "mariadb-columnstore-storage-engi # Boost is a source build in CentOS 6 so don't require it as a package SET(REDHAT_VERSION_NUMBER OFF) +SET(SUSE_VERSION_NUMBER OFF) IF (EXISTS "/etc/redhat-release") file (READ "/etc/redhat-release" REDHAT_VERSION) string(REGEX MATCH "release ([0-9]+)" CENTOS "${REDHAT_VERSION}") set(REDHAT_VERSION_NUMBER "${CMAKE_MATCH_1}") ENDIF () +IF (EXISTS "/etc/SuSE-release") + file (READ "/etc/SuSE-release" SUSE_VERSION) + string(REGEX MATCH "VERSION = ([0-9]+)" SUSE "${SUSE_VERSION}") + set(SUSE_VERSION_NUMBER "${CMAKE_MATCH_1}") +ENDIF () if (${REDHAT_VERSION_NUMBER} EQUAL 6) SETA(CPACK_RPM_platform_PACKAGE_REQUIRES "expect" "mariadb-columnstore-libs") # Disable auto require as this will also try to pull Boost via RPM SET(CPACK_RPM_PACKAGE_AUTOREQPROV " no") +elseif (${SUSE_VERSION_NUMBER} EQUAL 12) + SETA(CPACK_RPM_platform_PACKAGE_REQUIRES "expect" "boost-devel >= 1.54.0" "mariadb-columnstore-libs") else () - if (${REDHAT_VERSION_NUMBER} EQUAL 7) - SETA(CPACK_RPM_platform_PACKAGE_REQUIRES "expect" "boost >= 1.53.0" "mariadb-columnstore-libs") - else () - SETA(CPACK_RPM_platform_PACKAGE_REQUIRES "expect" "boost-devel" "mariadb-columnstore-libs") - endif() + SETA(CPACK_RPM_platform_PACKAGE_REQUIRES "expect" "boost >= 1.53.0" "mariadb-columnstore-libs") endif() - SETA(CPACK_RPM_storage-engine_PACKAGE_REQUIRES "mariadb-columnstore-libs") SET(CPACK_RPM_platform_POST_INSTALL_SCRIPT_FILE ${CMAKE_SOURCE_DIR}/build/postInstall_platform.sh) From 2525e8e855ae39739405ba0604908217543b44e9 Mon Sep 17 00:00:00 2001 From: David Hill Date: Thu, 9 Feb 2017 16:05:56 -0600 Subject: [PATCH 28/35] MCOL-105 - change suse boost-devel package check, add back in 1.1 changes --- cpackEngineRPM.cmake | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/cpackEngineRPM.cmake b/cpackEngineRPM.cmake index e5030c4fb..403b285e7 100644 --- a/cpackEngineRPM.cmake +++ b/cpackEngineRPM.cmake @@ -73,7 +73,8 @@ SETA(CPACK_RPM_libs_PACKAGE_PROVIDES "mariadb-columnstore-libs") SETA(CPACK_RPM_platform_PACKAGE_PROVIDES "mariadb-columnstore-platform") SETA(CPACK_RPM_storage-engine_PACKAGE_PROVIDES "mariadb-columnstore-storage-engine") -# Boost is a source build in CentOS 6 so don't require it as a package + +ost is a source build in CentOS 6 so don't require it as a package SET(REDHAT_VERSION_NUMBER OFF) SET(SUSE_VERSION_NUMBER OFF) IF (EXISTS "/etc/redhat-release") @@ -299,9 +300,6 @@ SET(CPACK_RPM_libs_USER_FILELIST "/usr/local/mariadb/columnstore/lib/libbatchloader.so.1.0.0" "/usr/local/mariadb/columnstore/lib/libbatchloader.so.1" "/usr/local/mariadb/columnstore/lib/libbatchloader.so" -"/usr/local/mariadb/columnstore/lib/libmysqlcl_idb.so.1.0.0" -"/usr/local/mariadb/columnstore/lib/libmysqlcl_idb.so.1" -"/usr/local/mariadb/columnstore/lib/libmysqlcl_idb.so" "/usr/local/mariadb/columnstore/lib/libquerystats.so.1.0.0" "/usr/local/mariadb/columnstore/lib/libquerystats.so.1" "/usr/local/mariadb/columnstore/lib/libquerystats.so" From ba897f0e34702260f21170d2c24efaa40e703840 Mon Sep 17 00:00:00 2001 From: David Hill Date: Thu, 9 Feb 2017 16:18:12 -0600 Subject: [PATCH 29/35] MCOL-105 - change suse boost-devel package check, add back in 1.1 changes --- cpackEngineRPM.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cpackEngineRPM.cmake b/cpackEngineRPM.cmake index 403b285e7..c006fac78 100644 --- a/cpackEngineRPM.cmake +++ b/cpackEngineRPM.cmake @@ -74,7 +74,7 @@ SETA(CPACK_RPM_platform_PACKAGE_PROVIDES "mariadb-columnstore-platform") SETA(CPACK_RPM_storage-engine_PACKAGE_PROVIDES "mariadb-columnstore-storage-engine") -ost is a source build in CentOS 6 so don't require it as a package +#boost is a source build in CentOS 6 so don't require it as a package SET(REDHAT_VERSION_NUMBER OFF) SET(SUSE_VERSION_NUMBER OFF) IF (EXISTS "/etc/redhat-release") From 1424fdac197103342779792b5c84993bbe220265 Mon Sep 17 00:00:00 2001 From: David Hill Date: Mon, 13 Feb 2017 10:49:09 -0600 Subject: [PATCH 30/35] MCOL-566 - remove expect wait for command line prompt --- oam/install_scripts/remote_command.sh | 1 - 1 file changed, 1 deletion(-) diff --git a/oam/install_scripts/remote_command.sh b/oam/install_scripts/remote_command.sh index 6878bcf22..1588a5f42 100755 --- a/oam/install_scripts/remote_command.sh +++ b/oam/install_scripts/remote_command.sh @@ -33,7 +33,6 @@ if { $TTYOPT != "" } { } log_user $DEBUG spawn -noecho /bin/bash -expect -re {[$#] } if { $PASSWORD == "ssh" } { set PASSWORD "" From 776add46dc7e40d388344b3bfaa7654b4238373d Mon Sep 17 00:00:00 2001 From: David Hill Date: Mon, 13 Feb 2017 14:01:31 -0600 Subject: [PATCH 31/35] MCOL-566 - remove expect wait for command line prompt- removed 3 more --- oam/install_scripts/remote_command.sh | 3 --- 1 file changed, 3 deletions(-) diff --git a/oam/install_scripts/remote_command.sh b/oam/install_scripts/remote_command.sh index 1588a5f42..daa44614f 100755 --- a/oam/install_scripts/remote_command.sh +++ b/oam/install_scripts/remote_command.sh @@ -56,13 +56,10 @@ expect { } "word: " { send "$PASSWORD\n" } "passphrase" { send "$PASSWORD\n" } - -re {[$#] } { exit 0 } } expect { - -re {[$#] } { exit 0 } "Permission denied" { send_user " FAILED: Invalid password\n" ; exit 1 } "(y or n)" { send "y\n" - expect -re {[$#] } { exit 0 } } } exit 0 From 87a679e6ebdbf6fd258625992e0a9bd1d3f6484e Mon Sep 17 00:00:00 2001 From: David Hall Date: Fri, 17 Feb 2017 09:44:32 -0600 Subject: [PATCH 32/35] MCOL-513 use a single funcor per thread. ThreadPool was doing one at a time anyway, but in a convpluted way that made it easier to add more if wanted. But it was expensive. Cleanup and polish. --- dbcon/joblist/joblist.cpp | 28 +- dbcon/joblist/jobstep.h | 14 + dbcon/joblist/pdictionaryscan.cpp | 2 +- dbcon/joblist/tupleunion.cpp | 2 - ddlproc/ddlprocessor.cpp | 1 + dmlproc/dmlproc.cpp | 18 +- dmlproc/dmlprocessor.cpp | 1 + exemgr/femsghandler.cpp | 8 +- exemgr/femsghandler.h | 10 +- exemgr/main.cpp | 32 +- primitives/primproc/primitiveserver.cpp | 1 + utils/threadpool/threadpool.cpp | 44 +-- utils/threadpool/threadpool.vpj | 440 ++++++++++++------------ 13 files changed, 305 insertions(+), 296 deletions(-) diff --git a/dbcon/joblist/joblist.cpp b/dbcon/joblist/joblist.cpp index 6e9607209..e5eb86b26 100644 --- a/dbcon/joblist/joblist.cpp +++ b/dbcon/joblist/joblist.cpp @@ -28,7 +28,6 @@ using namespace std; #include "joblist.h" - #include "calpontsystemcatalog.h" using namespace execplan; @@ -73,23 +72,26 @@ JobList::JobList(bool isEM) : JobList::~JobList() { - vector joiners; -// boost::thread *tmp; try { if (fIsRunning) { - JobStepVector::iterator iter; - JobStepVector::iterator end; #if 0 + // This logic creates a set of threads to wind down the query + vector joiners; + joiners.reserve(20); + NullStep nullStep; // For access to the static jobstepThreadPool. + + JobStepVector::iterator iter; + JobStepVector::iterator end; + iter = fQuery.begin(); end = fQuery.end(); // Wait for all the query steps to finish while (iter != end) { - tmp = new boost::thread(JSJoiner(iter->get())); - joiners.push_back(tmp); + joiners.push_back(nullStep.jobstepThreadPool.invoke(JSJoiner(iter->get()))); ++iter; } @@ -99,17 +101,15 @@ JobList::~JobList() // wait for the projection steps while (iter != end) { - tmp = new boost::thread(JSJoiner(iter->get())); - joiners.push_back(tmp); + joiners.push_back(nullStep.jobstepThreadPool.invoke(JSJoiner(iter->get()))); ++iter; } - for (uint32_t i = 0; i < joiners.size(); i++) { - joiners[i]->join(); - delete joiners[i]; - } + nullStep.jobstepThreadPool.join(joiners); #endif - // Stop all the query steps + // This logic stops the query steps one at a time + JobStepVector::iterator iter; + JobStepVector::iterator end; end = fQuery.end(); for (iter = fQuery.begin(); iter != end; ++iter) { diff --git a/dbcon/joblist/jobstep.h b/dbcon/joblist/jobstep.h index 5763ce782..00bf243d7 100644 --- a/dbcon/joblist/jobstep.h +++ b/dbcon/joblist/jobstep.h @@ -330,6 +330,20 @@ public: virtual bool deliverStringTableRowGroup() const = 0; }; +class NullStep : public JobStep +{ +public: + /** @brief virtual void Run method + */ + virtual void run(){} + /** @brief virtual void join method + */ + virtual void join(){} + /** @brief virtual string toString method + */ + virtual const std::string toString() const {return "NullStep";} +}; + // calls rhs->toString() std::ostream& operator<<(std::ostream& os, const JobStep* rhs); diff --git a/dbcon/joblist/pdictionaryscan.cpp b/dbcon/joblist/pdictionaryscan.cpp index 960458585..bfb0c27d2 100644 --- a/dbcon/joblist/pdictionaryscan.cpp +++ b/dbcon/joblist/pdictionaryscan.cpp @@ -134,9 +134,9 @@ pDictionaryScan::pDictionaryScan( sendWaiting(false), ridCount(0), ridList(0), + colType(ct), pThread(0), cThread(0), - colType(ct), fScanLbidReqLimit(jobInfo.rm->getJlScanLbidReqLimit()), fScanLbidReqThreshold(jobInfo.rm->getJlScanLbidReqThreshold()), fStopSending(false), diff --git a/dbcon/joblist/tupleunion.cpp b/dbcon/joblist/tupleunion.cpp index 1a2e37d93..bc83455ce 100644 --- a/dbcon/joblist/tupleunion.cpp +++ b/dbcon/joblist/tupleunion.cpp @@ -775,9 +775,7 @@ void TupleUnion::run() void TupleUnion::join() { - uint32_t i; mutex::scoped_lock lk(jlLock); - Uniquer_t::iterator it; if (joinRan) return; diff --git a/ddlproc/ddlprocessor.cpp b/ddlproc/ddlprocessor.cpp index 28d234b1a..c7f2f4502 100644 --- a/ddlproc/ddlprocessor.cpp +++ b/ddlproc/ddlprocessor.cpp @@ -340,6 +340,7 @@ DDLProcessor::DDLProcessor( int packageMaxThreads, int packageWorkQueueSize ) { fDdlPackagepool.setMaxThreads(fPackageMaxThreads); fDdlPackagepool.setQueueSize(fPackageWorkQueueSize); + fDdlPackagepool.setName("DdlPackagepool"); csc = CalpontSystemCatalog::makeCalpontSystemCatalog(); csc->identity(CalpontSystemCatalog::EC); string teleServerHost(config::Config::makeConfig()->getConfig("QueryTele", "Host")); diff --git a/dmlproc/dmlproc.cpp b/dmlproc/dmlproc.cpp index ced77ec82..c1575ff27 100644 --- a/dmlproc/dmlproc.cpp +++ b/dmlproc/dmlproc.cpp @@ -558,8 +558,23 @@ int main(int argc, char* argv[]) } DMLServer dmlserver(serverThreads, serverQueueSize,&dbrm); + ResourceManager *rm = ResourceManager::instance(); - //set ACTIVE state + // jobstepThreadPool is used by other processes. We can't call + // resourcemanaager (rm) functions during the static creation of threadpool + // because rm has a "isExeMgr" flag that is set upon creation (rm is a singleton). + // From the pools perspective, it has no idea if it is ExeMgr doing the + // creation, so it has no idea which way to set the flag. So we set the max here. + JobStep::jobstepThreadPool.setMaxThreads(rm->getJLThreadPoolSize()); + JobStep::jobstepThreadPool.setName("DMLProcJobList"); + +// if (rm->getJlThreadPoolDebug() == "Y" || rm->getJlThreadPoolDebug() == "y") +// { +// JobStep::jobstepThreadPool.setDebug(true); +// JobStep::jobstepThreadPool.invoke(ThreadPoolMonitor(&JobStep::jobstepThreadPool)); +// } + + //set ACTIVE state try { oam.processInitComplete("DMLProc", ACTIVE); @@ -567,7 +582,6 @@ int main(int argc, char* argv[]) catch (...) { } - ResourceManager *rm = ResourceManager::instance(); Dec = DistributedEngineComm::instance(rm); #ifndef _MSC_VER diff --git a/dmlproc/dmlprocessor.cpp b/dmlproc/dmlprocessor.cpp index b0f36305b..2205d1712 100644 --- a/dmlproc/dmlprocessor.cpp +++ b/dmlproc/dmlprocessor.cpp @@ -1130,6 +1130,7 @@ DMLServer::DMLServer(int packageMaxThreads, int packageWorkQueueSize, DBRM* dbrm fDmlPackagepool.setMaxThreads(fPackageMaxThreads); fDmlPackagepool.setQueueSize(fPackageWorkQueueSize); + fDmlPackagepool.setName("DmlPackagepool"); } void DMLServer::start() diff --git a/exemgr/femsghandler.cpp b/exemgr/femsghandler.cpp index c3df2ba92..f1b36204e 100644 --- a/exemgr/femsghandler.cpp +++ b/exemgr/femsghandler.cpp @@ -24,7 +24,7 @@ using namespace std; using namespace joblist; using namespace messageqcpp; -threadpool::ThreadPool FEMsgHandler::threadPool(100,200); +threadpool::ThreadPool FEMsgHandler::threadPool(50,100); namespace { @@ -52,15 +52,14 @@ FEMsgHandler::FEMsgHandler(boost::shared_ptr j, IOSocket *s) : FEMsgHandler::~FEMsgHandler() { stop(); -// thr.join(); - boost::unique_lock lk(joinMutex); + threadPool.join(thr); } void FEMsgHandler::start() { if (!running) { running = true; - threadPool.invoke(Runner(this)); + thr = threadPool.invoke(Runner(this)); } } @@ -109,7 +108,6 @@ bool FEMsgHandler::aborted() void FEMsgHandler::threadFcn() { int err = 0; - boost::unique_lock lk(joinMutex); int connectionNum = sock->getConnectionNum(); /* This waits for the next readable event on sock. An abort is signaled diff --git a/exemgr/femsghandler.h b/exemgr/femsghandler.h index 1d51e6d95..7e7ce438d 100644 --- a/exemgr/femsghandler.h +++ b/exemgr/femsghandler.h @@ -37,18 +37,14 @@ public: void threadFcn(); + static threadpool::ThreadPool threadPool; + private: bool die, running, sawData; messageqcpp::IOSocket *sock; boost::shared_ptr jl; boost::mutex mutex; -// boost::thread thr; - static threadpool::ThreadPool threadPool; - - // Because we can't join() a thread from a thread pool, threadFcn will - // unlock when it exits and the destructor can block until the thread is done. - boost::mutex joinMutex; - + uint64_t thr; }; #endif /* FEMSGHANDLER_H_ */ diff --git a/exemgr/main.cpp b/exemgr/main.cpp index 0d97394a7..2ff51bb2e 100644 --- a/exemgr/main.cpp +++ b/exemgr/main.cpp @@ -515,7 +515,7 @@ public: SJLP jl; bool incSessionThreadCnt = true; - bool selfJoin = false; + bool selfJoin = false; bool tryTuples = false; bool usingTuples = false; bool stmtCounted = false; @@ -1393,19 +1393,18 @@ int main(int argc, char* argv[]) } } - // It's possible that PM modules use this threadpool. Only ExeMgr creates - // massive amounts of threads and needs to be settable. It's also possible that - // other process on this UM module use this threadpool. In this case, they share. - // We can't call rm functions during the static creation because rm has a isExeMgr - // flag that is set upon first creation. For the pool, who has no idea if it is ExeMgr, - // to create the singleton rm would be wrong, no matter which way we set the flag. + // jobstepThreadPool is used by other processes. We can't call + // resourcemanaager (rm) functions during the static creation of threadpool + // because rm has a "isExeMgr" flag that is set upon creation (rm is a singleton). + // From the pools perspective, it has no idea if it is ExeMgr doing the + // creation, so it has no idea which way to set the flag. So we set the max here. JobStep::jobstepThreadPool.setMaxThreads(rm->getJLThreadPoolSize()); - JobStep::jobstepThreadPool.setName("ExeMgr"); - if (rm->getJlThreadPoolDebug() == "Y" || rm->getJlThreadPoolDebug() == "y") - { - JobStep::jobstepThreadPool.setDebug(true); - JobStep::jobstepThreadPool.invoke(ThreadPoolMonitor(&JobStep::jobstepThreadPool)); - } + JobStep::jobstepThreadPool.setName("ExeMgrJobList"); +// if (rm->getJlThreadPoolDebug() == "Y" || rm->getJlThreadPoolDebug() == "y") +// { +// JobStep::jobstepThreadPool.setDebug(true); +// JobStep::jobstepThreadPool.invoke(ThreadPoolMonitor(&JobStep::jobstepThreadPool)); +// } int serverThreads = rm->getEmServerThreads(); int serverQueueSize = rm->getEmServerQueueSize(); @@ -1413,7 +1412,11 @@ int main(int argc, char* argv[]) int pauseSeconds = rm->getEmSecondsBetweenMemChecks(); int priority = rm->getEmPriority(); - if (maxPct > 0) + FEMsgHandler::threadPool.setMaxThreads(serverThreads); + FEMsgHandler::threadPool.setQueueSize(serverQueueSize); + FEMsgHandler::threadPool.setName("FEMsgHandler"); + + if (maxPct > 0) startRssMon(maxPct, pauseSeconds); #ifndef _MSC_VER @@ -1448,6 +1451,7 @@ int main(int argc, char* argv[]) } threadpool::ThreadPool exeMgrThreadPool(serverThreads, serverQueueSize); + exeMgrThreadPool.setName("ExeMgrServer"); for (;;) { IOSocket ios; diff --git a/primitives/primproc/primitiveserver.cpp b/primitives/primproc/primitiveserver.cpp index deaae576e..1f6145733 100644 --- a/primitives/primproc/primitiveserver.cpp +++ b/primitives/primproc/primitiveserver.cpp @@ -2032,6 +2032,7 @@ PrimitiveServer::PrimitiveServer(int serverThreads, fCacheCount=cacheCount; fServerpool.setMaxThreads(fServerThreads); fServerpool.setQueueSize(fServerQueueSize); + fServerpool.setName("PrimitiveServer"); fProcessorPool.reset(new threadpool::PriorityThreadPool(fProcessorWeight, highPriorityThreads, medPriorityThreads, lowPriorityThreads, 0)); diff --git a/utils/threadpool/threadpool.cpp b/utils/threadpool/threadpool.cpp index 41ab57065..442d43c53 100644 --- a/utils/threadpool/threadpool.cpp +++ b/utils/threadpool/threadpool.cpp @@ -283,42 +283,28 @@ void ThreadPool::beginThread() throw() else { // Wait no more than 10 minutes - if (fNeedThread.timed_wait(lock1, timeout) == boost::cv_status::timeout) + if (!fNeedThread.timed_wait(lock1, timeout)) // false means it timed out { if (fThreadCount > fMaxThreads) { --fThreadCount; return; } + timeout = boost::get_system_time()+boost::posix_time::minutes(10); } } } else { - /* Need to tune these magic #s */ - vector todoList; - int i, num; - Container_T::const_iterator iter; - - /* Use num to control how many jobs are issued to a single thread - should you want to batch more than one */ - num = (waitingFunctorsSize - fIssued >= 1 ? 1 : 0); - - for (i = 0; i < num; i++) - todoList.push_back(fNextFunctor++); - - fIssued += num; -// cerr << "got " << num << " jobs." << endl; -// cerr << "got " << num << " jobs. waitingFunctorsSize=" << -// waitingFunctorsSize << " fIssued=" << fIssued << " fThreadCount=" << -// fThreadCount << endl; - lock1.unlock(); - - for (i = 0; i < num; i++) + // If there's anything waiting, run it + if (waitingFunctorsSize - fIssued > 0) { + Container_T::iterator todo = fNextFunctor++; + ++fIssued; + lock1.unlock(); try { - (*todoList[i]).functor(); + todo->functor(); } catch (exception &e) { @@ -334,18 +320,12 @@ void ThreadPool::beginThread() throw() ml.logErrorMessage( message ); #endif } + lock1.lock(); + --fIssued; + --waitingFunctorsSize; + fWaitingFunctors.erase(todo); } - lock1.lock(); - fIssued -= num; - waitingFunctorsSize -= num; - for (i = 0; i < num; i++) - fWaitingFunctors.erase(todoList[i]); -/* - if (waitingFunctorsSize != fWaitingFunctors.size()) - cerr << "size mismatch! fake size=" << waitingFunctorsSize << - " real size=" << fWaitingFunctors.size() << endl; -*/ timeout = boost::get_system_time()+boost::posix_time::minutes(10); fThreadAvailable.notify_all(); } diff --git a/utils/threadpool/threadpool.vpj b/utils/threadpool/threadpool.vpj index e9270a137..63c370751 100644 --- a/utils/threadpool/threadpool.vpj +++ b/utils/threadpool/threadpool.vpj @@ -1,222 +1,224 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + Version="10.0" + VendorName="SlickEdit" + TemplateName="GNU C/C++" + WorkingDir="."> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + From 59f984c3cade33cce2a22fd1aa2c127cae7d5599 Mon Sep 17 00:00:00 2001 From: David Hall Date: Fri, 17 Feb 2017 10:45:59 -0600 Subject: [PATCH 33/35] MCOL-513 Comment spelling --- exemgr/main.cpp | 2 +- utils/threadpool/threadpool.cpp | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/exemgr/main.cpp b/exemgr/main.cpp index 2ff51bb2e..d22c79b78 100644 --- a/exemgr/main.cpp +++ b/exemgr/main.cpp @@ -1393,7 +1393,7 @@ int main(int argc, char* argv[]) } } - // jobstepThreadPool is used by other processes. We can't call + // class jobstepThreadPool is used by other processes. We can't call // resourcemanaager (rm) functions during the static creation of threadpool // because rm has a "isExeMgr" flag that is set upon creation (rm is a singleton). // From the pools perspective, it has no idea if it is ExeMgr doing the diff --git a/utils/threadpool/threadpool.cpp b/utils/threadpool/threadpool.cpp index 442d43c53..b232617d6 100644 --- a/utils/threadpool/threadpool.cpp +++ b/utils/threadpool/threadpool.cpp @@ -274,7 +274,7 @@ void ThreadPool::beginThread() throw() if (fNextFunctor == fWaitingFunctors.end()) { // Wait until someone needs a thread - // Add the timed waait for queueSize == 0 so we can idle away threads + // Add the timed wait for queueSize == 0 so we can idle away threads // over fMaxThreads if (fQueueSize > 0) { @@ -392,7 +392,6 @@ uint64_t ThreadPool::addFunctor(const Functor_T &func) if (fNextFunctor == fWaitingFunctors.end()) bAtEnd = true; -// PoolFunction_T poolFunction(fNextHandle, func); PoolFunction_T poolFunction; poolFunction.hndl = fNextHandle; poolFunction.functor = func; From def06be564fbd8635a425099baa976372b071b3c Mon Sep 17 00:00:00 2001 From: David Hall Date: Mon, 20 Feb 2017 11:43:46 -0600 Subject: [PATCH 34/35] MCOL-513 Use vector ref for join to prevent vector copy. --- utils/threadpool/threadpool.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils/threadpool/threadpool.h b/utils/threadpool/threadpool.h index a000f060b..f11bb4b2b 100644 --- a/utils/threadpool/threadpool.h +++ b/utils/threadpool/threadpool.h @@ -145,7 +145,7 @@ public: /** @brief Wait for a specific thread */ - EXPORT void join(std::vector thrHandle); + EXPORT void join(std::vector& thrHandle); /** @brief for use in debugging */ From 88a372c67173490c0432f3252b136f9612480586 Mon Sep 17 00:00:00 2001 From: David Hall Date: Mon, 20 Feb 2017 11:45:29 -0600 Subject: [PATCH 35/35] MCOL-513 Use vector ref for join to prevent vector copy. --- utils/threadpool/threadpool.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils/threadpool/threadpool.cpp b/utils/threadpool/threadpool.cpp index b232617d6..1281e0b5f 100644 --- a/utils/threadpool/threadpool.cpp +++ b/utils/threadpool/threadpool.cpp @@ -134,7 +134,7 @@ void ThreadPool::join(uint64_t thrHandle) } } -void ThreadPool::join(std::vector thrHandle) +void ThreadPool::join(std::vector& thrHandle) { boost::mutex::scoped_lock lock1(fMutex);