Repository: drill
Updated Branches:
  refs/heads/master a2fec7869 -> df0f0af3d


http://git-wip-us.apache.org/repos/asf/drill/blob/df0f0af3/contrib/native/client/src/clientlib/errmsgs.cpp
----------------------------------------------------------------------
diff --git a/contrib/native/client/src/clientlib/errmsgs.cpp 
b/contrib/native/client/src/clientlib/errmsgs.cpp
index 11661f8..47d165f 100644
--- a/contrib/native/client/src/clientlib/errmsgs.cpp
+++ b/contrib/native/client/src/clientlib/errmsgs.cpp
@@ -47,6 +47,8 @@ static Drill::ErrorMessages errorMessages[]={
     {ERR_CONN_AUTHFAIL, ERR_CATEGORY_CONN, 0, "User authentication failed 
(please check the username and password)."
         "[Server message was: (%s) %s]"},
     {ERR_CONN_UNKNOWN_ERR, ERR_CATEGORY_CONN, 0, "Handshake Failed due to an 
error on the server. [Server message was: (%s) %s]"},
+    {ERR_CONN_NOCONN, ERR_CATEGORY_CONN, 0, "There is no connection to the 
server."},
+    {ERR_CONN_ALREADYCONN, ERR_CATEGORY_CONN, 0, "This client is already 
connected to a server."},
     {ERR_QRY_OUTOFMEM, ERR_CATEGORY_QRY, 0, "Out of memory."},
     {ERR_QRY_COMMERR, ERR_CATEGORY_QRY, 0, "Communication error. %s"},
     {ERR_QRY_INVREADLEN, ERR_CATEGORY_QRY, 0, "Internal Error: Received a 
message with an invalid read length."},

http://git-wip-us.apache.org/repos/asf/drill/blob/df0f0af3/contrib/native/client/src/clientlib/errmsgs.hpp
----------------------------------------------------------------------
diff --git a/contrib/native/client/src/clientlib/errmsgs.hpp 
b/contrib/native/client/src/clientlib/errmsgs.hpp
index b82efaa..cfb56a6 100644
--- a/contrib/native/client/src/clientlib/errmsgs.hpp
+++ b/contrib/native/client/src/clientlib/errmsgs.hpp
@@ -49,7 +49,9 @@ namespace Drill{
 #define ERR_CONN_BAD_RPC_VER    DRILL_ERR_START+16
 #define ERR_CONN_AUTHFAIL       DRILL_ERR_START+17
 #define ERR_CONN_UNKNOWN_ERR    DRILL_ERR_START+18
-#define ERR_CONN_MAX            DRILL_ERR_START+18
+#define ERR_CONN_NOCONN         DRILL_ERR_START+19
+#define ERR_CONN_ALREADYCONN    DRILL_ERR_START+20
+#define ERR_CONN_MAX            DRILL_ERR_START+20
 
 #define ERR_QRY_OUTOFMEM    ERR_CONN_MAX+1
 #define ERR_QRY_COMMERR     ERR_CONN_MAX+2

http://git-wip-us.apache.org/repos/asf/drill/blob/df0f0af3/contrib/native/client/src/clientlib/logger.cpp
----------------------------------------------------------------------
diff --git a/contrib/native/client/src/clientlib/logger.cpp 
b/contrib/native/client/src/clientlib/logger.cpp
index 5411d01..c498ee1 100644
--- a/contrib/native/client/src/clientlib/logger.cpp
+++ b/contrib/native/client/src/clientlib/logger.cpp
@@ -1,28 +1,40 @@
 /*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
+* Licensed to the Apache Software Foundation (ASF) under one
+* or more contributor license agreements.  See the NOTICE file
+* distributed with this work for additional information
+* regarding copyright ownership.  The ASF licenses this file
+* to you under the Apache License, Version 2.0 (the
+* "License"); you may not use this file except in compliance
+* with the License.  You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
 
+#include <sys/types.h>
 #include "boost/date_time/posix_time/posix_time.hpp"
 #include "boost/thread.hpp"
-
+#include "env.h"
+#include "utils.hpp"
 #include "logger.hpp"
 
 namespace Drill{
 
+/*
+* Creates a single instance of the logger the first time this is called
+*/
+/*  static */ boost::mutex g_logMutex;
+Logger& getLogger() {
+    boost::lock_guard<boost::mutex> logLock(g_logMutex);
+    static Logger* logger = new Logger();
+    return *logger;
+}
+
 std::string getTime(){
     return to_simple_string(boost::posix_time::second_clock::local_time());
 }
@@ -31,37 +43,77 @@ std::string getTid(){
     return boost::lexical_cast<std::string>(boost::this_thread::get_id());
 }
 
-logLevel_t Logger::s_level=LOG_ERROR;
-std::ostream* Logger::s_pOutStream=NULL;
-std::ofstream* Logger::s_pOutFileStream=NULL;
-char* Logger::s_filepath=NULL;
-
 void Logger::init(const char* path){
-    if(path!=NULL) {
-        s_pOutFileStream = new std::ofstream;
-        s_pOutFileStream->open(path, std::ofstream::out);
-        if(!s_pOutFileStream->is_open()){
-            std::cerr << "Logfile could not be opened. Logging to stdout" << 
std::endl;
+    static bool initialized = false;
+    boost::lock_guard<boost::mutex> logLock(m_logMutex);
+    if (!initialized && path != NULL) {
+        std::string fullname = path;
+        size_t lastindex = fullname.find_last_of(".");
+        std::string filename;
+        if (lastindex != std::string::npos){
+            filename = fullname.substr(0, lastindex)
+                + "-"
+                + Utils::to_string(Utils::s_randomNumber())
+                + fullname.substr(lastindex, fullname.length());
         }
+        else{
+            filename = fullname.substr(0, fullname.length())
+                + "-"
+                + Utils::to_string(Utils::s_randomNumber())
+                + ".log";
+        }
+        //m_filepath=path;
+        m_filepath = filename.c_str();
+        m_pOutFileStream = new std::ofstream;
+        m_pOutFileStream->open(m_filepath.c_str(), std::ios_base::out | 
std::ios_base::app);
+        if (!m_pOutFileStream->is_open()){
+            std::cerr << "Logfile ( " << m_filepath << ") could not be opened. 
Logging to stdout" << std::endl;
+            m_filepath.erase();
+            delete m_pOutFileStream; m_pOutFileStream=NULL;
+        }
+        initialized = true;
+
+        m_pOutStream = (m_pOutFileStream != NULL) ? m_pOutFileStream : 
&std::cout;
+#if defined _WIN32 || defined _WIN64
+
+        TCHAR szFile[MAX_PATH];
+        GetModuleFileName(NULL, szFile, MAX_PATH);
+#endif
+        *m_pOutStream
+            << "Drill Client Library" << std::endl
+            << "Build info:" <<  GIT_COMMIT_PROP << std::endl 
+
+#if defined _WIN32 || defined _WIN64
+            << "Loaded by process: " << szFile << std::endl
+            << "Current process id is: " << ::GetCurrentProcessId() << 
std::endl
+#else 
+            << "Current process id is: " << getpid() << std::endl
+#endif
+            << "Initialized Logging to file (" << 
((path!=NULL)?path:"std::out") << "). "
+            << std::endl;
     }
-    s_pOutStream=(s_pOutFileStream!=NULL && 
s_pOutFileStream->is_open())?s_pOutFileStream:&std::cout;
 }
 
 void Logger::close(){
-    if(s_pOutFileStream !=NULL){
-        if(s_pOutFileStream->is_open()){
-            s_pOutFileStream->close();
+    //boost::lock_guard<boost::mutex> logLock(Drill::Logger::m_logMutex); 
+    boost::lock_guard<boost::mutex> logLock(m_logMutex);
+    if (m_pOutFileStream != NULL){
+        if (m_pOutFileStream->is_open()){
+            m_pOutFileStream->close();
         }
-        delete s_pOutFileStream; s_pOutFileStream=NULL;
+        delete m_pOutFileStream; m_pOutFileStream = NULL;
+        m_pOutStream = &std::cout; // set it back to std::cout in case someone 
tries to log even after close
     }
 }
 
+// The log call itself cannot be thread safe. Use the DRILL_MT_LOG macro to 
make 
+// this thread safe
 std::ostream& Logger::log(logLevel_t level){
-    *s_pOutStream << getTime();
-    *s_pOutStream << " : "<<levelAsString(level);
-    *s_pOutStream << " : "<<getTid();
-    *s_pOutStream << " : ";
-    return *s_pOutStream;
+    *m_pOutStream << getTime();
+    *m_pOutStream << " : " << levelAsString(level);
+    *m_pOutStream << " : " << getTid();
+    *m_pOutStream << " : ";
+    return *m_pOutStream;
 }
 
 

http://git-wip-us.apache.org/repos/asf/drill/blob/df0f0af3/contrib/native/client/src/clientlib/logger.hpp
----------------------------------------------------------------------
diff --git a/contrib/native/client/src/clientlib/logger.hpp 
b/contrib/native/client/src/clientlib/logger.hpp
index e3edb13..7baf50c 100644
--- a/contrib/native/client/src/clientlib/logger.hpp
+++ b/contrib/native/client/src/clientlib/logger.hpp
@@ -1,20 +1,20 @@
 /*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
+* Licensed to the Apache Software Foundation (ASF) under one
+* or more contributor license agreements.  See the NOTICE file
+* distributed with this work for additional information
+* regarding copyright ownership.  The ASF licenses this file
+* to you under the Apache License, Version 2.0 (the
+* "License"); you may not use this file except in compliance
+* with the License.  You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
 
 #ifndef __LOGGER_H
 #define __LOGGER_H
@@ -25,47 +25,60 @@
 #include <string>
 #include <stdio.h>
 
+#include <boost/thread/mutex.hpp>
 #include "drill/common.hpp"
 
 namespace Drill{
 
 class Logger{
     public:
-        Logger(){}
+        Logger(){
+            m_level = LOG_ERROR;
+            m_pOutFileStream = NULL;
+            m_pOutStream = &std::cout;
+        }
         ~Logger(){ }
 
-        static void init(const char* path);
-        static void close();
-        static std::ostream& log(logLevel_t level);
-        static std::string levelAsString(logLevel_t level) {
+        void init(const char* path);
+        void close();
+        std::ostream& log(logLevel_t level);
+        std::string levelAsString(logLevel_t level) {
             static const char* const levelNames[] = {
-                "TRACE",
-                "DEBUG",
-                "INFO",
+                "TRACE  ",
+                "DEBUG  ",
+                "INFO   ",
                 "WARNING",
-                "ERROR",
-                "FATAL"
+                "ERROR  ",
+                "FATAL  "
             };
-            return levelNames[level];
+            return levelNames[level>=LOG_TRACE && 
level<=LOG_FATAL?level:LOG_ERROR];
         }
 
         // The logging level
-        static logLevel_t s_level;
-        static std::ostream* s_pOutStream;
+        logLevel_t m_level;
+        std::ostream* m_pOutStream;
+        boost::mutex m_logMutex;
 
     private:
-        //static std::ostream* s_pOutStream;
-        static std::ofstream* s_pOutFileStream;
-        static char* s_filepath;
+        std::ofstream* m_pOutFileStream;
+        std::string m_filepath;
 
 }; // Logger
 
-std::string getTime();
-std::string getTid();
+    Logger& getLogger();
+    std::string getTime();
+    std::string getTid();
+
+#define DRILL_MT_LOG(LOG) \
+    { \
+    boost::lock_guard<boost::mutex> logLock(getLogger().m_logMutex); \
+    LOG \
+    }
 
 #define DRILL_LOG(level) \
-    if (Logger::s_pOutStream==NULL || level < Drill::Logger::s_level); \
-    else Drill::Logger::log(level)       \
+    if (getLogger().m_pOutStream==NULL || level < getLogger().m_level); \
+        else getLogger().log(level)       \
+
 
 } // namespace Drill
 

http://git-wip-us.apache.org/repos/asf/drill/blob/df0f0af3/contrib/native/client/src/clientlib/utils.cpp
----------------------------------------------------------------------
diff --git a/contrib/native/client/src/clientlib/utils.cpp 
b/contrib/native/client/src/clientlib/utils.cpp
index f1f03a1..1e6a877 100644
--- a/contrib/native/client/src/clientlib/utils.cpp
+++ b/contrib/native/client/src/clientlib/utils.cpp
@@ -1,68 +1,107 @@
 /*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
+* Licensed to the Apache Software Foundation (ASF) under one
+* or more contributor license agreements.  See the NOTICE file
+* distributed with this work for additional information
+* regarding copyright ownership.  The ASF licenses this file
+* to you under the Apache License, Version 2.0 (the
+* "License"); you may not use this file except in compliance
+* with the License.  You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
 
+#include <limits.h>
 #include <stdlib.h>
 #include "utils.hpp"
+#include "logger.hpp"
 #include "drill/common.hpp"
 
 namespace Drill{
 
 
+
+boost::random::random_device Utils::s_RNG;
+boost::random::mt19937 Utils::s_URNG(s_RNG());
+boost::uniform_int<> Utils::s_uniformDist(0,std::numeric_limits<int>::max()-1);
+boost::variate_generator<boost::random::mt19937&, boost::uniform_int<> > 
Utils::s_randomNumber(s_URNG, s_uniformDist);
+
 boost::mutex AllocatedBuffer::s_memCVMutex;
 boost::condition_variable AllocatedBuffer::s_memCV;
-size_t AllocatedBuffer::s_allocatedMem=0;
-bool AllocatedBuffer::s_isBufferLimitReached=false;
+size_t AllocatedBuffer::s_allocatedMem = 0;
+bool AllocatedBuffer::s_isBufferLimitReached = false;
+boost::mutex s_utilMutex;
 
 ByteBuf_t Utils::allocateBuffer(size_t len){
     boost::lock_guard<boost::mutex> memLock(AllocatedBuffer::s_memCVMutex);
-    AllocatedBuffer::s_allocatedMem+=len;
+    AllocatedBuffer::s_allocatedMem += len;
     
//http://stackoverflow.com/questions/2688466/why-mallocmemset-is-slower-than-calloc
-    ByteBuf_t b = (ByteBuf_t)calloc(len, sizeof(Byte_t)); 
-    size_t safeSize= DrillClientConfig::getBufferLimit()-MEM_CHUNK_SIZE;
-    if(b!=NULL && AllocatedBuffer::s_allocatedMem >= safeSize){
-        AllocatedBuffer::s_isBufferLimitReached=true;
+    ByteBuf_t b = (ByteBuf_t)calloc(len, sizeof(Byte_t));
+    size_t safeSize = DrillClientConfig::getBufferLimit() - MEM_CHUNK_SIZE;
+    if (b != NULL && AllocatedBuffer::s_allocatedMem >= safeSize){
+        AllocatedBuffer::s_isBufferLimitReached = true;
     }
     return b;
 }
 
-void Utils::freeBuffer(ByteBuf_t b, size_t len){ 
+void Utils::freeBuffer(ByteBuf_t b, size_t len){
     boost::lock_guard<boost::mutex> memLock(AllocatedBuffer::s_memCVMutex);
-    AllocatedBuffer::s_allocatedMem-=len;
-    free(b); 
-    size_t safeSize= DrillClientConfig::getBufferLimit()-MEM_CHUNK_SIZE;
-    if(b!=NULL && AllocatedBuffer::s_allocatedMem < safeSize){
-        AllocatedBuffer::s_isBufferLimitReached=false;
+    AllocatedBuffer::s_allocatedMem -= len;
+    free(b);
+    size_t safeSize = DrillClientConfig::getBufferLimit() - MEM_CHUNK_SIZE;
+    if (b != NULL && AllocatedBuffer::s_allocatedMem < safeSize){
+        AllocatedBuffer::s_isBufferLimitReached = false;
         //signal any waiting threads
         AllocatedBuffer::s_memCV.notify_one();
     }
 }
 
+void Utils::parseConnectStr(const char* connectStr,
+  std::string& pathToDrill,
+  std::string& protocol,
+  std::string& hostPortStr){
+    boost::lock_guard<boost::mutex> memLock(s_utilMutex);
+    char u[MAX_CONNECT_STR + 1];
+    strncpy(u, connectStr, MAX_CONNECT_STR); u[MAX_CONNECT_STR] = 0;
+    char* z = strtok(u, "=");
+    char* c = strtok(NULL, "/");
+    char* p = strtok(NULL, "");
+
+    if (p != NULL) pathToDrill = std::string("/") + p;
+    protocol = z; hostPortStr = c;
+    return;
+}
+
+void Utils::shuffle(std::vector<std::string>& vector){
+    std::random_shuffle(vector.begin(), vector.end(), Utils::s_randomNumber);
+    return;
+}
+
+void Utils::add(std::vector<std::string>& vector1, std::vector<std::string>& 
vector2){
+    std::vector<std::string>::iterator it;
+    for (it = vector2.begin(); it != vector2.end(); it++) {
+        std::vector<std::string>::iterator it2 = std::find(vector1.begin(), 
vector1.end(), *it);
+        if (it2 == vector1.end()){
+            vector1.push_back(*it);
+        }
+    }
+}
 
 AllocatedBuffer::AllocatedBuffer(size_t l){
-    m_pBuffer=NULL;
-    m_pBuffer=Utils::allocateBuffer(l);
-    m_bufSize=m_pBuffer!=NULL?l:0;
+    m_pBuffer = NULL;
+    m_pBuffer = Utils::allocateBuffer(l);
+    m_bufSize = m_pBuffer != NULL ? l : 0;
 }
 
 AllocatedBuffer::~AllocatedBuffer(){
-    Utils::freeBuffer(m_pBuffer, m_bufSize); 
-    m_pBuffer=NULL; 
-    m_bufSize=0;
+    Utils::freeBuffer(m_pBuffer, m_bufSize);
+    m_pBuffer = NULL;
+    m_bufSize = 0;
 }
 
 } // namespace 

http://git-wip-us.apache.org/repos/asf/drill/blob/df0f0af3/contrib/native/client/src/clientlib/utils.hpp
----------------------------------------------------------------------
diff --git a/contrib/native/client/src/clientlib/utils.hpp 
b/contrib/native/client/src/clientlib/utils.hpp
index 0f26ad6..36fb91f 100644
--- a/contrib/native/client/src/clientlib/utils.hpp
+++ b/contrib/native/client/src/clientlib/utils.hpp
@@ -1,20 +1,20 @@
 /*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
+* Licensed to the Apache Software Foundation (ASF) under one
+* or more contributor license agreements.  See the NOTICE file
+* distributed with this work for additional information
+* regarding copyright ownership.  The ASF licenses this file
+* to you under the Apache License, Version 2.0 (the
+* "License"); you may not use this file except in compliance
+* with the License.  You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
 
 #ifndef __UTILS_H
 #define __UTILS_H
@@ -23,6 +23,19 @@
 #include <ostream>
 #include <fstream>
 #include <string>
+#include <vector>
+
+#if defined _WIN32  || defined _WIN64
+  //Windows header files redefine 'random'
+  #ifdef random
+    #undef random
+  #endif
+#endif
+#include <boost/asio/deadline_timer.hpp>
+#include <boost/random/mersenne_twister.hpp> // for mt19937
+#include <boost/random/random_device.hpp>
+#include <boost/random/uniform_int.hpp>
+#include <boost/random/variate_generator.hpp>
 #include <boost/thread.hpp>
 
 #include "drill/common.hpp"
@@ -33,26 +46,57 @@ namespace Drill{
 // Wrapper Class to keep track of allocated memory
 class AllocatedBuffer{
     public:
-    AllocatedBuffer(size_t l);
-    ~AllocatedBuffer();
-
-    ByteBuf_t m_pBuffer;
-    size_t    m_bufSize;
-    
-    // keep track of allocated memory. The client lib blocks
-    // if we have allocated up to a limit (defined in drillClientConfig).
-    static boost::mutex s_memCVMutex;
-    static boost::condition_variable s_memCV;
-    static size_t s_allocatedMem;
-    static bool s_isBufferLimitReached;
+        AllocatedBuffer(size_t l);
+        ~AllocatedBuffer();
+
+        ByteBuf_t m_pBuffer;
+        size_t    m_bufSize;
+
+        // keep track of allocated memory. The client lib blocks
+        // if we have allocated up to a limit (defined in drillClientConfig).
+        static boost::mutex s_memCVMutex;
+        static boost::condition_variable s_memCV;
+        static size_t s_allocatedMem;
+        static bool s_isBufferLimitReached;
+        static boost::mutex s_utilMutex; // for provideing safety around 
strtok and other non-reentrant functions
 
 };
 
 class Utils{
     public:
+        static boost::random::random_device s_RNG;   //Truly random (expensive 
and device dependent)
+        static boost::random::mt19937 s_URNG; //Pseudo random with a period of 
( 2^19937 - 1 )
+        static boost::uniform_int<> s_uniformDist;      // Produces a uniform 
distribution
+        static boost::variate_generator<boost::random::mt19937&, 
boost::uniform_int<> > s_randomNumber; // a random number generator also usable 
by shuffle
+
         //allocate memory for Record Batches
         static ByteBuf_t allocateBuffer(size_t len);
         static void freeBuffer(ByteBuf_t b, size_t len);
+        static void parseConnectStr(const char* connectStr,
+            std::string& pathToDrill,
+            std::string& protocol,
+            std::string& hostPortStr);
+
+        // useful vector methods/idioms
+
+        // performs a random shuffle on a string vector
+        static void shuffle(std::vector<std::string>& vector);
+
+        // adds the contents of vector2 to vector1
+        static void add(std::vector<std::string>& vector1, 
std::vector<std::string>& vector2);
+
+        // removes the element from the vector
+        template <typename T> static void eraseRemove(std::vector<T>& vector, 
T elem){
+            vector.erase(std::remove(vector.begin(), vector.end(), elem), 
vector.end());
+        }
+
+        // Provide a to_string that works with older C++ compilers
+        template <typename T> static std::string to_string(T val) {
+            std::stringstream stream;
+            stream << val;
+            return stream.str();
+        }
+
 }; // Utils
 
 } // namespace Drill

http://git-wip-us.apache.org/repos/asf/drill/blob/df0f0af3/contrib/native/client/src/include/drill/common.hpp
----------------------------------------------------------------------
diff --git a/contrib/native/client/src/include/drill/common.hpp 
b/contrib/native/client/src/include/drill/common.hpp
index bb8e2b4..a617dc7 100644
--- a/contrib/native/client/src/include/drill/common.hpp
+++ b/contrib/native/client/src/include/drill/common.hpp
@@ -45,6 +45,11 @@
 #define MEM_CHUNK_SIZE 64*1024; // 64K
 #define MAX_MEM_ALLOC_SIZE 256*1024*1024; // 256 MB
 
+#define MAX_BATCH_SIZE  65536; // see RecordBatch.java 
+#define ENABLE_CONNECTION_POOL_ENV  "DRILL_ENABLE_CONN_POOL"
+#define DEFAULT_MAX_CONCURRENT_CONNECTIONS 10
+#define MAX_CONCURRENT_CONNECTIONS_ENV  "DRILL_MAX_CONN"
+
 #ifdef _DEBUG
 #define EXTRA_DEBUGGING
 #define CODER_DEBUGGING
@@ -110,7 +115,9 @@ typedef enum{
     CONN_HOSTNAME_RESOLUTION_ERROR=6,
     CONN_AUTH_FAILED=7,
     CONN_BAD_RPC_VER=8,
-    CONN_DEAD=9
+    CONN_DEAD=9,
+    CONN_NOTCONNECTED=10,
+    CONN_ALREADYCONNECTED=11
 } connectionStatus_t;
 
 typedef enum{

http://git-wip-us.apache.org/repos/asf/drill/blob/df0f0af3/contrib/native/client/src/include/drill/drillClient.hpp
----------------------------------------------------------------------
diff --git a/contrib/native/client/src/include/drill/drillClient.hpp 
b/contrib/native/client/src/include/drill/drillClient.hpp
index 4568ca1..a74f4bd 100644
--- a/contrib/native/client/src/include/drill/drillClient.hpp
+++ b/contrib/native/client/src/include/drill/drillClient.hpp
@@ -53,6 +53,7 @@ namespace exec{
 namespace Drill{
 
 //struct UserServerEndPoint;
+class  DrillClientImplBase;
 class  DrillClientImpl;
 class  DrillClientQueryResult;
 class  FieldMetadata;
@@ -340,6 +341,10 @@ class DECLSPEC_DRILL_CLIENT DrillClient{
         std::string& getError();
 
         /*
+         * Returns the error message associated with the query handle
+         */
+        const std::string& getError(QueryHandle_t handle);
+        /*
          * Applications using the async query submit method can register a 
listener for schema changes
          *
          */
@@ -369,7 +374,7 @@ class DECLSPEC_DRILL_CLIENT DrillClient{
         static DrillClientInitializer s_init;
         static DrillClientConfig s_config;
 
-        DrillClientImpl * m_pImpl;
+        DrillClientImplBase * m_pImpl;
 };
 
 } // namespace Drill

Reply via email to