-
Notifications
You must be signed in to change notification settings - Fork 15
ENG-15036 add c-client to voltdb-client-cpp #57
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
84ef1dd
52f4e0d
f34a6d3
0d19704
755640e
d87cdba
779d4a5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -16,14 +16,26 @@ The Linux binary was compiled with GCC 4.4.7 on Centos 6.7. | |||||||||
The OSX binary was compiled with Xcode 7.2 on OSX 10.11. | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OS X |
||||||||||
|
||||||||||
The source code is available in the [VoltDB Github repository] | ||||||||||
(https://github.com/VoltDB/voltdb-client-cpp). | ||||||||||
(https://github.com/VoltDB/voltdb-client-cpp). | ||||||||||
|
||||||||||
New Features in 8.4 | ||||||||||
================== | ||||||||||
- Removed dependency on Boost library (by taking advantage of C++11 features) | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
|
||||||||||
- Added a C wrapper for a few functions to support synchronous execution of Ad-Hoc query. | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
The wrapper can serve as a bridge to any client in most other programming languages. | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
|
||||||||||
New Features in 7.1 | ||||||||||
================== | ||||||||||
- Add SSL support to C++ client to enable communication between VoltDB server and C++ client over SSL transport. | ||||||||||
To enable communication between a VoltDB server with SSL enabled for the external ports and a C++ client, the client | ||||||||||
needs to be instantiated using client config (voltdb::ClientConfig) with the ssl field (m_useSSL) set to true. Code | ||||||||||
snippet: | ||||||||||
|
||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No newline after the horizontal rule to be consistent with other release notes. |
||||||||||
- Add SSL support to C++ client to enable communication between VoltDB server | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
and C++ client over SSL transport. | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
|
||||||||||
To enable communication between a VoltDB server with SSL enabled for the | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
external ports and a C++ client, the client needs to be instantiated using | ||||||||||
client config (voltdb::ClientConfig) with the ssl field (m_useSSL) set to true. | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
Code snippet: | ||||||||||
|
||||||||||
```C++ | ||||||||||
voltdb::ClientConfig config; | ||||||||||
... | ||||||||||
|
@@ -36,9 +48,13 @@ voltdb::Client client = voltdb::Client::create(config); | |||||||||
New Features in 7.0 | ||||||||||
================== | ||||||||||
- Support for Table (synomous to VoltTable on server side) in parameter set. | ||||||||||
How to construct table: initialize table with column schema. Generate row to be inserted - initialize the row with same | ||||||||||
column schema as that of table, populate the row and add the row to the table. After inserting the populated row to the | ||||||||||
table, the row instance can be reused to populate it row with new values and push it table. | ||||||||||
|
||||||||||
How to construct table: initialize table with column schema. Generate row to be | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
inserted - initialize the row with same column schema as that of table, | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
populate the row and add the row to the table. After inserting the populated | ||||||||||
row to the table, the row instance can be reused to populate with new values | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
and push to the table. | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
|
||||||||||
```C++ | ||||||||||
std::vector<voltdb::Column> columns; | ||||||||||
columns.push_back(voltdb::Column("col1", voltdb::WIRE_TYPE_BIGINT)); | ||||||||||
|
@@ -54,7 +70,10 @@ table.addRow(row); | |||||||||
|
||||||||||
New Features in V6.9 | ||||||||||
================== | ||||||||||
- Support for timing out outstanding/pending invocation requests. By default the monitoring of the pending requests for timeout is disabled. To exercise feature, timeout has to be enabled using client config. Default timeout is 10 seconds and can be tweaked through client config. | ||||||||||
- Support for timing out outstanding/pending invocation requests. By default | ||||||||||
the monitoring of the pending requests for timeout is disabled. To exercise | ||||||||||
feature, timeout has to be enabled using client config. Default timeout is 10 | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
seconds and can be tweaked through client config. | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
```C++ | ||||||||||
bool enableQueryTimeout = true; | ||||||||||
int queryTimeout = 10; | ||||||||||
|
@@ -65,9 +84,16 @@ voltdb::Client client = voltdb::Client::create(config); | |||||||||
|
||||||||||
New Features in V6.8 | ||||||||||
================== | ||||||||||
- Update backpressure notification to notify when backpressure on client transitions from on to off | ||||||||||
- Fix handling of pending connection logic where client gets disconnected and tries to reconnect, if socket timeout is longer than 10 seconds, it can potentially crash the client | ||||||||||
- Update setaffinity logic to not drop the set affinity request in case of backpresure with client configured with enable abandon set to true. | ||||||||||
|
||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No newline after the horizontal rule to be consistent with other release notes. |
||||||||||
- Update backpressure notification to notify when backpressure on client | ||||||||||
transitions from on to off | ||||||||||
|
||||||||||
- Fix handling of pending connection logic where client gets disconnected and | ||||||||||
tries to reconnect, if socket timeout is longer than 10 seconds, it can | ||||||||||
potentially crash the client | ||||||||||
|
||||||||||
- Update setaffinity logic to not drop the set affinity request in case of | ||||||||||
backpresure with client configured with enable abandon set to true. | ||||||||||
|
||||||||||
New Features in V6.0 | ||||||||||
================== | ||||||||||
|
@@ -146,10 +172,9 @@ clientvoter.cpp \ | |||||||||
./libevent_pthread.a \ | ||||||||||
-lrt \ | ||||||||||
-pthread \ | ||||||||||
-lboost_system \ | ||||||||||
-lboost_thread \ | ||||||||||
-o voter | ||||||||||
``` | ||||||||||
|
||||||||||
Note that -lrt should not be included for the mac edition. See the example makefile | ||||||||||
for more detail. | ||||||||||
|
||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This write-up is far from the documentation quality. I think I need this to be reviewed by Andrew @ajgent |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -25,7 +25,6 @@ | |||||
#define __STDC_LIMIT_MACROS | ||||||
|
||||||
#include <vector> | ||||||
#include <boost/shared_ptr.hpp> | ||||||
#include "Client.h" | ||||||
#include "Table.h" | ||||||
#include "TableIterator.h" | ||||||
|
@@ -35,6 +34,22 @@ | |||||
#include "ParameterSet.hpp" | ||||||
#include "ClientConfig.h" | ||||||
|
||||||
#include "CAPI.h" | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. By looking at the examples I found I think this is not a good practice to give examples. Does it mean that the C++ APIs are designed for the asynchronous mode and C APIs are designed for the syncrhonous mode? Maybe put the C examples into another file like |
||||||
|
||||||
void print_result(c_stringified_tables* r) { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. C naming convention is not just using Regardless what programming language you are using, it is highly preferred that you use a different naming convention for structs and variables so the readers can easily tell the difference if the source code is not colored by the IDE. For example, in Java, all the class names are in upper camel case, and variables are in lower camel case: More often than not, C structs use the upper camel case ( That being said, I am requesting the C structs you created in void print_result(CStringifiedTables* tables) { Futhermore, since this is an example that people may refer to to understand how to use the library, I suggest that you give the variable Lastly, the function code needs proper spacing. |
||||||
for(int tbl_index = 0; tbl_index < r->num_tables; ++tbl_index) { | ||||||
std::cout<<tbl_index<<" th table:"<<std::endl; | ||||||
const c_stringified_table& tbl = r->tables[tbl_index]; | ||||||
for(int row_index = 0; row_index < tbl.num_rows; ++row_index) { | ||||||
for(int col_index = 0; col_index < tbl.num_cols; ++col_index) { | ||||||
std::cout<<tbl.tuples[row_index][col_index]<<"\t"; | ||||||
} | ||||||
std::cout<<std::endl; | ||||||
} | ||||||
std::cout<<std::endl; | ||||||
} | ||||||
} | ||||||
|
||||||
int main(int argc, char **argv) { | ||||||
/* | ||||||
* Instantiate a client and connect to the database. | ||||||
|
@@ -51,6 +66,32 @@ int main(int argc, char **argv) { | |||||
parameterTypes[0] = voltdb::Parameter(voltdb::WIRE_TYPE_STRING); | ||||||
parameterTypes[1] = voltdb::Parameter(voltdb::WIRE_TYPE_STRING); | ||||||
parameterTypes[2] = voltdb::Parameter(voltdb::WIRE_TYPE_STRING); | ||||||
{ | ||||||
|
||||||
c_client* client = c_create_client("myusername", "mypassword", "localhost", 21212, false, | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
All C++ classes are under the |
||||||
/*voltdb::HASH_SHA1,*/ false, false, 10, false); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If |
||||||
c_procedure* adhoc = c_create_call(); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
What you are creating here is a call to a procedure, not a procedure itself. You need to avoid the confusion. |
||||||
std::vector<std::string> queries{ | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
"DROP TABLE foo IF EXISTS;", | ||||||
"CREATE TABLE foo(i int, j int);", | ||||||
"INSERT INTO foo VALUES(12, 14);", | ||||||
"INSERT INTO foo VALUES(18, NULL);", | ||||||
"INSERT INTO foo VALUES(14, 16);", | ||||||
"SELECT * FROM foo ORDER BY i;" | ||||||
}; | ||||||
for (std::string const& s : queries) { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
For readability. |
||||||
const char* params[] = {s.c_str(), nullptr}; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What I don't understand here is that why do you have to a |
||||||
c_invocation_response* response = c_exec_proc(client, adhoc, params); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
if (c_status_code(response) != 1) { std::cout <<"Failed" << std::endl; return -1; } | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Do not fold so many lines into one. |
||||||
} | ||||||
const char* params[] = {queries[5].c_str(), nullptr}; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Again, why |
||||||
c_invocation_response* response = c_exec_proc(client, adhoc, params); | ||||||
c_stringified_tables* result = c_exec_result(response); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
What does "execute result" mean? |
||||||
print_result(result); | ||||||
c_destroy_result(result); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
c_drop_procedure(adhoc); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
drop procedure has a very specific meaning in database semantics. You definitely don't mean that here. |
||||||
c_close(client); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Otherwise, close what? A file? |
||||||
} | ||||||
voltdb::Procedure procedure("Insert", parameterTypes); | ||||||
|
||||||
voltdb::InvocationResponse response; | ||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,48 +2,45 @@ VOLT_INCLUDEDIR=.. | |
VOLT_LIBDIR=.. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The first three lines of this file are all assigning the same value to different names, they can all be collapsed to one single |
||
VOLT_LIBS=$(VOLT_LIBDIR) | ||
VOLT_INCLUDES=-I$(VOLT_INCLUDEDIR)/include | ||
CC=g++ | ||
RM=rm -rf | ||
OPTIMIZATION=-O3 | ||
CFLAGS=$(BOOST_INCLUDES) $(VOLT_INCLUDES) -g3 ${OPTIMIZATION} | ||
CFLAGS += -fPIC | ||
CXXFLAGS=$(VOLT_INCLUDES) -std=c++11 -g3 -O3 -fPIC | ||
|
||
PLATFORM = $(shell uname) | ||
ifeq ($(PLATFORM),Darwin) | ||
BOOST_INCLUDES=-I/usr/local/include | ||
BOOST_LIBS=-L/usr/local/lib | ||
SYSTEM_LIBS := -lpthread $(BOOST_LIBS) -lboost_system-mt -lboost_thread-mt | ||
THIRD_PARTY_DIR := $(VOLT_LIBS)/third_party_libs/osx | ||
THIRD_PARTY_LIBS := $(THIRD_PARTY_DIR)/libevent.a \ | ||
$(THIRD_PARTY_DIR)/libevent_openssl.a \ | ||
$(THIRD_PARTY_DIR)/libevent_pthreads.a \ | ||
$(THIRD_PARTY_DIR)/libssl.a \ | ||
$(THIRD_PARTY_DIR)/libcrypto.a | ||
endif | ||
ifeq ($(PLATFORM),Linux) | ||
THIRD_PARTY_DIR := $(VOLT_LIBS)/third_party_libs/linux | ||
THIRD_PARTY_LIBS := $(THIRD_PARTY_DIR)/libevent.a \ | ||
$(THIRD_PARTY_DIR)/libevent_openssl.a \ | ||
$(THIRD_PARTY_DIR)/libevent_pthreads.a \ | ||
$(THIRD_PARTY_DIR)/libssl.a \ | ||
$(THIRD_PARTY_DIR)/libcrypto.a \ | ||
-ldl | ||
SYSTEM_LIBS := -lpthread -lrt -lboost_system -lboost_thread | ||
THIRD_PARTY_DIR := $(VOLT_LIBS)/third_party_libs/osx | ||
THIRD_PARTY_LIBS := $(THIRD_PARTY_DIR)/libevent.a \ | ||
$(THIRD_PARTY_DIR)/libevent_openssl.a \ | ||
$(THIRD_PARTY_DIR)/libevent_pthreads.a \ | ||
$(THIRD_PARTY_DIR)/libssl.a \ | ||
$(THIRD_PARTY_DIR)/libcrypto.a | ||
SYSTEM_LIBS := -lpthread | ||
else ifeq ($(PLATFORM),Linux) | ||
THIRD_PARTY_DIR := $(VOLT_LIBS)/third_party_libs/linux | ||
THIRD_PARTY_LIBS := $(THIRD_PARTY_DIR)/libevent.a \ | ||
$(THIRD_PARTY_DIR)/libevent_openssl.a \ | ||
$(THIRD_PARTY_DIR)/libevent_pthreads.a \ | ||
$(THIRD_PARTY_DIR)/libssl.a \ | ||
$(THIRD_PARTY_DIR)/libcrypto.a \ | ||
-ldl | ||
SYSTEM_LIBS := -lpthread -lrt | ||
else | ||
$(error "Unsupported platform $(PLATFORM)") | ||
endif | ||
|
||
all: helloworld asynchelloworld voter sslvoter | ||
|
||
asynchelloworld: AsyncHelloWorld.cpp $(VOLT_LIBS)/libvoltdbcpp.a | ||
$(CC) $(CFLAGS) AsyncHelloWorld.cpp $(VOLT_LIBS)/libvoltdbcpp.a $(THIRD_PARTY_LIBS) $(SYSTEM_LIBS) -o asynchelloworld | ||
$(CXX) $(CXXFLAGS) AsyncHelloWorld.cpp $(VOLT_LIBS)/libvoltdbcpp.a $(THIRD_PARTY_LIBS) $(SYSTEM_LIBS) -o asynchelloworld | ||
|
||
helloworld: HelloWorld.cpp $(VOLT_LIBS)/libvoltdbcpp.a | ||
$(CC) $(CFLAGS) HelloWorld.cpp $(VOLT_LIBS)/libvoltdbcpp.a $(THIRD_PARTY_LIBS) $(SYSTEM_LIBS) -o helloworld | ||
$(CXX) $(CXXFLAGS) HelloWorld.cpp $(VOLT_LIBS)/libvoltdbcpp.a $(THIRD_PARTY_LIBS) $(SYSTEM_LIBS) -o helloworld | ||
|
||
voter: Voter.cpp $(VOLT_LIBS)/libvoltdbcpp.a | ||
$(CC) $(CFLAGS) Voter.cpp $(VOLT_LIBS)/libvoltdbcpp.a $(THIRD_PARTY_LIBS) $(SYSTEM_LIBS) -o voter | ||
$(CXX) $(CXXFLAGS) Voter.cpp $(VOLT_LIBS)/libvoltdbcpp.a $(THIRD_PARTY_LIBS) $(SYSTEM_LIBS) -o voter | ||
|
||
sslvoter: SSLVoter.cpp $(VOLT_LIBS)/libvoltdbcpp.a | ||
$(CC) $(CFLAGS) SSLVoter.cpp $(VOLT_LIBS)/libvoltdbcpp.a $(THIRD_PARTY_LIBS) $(SYSTEM_LIBS) -o sslvoter | ||
$(CXX) $(CXXFLAGS) SSLVoter.cpp $(VOLT_LIBS)/libvoltdbcpp.a $(THIRD_PARTY_LIBS) $(SYSTEM_LIBS) -o sslvoter | ||
|
||
clean: | ||
$(RM) asynchelloworld helloworld voter sslvoter *.dSYM *~ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
More likely people need to add
sudo
to use this command.Plus,
apt get
without the dash is a legitimate way to call.This file was not written using MarkDown. If we do not intend to do so, we shouldn't use `