Commit df10bf62 authored by Casualet's avatar Casualet

clean std::cout

parent 9dcd9f88
#include <vector>
#include <iomanip>
#include <crypto/cbc.hh>
#include <crypto/cmc.hh>
#include <crypto/prng.hh>
#include <crypto/aes.hh>
#include <crypto/blowfish.hh>
#include <crypto/ope.hh>
#include <crypto/arc4.hh>
#include <crypto/hgd.hh>
#include <crypto/sha.hh>
#include <crypto/hmac.hh>
#include <crypto/paillier.hh>
#include <crypto/bn.hh>
#include <crypto/ecjoin.hh>
#include <crypto/search.hh>
#include <crypto/skip32.hh>
#include <crypto/cbcmac.hh>
#include <crypto/ffx.hh>
#include <crypto/online_ope.hh>
#include <crypto/padding.hh>
#include <crypto/mont.hh>
#include <crypto/gfe.hh>
#include <util/timer.hh>
#include <NTL/ZZ.h>
#include <NTL/RR.h>
using namespace std;
using namespace NTL;
template<class T>
void
test_block_cipher(T *c, PRNG *u, const std::string &cname)
{
auto pt = u->rand_string(c->blocksize);
string ct(pt.size(), 0);
string pt2(pt.size(), 0);
c->block_encrypt(&pt[0], &ct[0]);
c->block_decrypt(&ct[0], &pt2[0]);
throw_c(pt == pt2);
auto cbc_pt = u->rand_string(c->blocksize * 32);
auto cbc_iv = u->rand_string(c->blocksize);
string cbc_ct, cbc_pt2;
cbc_encrypt(c, cbc_iv, cbc_pt, &cbc_ct);
cbc_decrypt(c, cbc_iv, cbc_ct, &cbc_pt2);
throw_c(cbc_pt == cbc_pt2);
cmc_encrypt(c, cbc_pt, &cbc_ct);
cmc_decrypt(c, cbc_ct, &cbc_pt2);
throw_c(cbc_pt == cbc_pt2);
for (int i = 0; i < 1000; i++) {
auto cts_pt = u->rand_string(c->blocksize + (u->rand<size_t>() % 1024));
auto cts_iv = u->rand_string(c->blocksize);
string cts_ct, cts_pt2;
cbc_encrypt(c, cts_iv, cts_pt, &cts_ct);
cbc_decrypt(c, cts_iv, cts_ct, &cts_pt2);
throw_c(cts_pt == cts_pt2);
}
enum { nperf = 1000 };
auto cbc_perf_pt = u->rand_string(1024);
auto cbc_perf_iv = u->rand_string(c->blocksize);
string cbc_perf_ct, cbc_perf_pt2;
timer cbc_perf;
for (uint i = 0; i < nperf; i++) {
cbc_encrypt(c, cbc_perf_iv, cbc_perf_pt, &cbc_perf_ct);
if (i == 0) {
cbc_decrypt(c, cbc_perf_iv, cbc_perf_ct, &cbc_perf_pt2);
throw_c(cbc_perf_pt == cbc_perf_pt2);
}
}
cout << cname << "-cbc speed: "
<< cbc_perf_pt.size() * nperf * 1000 * 1000 / cbc_perf.lap() << endl;
timer cmc_perf;
for (uint i = 0; i < nperf; i++) {
cmc_encrypt(c, cbc_perf_pt, &cbc_perf_ct);
if (i == 0) {
cmc_decrypt(c, cbc_perf_ct, &cbc_perf_pt2);
throw_c(cbc_perf_pt == cbc_perf_pt2);
}
}
cout << cname << "-cmc speed: "
<< cbc_perf_pt.size() * nperf * 1000 * 1000 / cmc_perf.lap() << endl;
}
static void
test_ope(int pbits, int cbits)
{
urandom u;
OPE o("hello world", pbits, cbits);
RR maxerr = to_RR(0);
timer t;
enum { niter = 100 };
for (uint i = 1; i < niter; i++) {
ZZ pt = u.rand_zz_mod(to_ZZ(1) << pbits);
ZZ ct = o.encrypt(pt);
ZZ pt2 = o.decrypt(ct);
throw_c(pt2 == pt);
// cout << pt << " -> " << o.encrypt(pt, -1) << "/" << ct << "/" << o.encrypt(pt, 1) << " -> " << pt2 << endl;
RR::SetPrecision(cbits+pbits);
ZZ guess = ct / (to_ZZ(1) << (cbits-pbits));
RR error = abs(to_RR(guess) / to_RR(pt) - 1);
maxerr = max(error, maxerr);
// cout << "pt guess is " << error << " off" << endl;
}
cout << "--- ope: " << pbits << "-bit plaintext, "
<< cbits << "-bit ciphertext" << endl
<< " enc/dec pair: " << t.lap() / niter << " usec; "
<< "~#bits leaked: "
<< ((maxerr < pow(to_RR(2), to_RR(-pbits))) ? pbits
: NumBits(to_ZZ(1/maxerr))) << endl;
}
static void
test_hgd()
{
streamrng<arc4> r("hello world");
ZZ s;
s = HGD(to_ZZ(100), to_ZZ(100), to_ZZ(100), &r);
throw_c(s > 0 && s < 100);
s = HGD(to_ZZ(100), to_ZZ(0), to_ZZ(100), &r);
throw_c(s == 0);
s = HGD(to_ZZ(100), to_ZZ(100), to_ZZ(0), &r);
throw_c(s == 100);
}
static void
test_paillier()
{
urandom u;
auto sk = Paillier_priv::keygen(&u);
Paillier_priv pp(sk);
auto pk = pp.pubkey();
Paillier p(pk);
ZZ pt0 = u.rand_zz_mod(to_ZZ(1) << 256);
ZZ pt1 = u.rand_zz_mod(to_ZZ(1) << 256);
ZZ ct0 = p.encrypt(pt0);
ZZ ct1 = p.encrypt(pt1);
ZZ sum = p.add(ct0, ct1);
throw_c(pp.decrypt(ct0) == pt0);
throw_c(pp.decrypt(ct1) == pt1);
throw_c(pp.decrypt(sum) == (pt0 + pt1));
ZZ v0 = u.rand_zz_mod(to_ZZ(1) << 256);
ZZ v1 = u.rand_zz_mod(to_ZZ(1) << 256);
throw_c(pp.decrypt(p.mul(p.encrypt(v0), v1)) == v0 * v1);
ZZ a = p.encrypt(pt0);
ZZ b = p.encrypt(pt1);
timer sumperf;
for (int i = 0; i < 1000; i++) {
a = p.add(a, b);
}
cout << "paillier add: "
<< ((double) sumperf.lap()) / 1000 << " usec" << endl;
for (int i = 0; i < 10; i++) {
blockrng<AES> br(u.rand_string(16));
auto v = u.rand_string(AES::blocksize);
br.set_ctr(v);
auto sk0 = Paillier_priv::keygen(&br);
br.set_ctr(v);
auto sk1 = Paillier_priv::keygen(&br);
throw_c(sk0 == sk1);
}
}
static void
test_paillier_packing()
{
urandom u;
Paillier_priv pp(Paillier_priv::keygen(&u));
Paillier p(pp.pubkey());
uint32_t npack = p.pack_count<uint64_t>();
cout << "paillier pack count for uint64_t: " << npack << endl;
std::vector<uint64_t> a;
for (uint i = 0; i < npack; i++)
a.push_back(u.rand<uint32_t>());
ZZ ct = p.encrypt_pack(a);
for (uint x = 0; x < 10; x++) {
ZZ agg = to_ZZ(1);
uint64_t plainagg = 0;
uint64_t mask = u.rand<uint64_t>();
for (uint idx = 0; idx < npack; idx++) {
if (mask & (1 << idx)) {
plainagg += a[idx];
agg = p.add_pack<uint64_t>(agg, ct, idx);
}
}
uint64_t decagg = pp.decrypt_pack<uint64_t>(agg);
// cout << hex << "pack: " << decagg << ", " << plainagg << dec << endl;
throw_c(decagg == to_ZZ(plainagg));
}
uint32_t npack2 = p.pack2_count<uint64_t>();
cout << "paillier pack2 count for uint64_t: " << npack2 << endl;
std::vector<uint64_t> b[32];
ZZ bct[32];
for (uint i = 0; i < 32; i++) {
for (uint j = 0; j < npack2; j++)
b[i].push_back(u.rand<uint32_t>());
bct[i] = p.encrypt_pack2(b[i]);
}
for (uint x = 0; x < 100; x++) {
Paillier::pack2_agg<uint64_t> agg(&p);
uint64_t plainagg = 0;
for (uint i = 0; i < 32; i++) {
uint64_t mask = u.rand<uint64_t>();
for (uint idx = 0; idx < npack2; idx++) {
if (mask & (1 << idx)) {
plainagg += b[i][idx];
agg.add(bct[i], idx);
}
}
}
uint64_t decagg = pp.decrypt_pack2<uint64_t>(agg);
// cout << hex << "pack2: " << decagg << ", " << plainagg << dec << endl;
throw_c(decagg == to_ZZ(plainagg));
}
}
static void
test_montgomery()
{
urandom u;
ZZ n = RandomPrime_ZZ(512) * RandomPrime_ZZ(512);
ZZ m = n * n;
montgomery mm(m);
for (int i = 0; i < 1000; i++) {
ZZ a = u.rand_zz_mod(m);
ZZ b = u.rand_zz_mod(m);
ZZ ma = mm.to_mont(a);
ZZ mb = mm.to_mont(b);
throw_c(a == mm.from_mont(ma));
throw_c(b == mm.from_mont(mb));
ZZ ab = MulMod(a, b, m);
ZZ mab = mm.mmul(ma, mb);
throw_c(ab == mm.from_mont(mab));
}
cout << "montgomery ok" << endl;
ZZ x = u.rand_zz_mod(m);
ZZ mx = mm.to_mont(x);
timer tplain;
ZZ p = x;
for (int i = 0; i < 100000; i++)
p = MulMod(p, x, m);
cout << "regular multiply: " << tplain.lap() << " usec for 100k" << endl;
timer tmont;
ZZ mp = mx;
for (int i = 0; i < 100000; i++)
mp = mm.mmul(mp, mx);
cout << "montgomery multiply: " << tmont.lap() << " usec for 100k" << endl;
}
static void
test_bn()
{
bignum a(123);
bignum b(20);
bignum c(78);
bignum d(500);
auto r = (a + b * c) % d;
throw_c(r == 183);
throw_c(r <= 183);
throw_c(r <= 184);
throw_c(r < 184);
throw_c(r >= 183);
throw_c(r >= 181);
throw_c(r > 181);
streamrng<arc4> rand("seed");
throw_c(rand.rand_bn_mod(1000) == 498);
}
static void
test_ecjoin()
{
ecjoin_priv e("hello world");
auto p1 = e.hash("some data", "hash key");
auto p2 = e.hash("some data", "hash key");
throw_c(p1 == p2);
auto p3 = e.hash("some data", "another hash key");
auto p4 = e.hash("other data", "hash key");
throw_c(p1 != p4);
throw_c(p3 != p4);
bignum d = e.delta("another hash key", "hash key");
auto p5 = e.adjust(p3, d);
throw_c(p1 == p5);
}
static void
test_search()
{
search_priv s("my key");
auto cl = s.transform({"hello", "world", "hello", "testing", "test"});
throw_c(s.match(cl, s.wordkey("hello")));
throw_c(!s.match(cl, s.wordkey("Hello")));
throw_c(s.match(cl, s.wordkey("world")));
}
static void
test_skip32(void)
{
std::vector<uint8_t> k = { 0x00, 0x99, 0x88, 0x77, 0x66,
0x55, 0x44, 0x33, 0x22, 0x11 };
skip32 s(k);
uint8_t pt[4] = { 0x33, 0x22, 0x11, 0x00 };
uint8_t ct[4];
s.block_encrypt(pt, ct);
throw_c(ct[0] == 0x81 && ct[1] == 0x9d && ct[2] == 0x5f && ct[3] == 0x1f);
uint8_t pt2[4];
s.block_decrypt(ct, pt2);
throw_c(pt2[0] == 0x33 && pt2[1] == 0x22 && pt2[2] == 0x11 && pt2[3] == 0x00);
}
static void
test_ffx()
{
streamrng<arc4> rnd("test seed");
AES key(rnd.rand_string(16));
for (int i = 0; i < 1000; i++) {
uint nbits = 8 + (rnd.rand<uint>() % 121);
auto pt = rnd.rand_vec<uint8_t>((nbits + 7) / 8);
auto t = rnd.rand_vec<uint8_t>(rnd.rand<uint>() % 1024);
uint lowbits = nbits % 8;
pt[(nbits-1) / 8] &= ~0 << (8 - lowbits);
std::vector<uint8_t> ct, pt2;
ct.resize(pt.size());
pt2.resize(pt.size());
ffx2<AES> f0(&key, nbits, t);
f0.encrypt(&pt[0], &ct[0]);
ffx2<AES> f1(&key, nbits, t); /* duplicate of f0, for testing */
f1.decrypt(&ct[0], &pt2[0]);
if (0) {
cout << "nbits: " << nbits << endl;
cout << "plaintext: ";
for (auto &x: pt)
cout << hex << setw(2) << setfill('0') << (uint) x;
cout << dec << endl;
cout << "ciphertext: ";
for (auto &x: ct)
cout << hex << setw(2) << setfill('0') << (uint) x;
cout << dec << endl;
cout << "plaintext2: ";
for (auto &x: pt2)
cout << hex << setw(2) << setfill('0') << (uint) x;
cout << dec << endl;
}
throw_c(pt != ct);
throw_c(pt == pt2);
}
urandom u;
auto tweak = u.rand_vec<uint8_t>(1024);
blowfish bf(u.rand_string(128));
ffx2_block_cipher<AES, 128> fbca128(&key, tweak);
test_block_cipher(&fbca128, &u, "ffx128-aes128");
ffx2_block_cipher<blowfish, 128> fbcb128(&bf, tweak);
test_block_cipher(&fbcb128, &u, "ffx128-bf");
ffx2_block_cipher<AES, 64> fbc64(&key, tweak);
test_block_cipher(&fbc64, &u, "ffx64-aes128");
ffx2_block_cipher<blowfish, 64> fbcb64(&bf, tweak);
test_block_cipher(&fbcb64, &u, "ffx64-bf");
ffx2_block_cipher<AES, 32> fbc32(&key, tweak);
test_block_cipher(&fbc32, &u, "ffx32-aes128");
ffx2_block_cipher<blowfish, 32> fbcb32(&bf, tweak);
test_block_cipher(&fbcb32, &u, "ffx32-bf");
if (0) { /* Painfully slow */
ffx2_block_cipher<AES, 16> fbc16(&key, tweak);
test_block_cipher(&fbc16, &u, "ffx16-aes128");
ffx2_block_cipher<blowfish, 16> fbcb16(&bf, tweak);
test_block_cipher(&fbcb16, &u, "ffx16-bf");
ffx2_block_cipher<AES, 8> fbc8(&key, tweak);
test_block_cipher(&fbc8, &u, "ffx8-aes128");
ffx2_block_cipher<blowfish, 8> fbcb8(&bf, tweak);
test_block_cipher(&fbcb8, &u, "ffx8-bf");
}
}
static void
test_online_ope()
{
cerr << "test online ope .. \n";
urandom u;
blowfish bf(u.rand_string(128));
ffx2_block_cipher<blowfish, 16> fk(&bf, {});
ope_server<uint16_t> ope_serv;
ope_client<uint16_t, ffx2_block_cipher<blowfish, 16>> ope_clnt(&fk, &ope_serv);
for (uint i = 0; i < 1000; i++) {
// cerr << "============= i = " << i << "========" << "\n";
uint64_t pt = u.rand<uint16_t>();
// cout << "online-ope pt: " << pt << endl;
auto ct = ope_clnt.encrypt(pt);
// cout << "online-ope ct: " << hex << ct << dec << endl;
//print_tree(ope_serv.root);
auto pt2 = ope_clnt.decrypt(ct);
// cout << "online-ope pt2: " << pt2 << endl;
throw_c(pt == pt2);
}
for (uint i = 0; i < 1000; i++) {
uint8_t a = u.rand<uint8_t>();
uint8_t b = u.rand<uint8_t>();
ope_clnt.encrypt(a);
ope_clnt.encrypt(b);
auto ac = ope_clnt.encrypt(a);
auto bc = ope_clnt.encrypt(b);
//cout << "a=" << hex << (uint64_t) a << ", ac=" << ac << dec << endl;
//cout << "b=" << hex << (uint64_t) b << ", bc=" << bc << dec << endl;
if (a == b)
throw_c(ac == bc);
else if (a > b)
throw_c(ac > bc);
else
throw_c(ac < bc);
}
}
static void
test_online_ope_rebalance()
{
urandom u;
blowfish bf(u.rand_string(128));
ffx2_block_cipher<blowfish, 16> fk(&bf, {});
ope_server<uint16_t> ope_serv;
ope_client<uint16_t, ffx2_block_cipher<blowfish, 16>> ope_clnt(&fk, &ope_serv);
// only manual testing so far -- when balancing is implemented this will be automated
ope_clnt.encrypt(10);
ope_clnt.encrypt(20);
ope_clnt.encrypt(30);
ope_clnt.encrypt(5);
ope_clnt.encrypt(1);
ope_clnt.encrypt(8);
ope_clnt.encrypt(3);
ope_clnt.encrypt(200);
cerr << "test online ope rebalance OK \n";
}
static void
test_padding()
{
urandom u;
for (int i = 0; i < 1000; i++) {
size_t blocksize = 1 + (u.rand<size_t>() % 32);
auto v = u.rand_string(u.rand<size_t>() % 8192);
auto v2 = v;
pad_blocksize(&v2, blocksize);
throw_c((v2.size() % blocksize) == 0);
unpad_blocksize(&v2, blocksize);
throw_c(v == v2);
}
cout << "test padding ok\n";
}
template<typename T>
static void
test_gfe(size_t q)
{
urandom u;
gfe_priv<T> gp(u.rand_string(16), q);
for (int i = 0; i < 100; i++) {
// Check PRF generation
int a = u.rand<uint8_t>();
int b = u.rand<uint8_t>();
auto x = u.rand<T>();
auto y = u.rand<T>();
if (x == y)
y++;
if (a == b)
b++;
throw_c(gp.prf(make_pair(a, x)) == gp.prf(make_pair(a, x)));
throw_c(gp.prf(make_pair(a, x)) != gp.prf(make_pair(a, y)));
throw_c(gp.prf(make_pair(a, x)) != gp.prf(make_pair(b, x)));
throw_c(gp.prf(make_pair(a, x)) != gp.prf(make_pair(b, y)));
throw_c(gp.prf(make_pair(a, x)) != gp.prf(make_pair(-1, x)));
throw_c(gp.prf(make_pair(a, x)) != gp.prf(make_pair(-1, y)));
throw_c(gp.prf(make_pair(-1, x)) != gp.prf(make_pair(-1, x)));
}
for (int i = 0; i < 1000; i++) {
auto x = u.rand<T>();
auto y = u.rand<T>();
// Check prefix generation
auto xv = gfe<T>::cover_prefixes(x);
auto yv = gfe<T>::right_prefixes(y);
throw_c(xv.size() == yv.size());
int match = 0;
for (uint i = 0; i < xv.size(); i++)
if (xv[i] == yv[i])
match++;
if (x > y)
throw_c(match == 1);
else
throw_c(match == 0);
}
for (int i = 0; i < 100; i++) {
auto x = u.rand<T>();
auto y = u.rand<T>();
auto xv = gfe<T>::cover_prefixes(x);
auto yv = gfe<T>::right_prefixes(y);
// Check dot-product
auto xpv = gp.prfvec(xv);
auto ypv = gp.prfvec(yv);
uint64_t dp = gfe<T>::dotproduct(xpv, ypv);
// cout << "x " << (int)x << ", y " << (int)y << ", dp " << dp << endl;
if (x > y)
throw_c(labs(dp - gp.e1_) < labs(dp - gp.e0_));
else
throw_c(labs(dp - gp.e0_) < labs(dp - gp.e1_));
}
cout << "test_gfe size " << sizeof(T) << " q " << q << " ok\n";
}
int
main(int ac, char **av)
{
urandom u;
cout << u.rand<uint64_t>() << endl;
cout << u.rand<int64_t>() << endl;
test_online_ope_rebalance();
test_gfe<uint8_t>(4);
test_gfe<uint16_t>(3);
test_gfe<uint32_t>(3);
test_gfe<uint64_t>(3);
test_padding();
test_bn();
test_ecjoin();
test_search();
test_paillier();
test_paillier_packing();
test_montgomery();
test_skip32();
test_online_ope();
test_ffx();
AES aes128(u.rand_string(16));
test_block_cipher(&aes128, &u, "aes-128");
AES aes256(u.rand_string(32));
test_block_cipher(&aes256, &u, "aes-256");
blowfish bf(u.rand_string(128));
test_block_cipher(&bf, &u, "blowfish");
skip32 s32(u.rand_vec<uint8_t>(10));
test_block_cipher(&s32, &u, "skip32");
auto hv = sha256::hash("Hello world\n");
for (auto &x: hv)
cout << hex << setw(2) << setfill('0') << (uint) x;
cout << dec << endl;
auto mv = hmac<sha256>::mac("Hello world\n", "key");
for (auto &x: mv)
cout << hex << setw(2) << setfill('0') << (uint) x;
cout << dec << endl;
cbcmac<AES> cmac(&aes256);
cmac.update(sha256::hash("Hello world\n"));
for (auto &x: cmac.final())
cout << hex << setw(2) << setfill('0') << (uint) x;
cout << dec << endl;
test_hgd();
for (int pbits = 32; pbits <= 128; pbits += 32)
for (int cbits = pbits; cbits <= pbits + 128; cbits += 32)
test_ope(pbits, cbits);
}
...@@ -540,7 +540,6 @@ bool CreateDelta::apply(const std::unique_ptr<Connect> &e_conn, ...@@ -540,7 +540,6 @@ bool CreateDelta::apply(const std::unique_ptr<Connect> &e_conn,
" '" + esc_serial_key + "'," " '" + esc_serial_key + "',"
" " + std::to_string(parent_id) + "," " " + std::to_string(parent_id) + ","
" " + std::to_string(old_object_id.get()) + ");"; " " + std::to_string(old_object_id.get()) + ");";
std::cout<<"query in writedelta:"<<query<<std::endl;
RETURN_FALSE_IF_FALSE(e_conn->execute(query)); RETURN_FALSE_IF_FALSE(e_conn->execute(query));
const unsigned int object_id = e_conn->last_insert_id(); const unsigned int object_id = e_conn->last_insert_id();
...@@ -675,7 +674,6 @@ deltaOutputBeforeQuery(const std::unique_ptr<Connect> &e_conn, ...@@ -675,7 +674,6 @@ deltaOutputBeforeQuery(const std::unique_ptr<Connect> &e_conn,
" (SELECT DATABASE()), FALSE," " (SELECT DATABASE()), FALSE,"
" '" + TypeText<CompletionType>::toText(completion_type) + "'" " '" + TypeText<CompletionType>::toText(completion_type) + "'"
" );"; " );";
std::cout<<q_completion<<std::endl;
ROLLBACK_AND_RFIF(e_conn->execute(q_completion), e_conn); ROLLBACK_AND_RFIF(e_conn->execute(q_completion), e_conn);
*embedded_completion_id = e_conn->last_insert_id(); *embedded_completion_id = e_conn->last_insert_id();
assert(*embedded_completion_id); assert(*embedded_completion_id);
......
...@@ -221,14 +221,12 @@ class CreateDBHandler : public DDLHandler { ...@@ -221,14 +221,12 @@ class CreateDBHandler : public DDLHandler {
rewriteAndUpdate(Analysis &a, LEX *const lex, const Preamble &pre) rewriteAndUpdate(Analysis &a, LEX *const lex, const Preamble &pre)
const const
{ {
std::cout<<__PRETTY_FUNCTION__<<":"<<__LINE__<<":"<<__FILE__<<":"<<__LINE__<<std::endl<<std::endl;
assert(a.deltas.size() == 0); assert(a.deltas.size() == 0);
const std::string &dbname = const std::string &dbname =
convert_lex_str(lex->name); convert_lex_str(lex->name);
if (false == a.databaseMetaExists(dbname)) { if (false == a.databaseMetaExists(dbname)) {
std::unique_ptr<DatabaseMeta> dm(new DatabaseMeta()); std::unique_ptr<DatabaseMeta> dm(new DatabaseMeta());
std::cout<<"create_db_id= : "<<dm->getDatabaseID()<<std::endl;
//可以看到, 建立数据库的时候,和建立表的时候类型, 使用了createdelta, 添加了从db到schema的映射过程. //可以看到, 建立数据库的时候,和建立表的时候类型, 使用了createdelta, 添加了从db到schema的映射过程.
a.deltas.push_back(std::unique_ptr<Delta>( a.deltas.push_back(std::unique_ptr<Delta>(
new CreateDelta(std::move(dm), a.getSchema(), new CreateDelta(std::move(dm), a.getSchema(),
...@@ -240,7 +238,6 @@ class CreateDBHandler : public DDLHandler { ...@@ -240,7 +238,6 @@ class CreateDBHandler : public DDLHandler {
TEST_TextMessageError(test, TEST_TextMessageError(test,
"Database " + dbname + " already exists!"); "Database " + dbname + " already exists!");
} }
std::cout<<"delta_size: "<<a.deltas.size()<<std::endl;
return new DDLQueryExecutor(*copyWithTHD(lex), std::move(a.deltas)); return new DDLQueryExecutor(*copyWithTHD(lex), std::move(a.deltas));
} }
}; };
...@@ -399,7 +396,6 @@ nextImpl(const ResType &res, const NextParams &nparams) ...@@ -399,7 +396,6 @@ nextImpl(const ResType &res, const NextParams &nparams)
"deltaOutputBeforeQuery failed for DDL"); "deltaOutputBeforeQuery failed for DDL");
this->embedded_completion_id = embedded_completion_id; this->embedded_completion_id = embedded_completion_id;
} }
std::cout<<RED_BEGIN<<"rewritten DDL: "<<this->new_query<<COLOR_END<<std::endl;
return CR_QUERY_AGAIN(this->new_query); return CR_QUERY_AGAIN(this->new_query);
} }
TEST_ErrPkt(res.success(), "DDL query failed"); TEST_ErrPkt(res.success(), "DDL query failed");
......
...@@ -56,7 +56,6 @@ void rewriteInsertHelper(const Item &i, const FieldMeta &fm, Analysis &a, ...@@ -56,7 +56,6 @@ void rewriteInsertHelper(const Item &i, const FieldMeta &fm, Analysis &a,
//这里先做lookup, 找到类以后调用内部的结果, 试试 //这里先做lookup, 找到类以后调用内部的结果, 试试
//对于普通的student操作, 最后调用的是ANON的typical_rewrite_insert_type来进行重写. //对于普通的student操作, 最后调用的是ANON的typical_rewrite_insert_type来进行重写.
itemTypes.do_rewrite_insert(i, fm, a, &l); itemTypes.do_rewrite_insert(i, fm, a, &l);
std::cout<<"size after do_rewrite_insert: "<<l.size()<<std::endl;
for (auto it : l) { for (auto it : l) {
append_list->push_back(it); append_list->push_back(it);
} }
...@@ -166,7 +165,6 @@ class InsertHandler : public DMLHandler { ...@@ -166,7 +165,6 @@ class InsertHandler : public DMLHandler {
// ----------------- // -----------------
if (lex->many_values.head()) { if (lex->many_values.head()) {
//开始处理many values //开始处理many values
std::cout<<"start many values"<<std::endl;
auto it = List_iterator<List_item>(lex->many_values); auto it = List_iterator<List_item>(lex->many_values);
List<List_item> newList; List<List_item> newList;
for (;;) { for (;;) {
...@@ -187,14 +185,13 @@ class InsertHandler : public DMLHandler { ...@@ -187,14 +185,13 @@ class InsertHandler : public DMLHandler {
//li指向了lex->many_values的迭代内容 //li指向了lex->many_values的迭代内容
auto it0 = List_iterator<Item>(*li); auto it0 = List_iterator<Item>(*li);
auto fmVecIt = fmVec.begin(); auto fmVecIt = fmVec.begin();
int lnum=0;
for (;;) { for (;;) {
const Item *const i = it0++; const Item *const i = it0++;
assert(!!i == (fmVec.end() != fmVecIt)); assert(!!i == (fmVec.end() != fmVecIt));
if (!i) { if (!i) {
break; break;
} }
std::cout<<"c"<<lnum++<<std::endl;
//获得values中的内容,并且通过fieldMeta好帮助完成rewrite工作 //获得values中的内容,并且通过fieldMeta好帮助完成rewrite工作
//每个field都要进行洋葱的加密. //每个field都要进行洋葱的加密.
rewriteInsertHelper(*i, **fmVecIt, a, newList0); rewriteInsertHelper(*i, **fmVecIt, a, newList0);
...@@ -469,7 +466,6 @@ process_filters_lex(const st_select_lex &select_lex, Analysis &a) ...@@ -469,7 +466,6 @@ process_filters_lex(const st_select_lex &select_lex, Analysis &a)
void void
process_select_lex(const st_select_lex &select_lex, Analysis &a) process_select_lex(const st_select_lex &select_lex, Analysis &a)
{ {
// std::cout<<__PRETTY_FUNCTION__<<":"<<__LINE__<<":"<<__FILE__<<":"<<__LINE__<<std::endl<<std::endl;
//可以看到, 首先处理top_join_list, 是List<TABLE_LIST>类型. 其含义是join list of the top level. //可以看到, 首先处理top_join_list, 是List<TABLE_LIST>类型. 其含义是join list of the top level.
//内部分别用process_table_aliases(tll, a); process_table_joins_and_derived(tll, a);两个函数处理. //内部分别用process_table_aliases(tll, a); process_table_joins_and_derived(tll, a);两个函数处理.
//如果不是jion式的语句, 就不用管了.其内部通过递归处理nested join, 并且处理了*on*语句. //如果不是jion式的语句, 就不用管了.其内部通过递归处理nested join, 并且处理了*on*语句.
...@@ -488,10 +484,8 @@ process_select_lex(const st_select_lex &select_lex, Analysis &a) ...@@ -488,10 +484,8 @@ process_select_lex(const st_select_lex &select_lex, Analysis &a)
if (!item) if (!item)
break; break;
numOfItem++; numOfItem++;
std::cout<<"item name in process_select_lex: "<<item->name<<std::endl;
gatherAndAddAnalysisRewritePlan(*item, a); gatherAndAddAnalysisRewritePlan(*item, a);
} }
std::cout<<"numOfItem: "<<numOfItem<<std::endl;
//这里处理的是select_lex.where和select_lex.having, 通过Item类型的函数, 也就是下面那个, 为其添加 //这里处理的是select_lex.where和select_lex.having, 通过Item类型的函数, 也就是下面那个, 为其添加
//rewriteplain. 然后再通过process_order, 对select_lex.group_list和select_lex.order_list添加 //rewriteplain. 然后再通过process_order, 对select_lex.group_list和select_lex.order_list添加
//rewritePlain //rewritePlain
...@@ -662,21 +656,17 @@ rewrite_proj(const Item &i, const RewritePlan &rp, Analysis &a, ...@@ -662,21 +656,17 @@ rewrite_proj(const Item &i, const RewritePlan &rp, Analysis &a,
AssignOnce<Item *> ir; AssignOnce<Item *> ir;
if (i.type() == Item::Type::FIELD_ITEM) { if (i.type() == Item::Type::FIELD_ITEM) {
std::cout<<"type= "<<"FIELD_ITEM"<<std::endl;
const Item_field &field_i = static_cast<const Item_field &>(i); const Item_field &field_i = static_cast<const Item_field &>(i);
const auto &cached_rewritten_i = a.item_cache.find(&field_i); const auto &cached_rewritten_i = a.item_cache.find(&field_i);
if (cached_rewritten_i != a.item_cache.end()) { if (cached_rewritten_i != a.item_cache.end()) {
std::cout<<"used cached plain: "<<std::endl;
ir = cached_rewritten_i->second.first; ir = cached_rewritten_i->second.first;
olk = cached_rewritten_i->second.second; olk = cached_rewritten_i->second.second;
} else { } else {
std::cout<<"do not use cached plain: "<<std::endl;
//对于select中的选择域来说,这里对应的是rewrite_field.cc中的83, do_rewrite_type //对于select中的选择域来说,这里对应的是rewrite_field.cc中的83, do_rewrite_type
ir = rewrite(i, rp.es_out, a); ir = rewrite(i, rp.es_out, a);
olk = rp.es_out.chooseOne(); olk = rp.es_out.chooseOne();
} }
} else { } else {
std::cout<<"type != FIELD_ITEM"<<std::endl;
ir = rewrite(i, rp.es_out, a); ir = rewrite(i, rp.es_out, a);
olk = rp.es_out.chooseOne(); olk = rp.es_out.chooseOne();
} }
...@@ -726,13 +716,11 @@ rewrite_select_lex(const st_select_lex &select_lex, Analysis &a) ...@@ -726,13 +716,11 @@ rewrite_select_lex(const st_select_lex &select_lex, Analysis &a)
if (!item) if (!item)
break; break;
numOfItem++; numOfItem++;
std::cout<<"itemname before: "<<item->name<<std::endl;
rewrite_proj(*item, rewrite_proj(*item,
*constGetAssert(a.rewritePlans, item).get(), *constGetAssert(a.rewritePlans, item).get(),
a, &newList); a, &newList);
} }
std::cout<<"numOfItem: "<<numOfItem<<std::endl;
// auto item_it_new = // auto item_it_new =
// RiboldMYSQL::constList_iterator<Item>(newList); // RiboldMYSQL::constList_iterator<Item>(newList);
// std::cout<<"rewrite#############" <<std::endl; // std::cout<<"rewrite#############" <<std::endl;
...@@ -1328,7 +1316,6 @@ DMLQueryExecutor:: ...@@ -1328,7 +1316,6 @@ DMLQueryExecutor::
nextImpl(const ResType &res, const NextParams &nparams) nextImpl(const ResType &res, const NextParams &nparams)
{ {
reenter(this->corot) { reenter(this->corot) {
std::cout<<RED_BEGIN<<"rewritten DML: "<<this->query<<COLOR_END<<std::endl;
yield return CR_QUERY_AGAIN(this->query); yield return CR_QUERY_AGAIN(this->query);
TEST_ErrPkt(res.success(), "DML query failed against remote database"); TEST_ErrPkt(res.success(), "DML query failed against remote database");
yield { yield {
...@@ -1641,7 +1628,6 @@ addShowDirectiveEntry(const std::unique_ptr<Connect> &e_conn, ...@@ -1641,7 +1628,6 @@ addShowDirectiveEntry(const std::unique_ptr<Connect> &e_conn,
" ('" + database + "', '" + table + "'," " ('" + database + "', '" + table + "',"
" '" + field + "', '" + onion + "', '" + level + "')"; " '" + field + "', '" + onion + "', '" + level + "')";
std::cout<<"query: "<<query<<std::endl;
return e_conn->execute(query); return e_conn->execute(query);
} }
...@@ -1721,7 +1707,6 @@ nextImpl(const ResType &res, const NextParams &nparams) ...@@ -1721,7 +1707,6 @@ nextImpl(const ResType &res, const NextParams &nparams)
std::pair<AbstractQueryExecutor::ResultType, AbstractAnything *> std::pair<AbstractQueryExecutor::ResultType, AbstractAnything *>
ShowCreateTableExecutor:: ShowCreateTableExecutor::
nextImpl(const ResType &res, const NextParams &nparams){ nextImpl(const ResType &res, const NextParams &nparams){
std::cout<<"showCreateTableExecutor"<<std::endl;
//return CR_QUERY_AGAIN(nparams.original_query); //return CR_QUERY_AGAIN(nparams.original_query);
reenter(this->corot) { reenter(this->corot) {
yield return CR_QUERY_AGAIN(this->query); yield return CR_QUERY_AGAIN(this->query);
......
...@@ -91,7 +91,6 @@ static bool ...@@ -91,7 +91,6 @@ static bool
sanityCheck(TableMeta &tm) sanityCheck(TableMeta &tm)
{ {
for (const auto &it : tm.getChildren()) { for (const auto &it : tm.getChildren()) {
std::cout<<__PRETTY_FUNCTION__<<":"<<__LINE__<<":"<<__FILE__<<":"<<__LINE__<<std::endl<<std::endl;
const auto &fm = it.second; const auto &fm = it.second;
assert(sanityCheck(*fm.get())); assert(sanityCheck(*fm.get()));
} }
...@@ -122,7 +121,6 @@ static std::map<std::string, int> ...@@ -122,7 +121,6 @@ static std::map<std::string, int>
collectTableNames(const std::string &db_name, collectTableNames(const std::string &db_name,
const std::unique_ptr<Connect> &c) const std::unique_ptr<Connect> &c)
{ {
std::cout<<__PRETTY_FUNCTION__<<":"<<__LINE__<<":"<<__FILE__<<":"<<__LINE__<<std::endl<<std::endl;
std::map<std::string, int> name_map; std::map<std::string, int> name_map;
assert(c->execute("USE " + quoteText(db_name))); assert(c->execute("USE " + quoteText(db_name)));
...@@ -152,7 +150,6 @@ tablesSanityCheck(SchemaInfo &schema, ...@@ -152,7 +150,6 @@ tablesSanityCheck(SchemaInfo &schema,
{ {
for (const auto &dm_it : schema.getChildren()) { for (const auto &dm_it : schema.getChildren()) {
const auto &db_name = dm_it.first.getValue(); const auto &db_name = dm_it.first.getValue();
std::cout<<"db_name: "<<db_name<<std::endl;
const auto &dm = dm_it.second; const auto &dm = dm_it.second;
// gather anonymous tables // gather anonymous tables
std::map<std::string, int> anon_name_map = std::map<std::string, int> anon_name_map =
...@@ -206,14 +203,12 @@ collectRecoveryDetails(const std::unique_ptr<Connect> &conn, ...@@ -206,14 +203,12 @@ collectRecoveryDetails(const std::unique_ptr<Connect> &conn,
unsigned long unfinished_id, unsigned long unfinished_id,
std::unique_ptr<RecoveryDetails> *details) std::unique_ptr<RecoveryDetails> *details)
{ {
std::cout<<__PRETTY_FUNCTION__<<":"<<__LINE__<<":"<<__FILE__<<":"<<__LINE__<<std::endl<<std::endl;
// collect completion data // collect completion data
std::unique_ptr<DBResult> dbres; std::unique_ptr<DBResult> dbres;
const std::string &embedded_completion_q = const std::string &embedded_completion_q =
" SELECT complete, original_query, rewritten_query, default_db FROM " + " SELECT complete, original_query, rewritten_query, default_db FROM " +
MetaData::Table::embeddedQueryCompletion() + MetaData::Table::embeddedQueryCompletion() +
" WHERE id = " + std::to_string(unfinished_id) + ";"; " WHERE id = " + std::to_string(unfinished_id) + ";";
std::cout<<"query: "<<embedded_completion_q<<std::endl;
RETURN_FALSE_IF_FALSE(e_conn->execute(embedded_completion_q, &dbres)); RETURN_FALSE_IF_FALSE(e_conn->execute(embedded_completion_q, &dbres));
assert(mysql_num_rows(dbres->n) == 1); assert(mysql_num_rows(dbres->n) == 1);
...@@ -228,7 +223,6 @@ collectRecoveryDetails(const std::unique_ptr<Connect> &conn, ...@@ -228,7 +223,6 @@ collectRecoveryDetails(const std::unique_ptr<Connect> &conn,
" SELECT COUNT(*) FROM " + MetaData::Table::remoteQueryCompletion() + " SELECT COUNT(*) FROM " + MetaData::Table::remoteQueryCompletion() +
" WHERE embedded_completion_id = " + " WHERE embedded_completion_id = " +
std::to_string(unfinished_id) + ";"; std::to_string(unfinished_id) + ";";
std::cout<<"query: "<<remote_completion_q<<std::endl;
RETURN_FALSE_IF_FALSE(conn->execute(remote_completion_q, &dbres)); RETURN_FALSE_IF_FALSE(conn->execute(remote_completion_q, &dbres));
assert(1 == mysql_num_rows(dbres->n)); assert(1 == mysql_num_rows(dbres->n));
...@@ -258,12 +252,10 @@ static bool ...@@ -258,12 +252,10 @@ static bool
abortQuery(const std::unique_ptr<Connect> &e_conn, abortQuery(const std::unique_ptr<Connect> &e_conn,
unsigned long unfinished_id) unsigned long unfinished_id)
{ {
std::cout<<__PRETTY_FUNCTION__<<":"<<__LINE__<<":"<<__FILE__<<":"<<__LINE__<<std::endl<<std::endl;
const std::string update_aborted = const std::string update_aborted =
" UPDATE " + MetaData::Table::embeddedQueryCompletion() + " UPDATE " + MetaData::Table::embeddedQueryCompletion() +
" SET aborted = TRUE" " SET aborted = TRUE"
" WHERE id = " + std::to_string(unfinished_id) + ";"; " WHERE id = " + std::to_string(unfinished_id) + ";";
std::cout<<"query: "<<update_aborted<<std::endl;
RETURN_FALSE_IF_FALSE(e_conn->execute("START TRANSACTION")); RETURN_FALSE_IF_FALSE(e_conn->execute("START TRANSACTION"));
ROLLBACK_AND_RFIF(setBleedingTableToRegularTable(e_conn), e_conn); ROLLBACK_AND_RFIF(setBleedingTableToRegularTable(e_conn), e_conn);
ROLLBACK_AND_RFIF(e_conn->execute(update_aborted), e_conn); ROLLBACK_AND_RFIF(e_conn->execute(update_aborted), e_conn);
...@@ -276,13 +268,11 @@ static bool ...@@ -276,13 +268,11 @@ static bool
finishQuery(const std::unique_ptr<Connect> &e_conn, finishQuery(const std::unique_ptr<Connect> &e_conn,
unsigned long unfinished_id) unsigned long unfinished_id)
{ {
std::cout<<__PRETTY_FUNCTION__<<":"<<__LINE__<<":"<<__FILE__<<":"<<__LINE__<<std::endl<<std::endl;
const std::string update_completed = const std::string update_completed =
" UPDATE " + MetaData::Table::embeddedQueryCompletion() + " UPDATE " + MetaData::Table::embeddedQueryCompletion() +
" SET complete = TRUE" " SET complete = TRUE"
" WHERE id = " + std::to_string(unfinished_id) + ";"; " WHERE id = " + std::to_string(unfinished_id) + ";";
std::cout<<"query: "<<update_completed<<std::endl;
RETURN_FALSE_IF_FALSE(e_conn->execute("START TRANSACTION")); RETURN_FALSE_IF_FALSE(e_conn->execute("START TRANSACTION"));
ROLLBACK_AND_RFIF(setRegularTableToBleedingTable(e_conn), e_conn); ROLLBACK_AND_RFIF(setRegularTableToBleedingTable(e_conn), e_conn);
ROLLBACK_AND_RFIF(e_conn->execute(update_completed), e_conn); ROLLBACK_AND_RFIF(e_conn->execute(update_completed), e_conn);
...@@ -297,7 +287,6 @@ fixAdjustOnion(const std::unique_ptr<Connect> &conn, ...@@ -297,7 +287,6 @@ fixAdjustOnion(const std::unique_ptr<Connect> &conn,
const std::unique_ptr<Connect> &e_conn, const std::unique_ptr<Connect> &e_conn,
unsigned long unfinished_id) unsigned long unfinished_id)
{ {
std::cout<<__PRETTY_FUNCTION__<<":"<<__LINE__<<":"<<__FILE__<<":"<<__LINE__<<std::endl<<std::endl;
std::unique_ptr<RecoveryDetails> details; std::unique_ptr<RecoveryDetails> details;
RETURN_FALSE_IF_FALSE( RETURN_FALSE_IF_FALSE(
collectRecoveryDetails(conn, e_conn, unfinished_id, &details)); collectRecoveryDetails(conn, e_conn, unfinished_id, &details));
...@@ -375,7 +364,6 @@ enum class QueryStatus {UNKNOWN_ERROR, MALFORMED_QUERY, SUCCESS, ...@@ -375,7 +364,6 @@ enum class QueryStatus {UNKNOWN_ERROR, MALFORMED_QUERY, SUCCESS,
static QueryStatus static QueryStatus
retryQuery(const std::unique_ptr<Connect> &c, const std::string &query) retryQuery(const std::unique_ptr<Connect> &c, const std::string &query)
{ {
std::cout<<__PRETTY_FUNCTION__<<":"<<__LINE__<<":"<<__FILE__<<":"<<__LINE__<<std::endl<<std::endl;
if (true == c->execute(query)) { if (true == c->execute(query)) {
return QueryStatus::SUCCESS; return QueryStatus::SUCCESS;
} }
...@@ -407,7 +395,6 @@ fixDDL(const std::unique_ptr<Connect> &conn, ...@@ -407,7 +395,6 @@ fixDDL(const std::unique_ptr<Connect> &conn,
const std::unique_ptr<Connect> &e_conn, const std::unique_ptr<Connect> &e_conn,
unsigned long unfinished_id) unsigned long unfinished_id)
{ {
std::cout<<__PRETTY_FUNCTION__<<":"<<__LINE__<<":"<<__FILE__<<":"<<__LINE__<<std::endl<<std::endl;
std::unique_ptr<RecoveryDetails> details; std::unique_ptr<RecoveryDetails> details;
RETURN_FALSE_IF_FALSE( RETURN_FALSE_IF_FALSE(
collectRecoveryDetails(conn, e_conn, unfinished_id, &details)); collectRecoveryDetails(conn, e_conn, unfinished_id, &details));
...@@ -506,7 +493,6 @@ deltaSanityCheck(const std::unique_ptr<Connect> &conn, ...@@ -506,7 +493,6 @@ deltaSanityCheck(const std::unique_ptr<Connect> &conn,
" SELECT id, type FROM " + embedded_completion + " SELECT id, type FROM " + embedded_completion +
" WHERE complete = FALSE AND aborted != TRUE;"; " WHERE complete = FALSE AND aborted != TRUE;";
//std::cout<<"query in deltaSanityCheck to find unfinished deltas: "<<unfinished_deltas<<__LINE__<<":"<<__FILE__<<std::endl;
RETURN_FALSE_IF_FALSE(e_conn->execute(unfinished_deltas, &dbres)); RETURN_FALSE_IF_FALSE(e_conn->execute(unfinished_deltas, &dbres));
...@@ -523,7 +509,6 @@ deltaSanityCheck(const std::unique_ptr<Connect> &conn, ...@@ -523,7 +509,6 @@ deltaSanityCheck(const std::unique_ptr<Connect> &conn,
return false; return false;
} }
std::cout<<GREEN_BEGIN<<"We do reach here!!!!!"<<unfinished_count<<__LINE__<<":"<<__FILE__<<std::endl;
const MYSQL_ROW row = mysql_fetch_row(dbres->n); const MYSQL_ROW row = mysql_fetch_row(dbres->n);
const unsigned long *const l = mysql_fetch_lengths(dbres->n); const unsigned long *const l = mysql_fetch_lengths(dbres->n);
...@@ -900,11 +885,9 @@ std::pair<std::vector<std::unique_ptr<Delta> >, ...@@ -900,11 +885,9 @@ std::pair<std::vector<std::unique_ptr<Delta> >,
adjustOnion(const Analysis &a, onion o, const TableMeta &tm, adjustOnion(const Analysis &a, onion o, const TableMeta &tm,
const FieldMeta &fm, SECLEVEL tolevel) const FieldMeta &fm, SECLEVEL tolevel)
{ {
std::cout<<__PRETTY_FUNCTION__<<":"<<__LINE__<<":"<<__FILE__<<":"<<__LINE__<<std::endl<<std::endl;
TEST_Text(tolevel >= a.getOnionMeta(fm, o).getMinimumSecLevel(), TEST_Text(tolevel >= a.getOnionMeta(fm, o).getMinimumSecLevel(),
"your query requires to permissive of a security level"); "your query requires to permissive of a security level");
std::cout << GREEN_BEGIN << "onion: " << TypeText<onion>::toText(o) << COLOR_END << std::endl;
// Make a copy of the onion meta for the purpose of making // Make a copy of the onion meta for the purpose of making
// modifications during removeOnionLayer(...) // modifications during removeOnionLayer(...)
OnionMetaAdjustor om_adjustor(*fm.getOnionMeta(o)); OnionMetaAdjustor om_adjustor(*fm.getOnionMeta(o));
...@@ -1355,8 +1338,6 @@ Rewriter::dispatchOnLex(Analysis &a, const std::string &query) ...@@ -1355,8 +1338,6 @@ Rewriter::dispatchOnLex(Analysis &a, const std::string &query)
executor = handler.transformLex(a, lex); executor = handler.transformLex(a, lex);
} catch (OnionAdjustExcept e) { } catch (OnionAdjustExcept e) {
LOG(cdb_v) << "caught onion adjustment"; LOG(cdb_v) << "caught onion adjustment";
std::cout << GREEN_BEGIN << "Adjusting onion!" << COLOR_END
<< std::endl;
//We use deltas to remove layers in the metadata, and queyrs to decrypt data. //We use deltas to remove layers in the metadata, and queyrs to decrypt data.
std::pair<std::vector<std::unique_ptr<Delta> >, std::pair<std::vector<std::unique_ptr<Delta> >,
...@@ -1411,7 +1392,6 @@ Rewriter::rewrite(const std::string &q, const SchemaInfo &schema, ...@@ -1411,7 +1392,6 @@ Rewriter::rewrite(const std::string &q, const SchemaInfo &schema,
AbstractQueryExecutor *const executor = AbstractQueryExecutor *const executor =
Rewriter::dispatchOnLex(analysis, q); Rewriter::dispatchOnLex(analysis, q);
if (!executor) { if (!executor) {
std::cout<<"we return noopexecutor here"<<__FILE__<<":"<<__LINE__<<std::endl;
return QueryRewrite(true, analysis.rmeta, analysis.kill_zone, return QueryRewrite(true, analysis.rmeta, analysis.kill_zone,
new NoOpExecutor()); new NoOpExecutor());
} }
......
...@@ -34,7 +34,6 @@ rewrite_agg_args(const Item_sum &oldi, const OLK &constr, ...@@ -34,7 +34,6 @@ rewrite_agg_args(const Item_sum &oldi, const OLK &constr,
const RewritePlanOneOLK &rp, Analysis &a, const RewritePlanOneOLK &rp, Analysis &a,
int no_args = -1) int no_args = -1)
{ {
std::cout<<__PRETTY_FUNCTION__<<":"<<__LINE__<<":"<<__FILE__<<"AAAAAAAAAAAAAAAAA"<<std::endl;
if (no_args >= 0) { if (no_args >= 0) {
TEST_BadItemArgumentCount(oldi.type(), no_args, TEST_BadItemArgumentCount(oldi.type(), no_args,
RiboldMYSQL::get_arg_count(oldi)); RiboldMYSQL::get_arg_count(oldi));
...@@ -66,7 +65,6 @@ class CItemCount : public CItemSubtypeST<Item_sum_count, SFT> { ...@@ -66,7 +65,6 @@ class CItemCount : public CItemSubtypeST<Item_sum_count, SFT> {
virtual RewritePlan * virtual RewritePlan *
do_gather_type(const Item_sum_count &i, Analysis &a) const do_gather_type(const Item_sum_count &i, Analysis &a) const
{ {
std::cout<<__PRETTY_FUNCTION__<<":"<<__LINE__<<":"<<__FILE__<<"AAAAAAAAAAAAAAAAA"<<std::endl;
const unsigned int arg_count = const unsigned int arg_count =
RiboldMYSQL::get_arg_count(i); RiboldMYSQL::get_arg_count(i);
TEST_BadItemArgumentCount(i.type(), 1, arg_count); TEST_BadItemArgumentCount(i.type(), 1, arg_count);
...@@ -95,7 +93,6 @@ class CItemCount : public CItemSubtypeST<Item_sum_count, SFT> { ...@@ -95,7 +93,6 @@ class CItemCount : public CItemSubtypeST<Item_sum_count, SFT> {
do_rewrite_type(const Item_sum_count &i, const OLK &constr, do_rewrite_type(const Item_sum_count &i, const OLK &constr,
const RewritePlan &rp, Analysis &a) const const RewritePlan &rp, Analysis &a) const
{ {
std::cout<<__PRETTY_FUNCTION__<<":"<<__LINE__<<":"<<__FILE__<<"AAAAAAAAAAAA"<<std::endl;
std::list<Item *> args = std::list<Item *> args =
rewrite_agg_args(i, constr, rewrite_agg_args(i, constr,
static_cast<const RewritePlanOneOLK &>(rp), static_cast<const RewritePlanOneOLK &>(rp),
...@@ -116,7 +113,6 @@ class CItemChooseOrder : public CItemSubtypeST<Item_sum_hybrid, SFT> { ...@@ -116,7 +113,6 @@ class CItemChooseOrder : public CItemSubtypeST<Item_sum_hybrid, SFT> {
virtual RewritePlan * virtual RewritePlan *
do_gather_type(const Item_sum_hybrid &i, Analysis &a) const do_gather_type(const Item_sum_hybrid &i, Analysis &a) const
{ {
std::cout<<__PRETTY_FUNCTION__<<":"<<__LINE__<<":"<<__FILE__<<"AAAAAAAAAA"<<std::endl;
const unsigned int arg_count = RiboldMYSQL::get_arg_count(i); const unsigned int arg_count = RiboldMYSQL::get_arg_count(i);
TEST_BadItemArgumentCount(i.type(), 1, arg_count); TEST_BadItemArgumentCount(i.type(), 1, arg_count);
const Item *const child = RiboldMYSQL::get_arg(i, 0); const Item *const child = RiboldMYSQL::get_arg(i, 0);
...@@ -138,7 +134,6 @@ class CItemChooseOrder : public CItemSubtypeST<Item_sum_hybrid, SFT> { ...@@ -138,7 +134,6 @@ class CItemChooseOrder : public CItemSubtypeST<Item_sum_hybrid, SFT> {
do_rewrite_type(const Item_sum_hybrid &i, const OLK &constr, do_rewrite_type(const Item_sum_hybrid &i, const OLK &constr,
const RewritePlan &rp, Analysis &a) const const RewritePlan &rp, Analysis &a) const
{ {
std::cout<<__PRETTY_FUNCTION__<<":"<<__LINE__<<":"<<__FILE__<<"AAAAAAAAAA"<<std::endl;
std::list<Item *> args = std::list<Item *> args =
rewrite_agg_args(i, constr, rewrite_agg_args(i, constr,
static_cast<const RewritePlanOneOLK &>(rp), static_cast<const RewritePlanOneOLK &>(rp),
...@@ -155,7 +150,6 @@ class CItemSum : public CItemSubtypeST<Item_sum_sum, SFT> { ...@@ -155,7 +150,6 @@ class CItemSum : public CItemSubtypeST<Item_sum_sum, SFT> {
virtual RewritePlan * virtual RewritePlan *
do_gather_type(const Item_sum_sum &i, Analysis &a) const do_gather_type(const Item_sum_sum &i, Analysis &a) const
{ {
std::cout<<__PRETTY_FUNCTION__<<":"<<__LINE__<<":"<<__FILE__<<"AAAAAAAAA"<<std::endl;
LOG(cdb_v) << "gather Item_sum_sum " << i << std::endl; LOG(cdb_v) << "gather Item_sum_sum " << i << std::endl;
const unsigned int arg_count = RiboldMYSQL::get_arg_count(i); const unsigned int arg_count = RiboldMYSQL::get_arg_count(i);
...@@ -184,7 +178,6 @@ class CItemSum : public CItemSubtypeST<Item_sum_sum, SFT> { ...@@ -184,7 +178,6 @@ class CItemSum : public CItemSubtypeST<Item_sum_sum, SFT> {
do_rewrite_type(const Item_sum_sum &i, const OLK &constr, do_rewrite_type(const Item_sum_sum &i, const OLK &constr,
const RewritePlan &rp, Analysis &a) const const RewritePlan &rp, Analysis &a) const
{ {
std::cout<<__PRETTY_FUNCTION__<<":"<<__LINE__<<":"<<__FILE__<<"AAAAAAAAA"<<std::endl;
auto rp_wc = static_cast<const RewritePlanWithChildren &>(rp); auto rp_wc = static_cast<const RewritePlanWithChildren &>(rp);
assert(rp_wc.childr_rp.size() == 1); assert(rp_wc.childr_rp.size() == 1);
...@@ -230,7 +223,6 @@ static class ANON : public CItemSubtypeST<Item_sum_bit, Item_sum::Sumfunctype::S ...@@ -230,7 +223,6 @@ static class ANON : public CItemSubtypeST<Item_sum_bit, Item_sum::Sumfunctype::S
virtual RewritePlan * virtual RewritePlan *
do_gather_type(const Item_sum_bit &i, Analysis &a) const do_gather_type(const Item_sum_bit &i, Analysis &a) const
{ {
std::cout<<__PRETTY_FUNCTION__<<":"<<__LINE__<<":"<<__FILE__<<"AAAAAAAA"<<std::endl;
/* LOG(cdb_v) << "do_a_t Item_sum_bit reason " << tr; /* LOG(cdb_v) << "do_a_t Item_sum_bit reason " << tr;
analyze(i->get_arg(0), reason(EMPTY_EncSet, "bitagg", i, &tr, false), a); analyze(i->get_arg(0), reason(EMPTY_EncSet, "bitagg", i, &tr, false), a);
return tr.encset; return tr.encset;
...@@ -243,7 +235,6 @@ static class ANON : public CItemSubtypeST<Item_func_group_concat, Item_sum::Sumf ...@@ -243,7 +235,6 @@ static class ANON : public CItemSubtypeST<Item_func_group_concat, Item_sum::Sumf
virtual RewritePlan * virtual RewritePlan *
do_gather_type(const Item_func_group_concat &i, Analysis &a) const do_gather_type(const Item_func_group_concat &i, Analysis &a) const
{ {
std::cout<<__PRETTY_FUNCTION__<<":"<<__LINE__<<":"<<__FILE__<<"AAAAAAAAA"<<std::endl;
/* LOG(cdb_v) << "do_a_t Item_func_group reason " << tr; /* LOG(cdb_v) << "do_a_t Item_func_group reason " << tr;
uint arg_count_field = i->*rob<Item_func_group_concat, uint, uint arg_count_field = i->*rob<Item_func_group_concat, uint,
&Item_func_group_concat::arg_count_field>::ptr(); &Item_func_group_concat::arg_count_field>::ptr();
...@@ -264,7 +255,6 @@ static class ANON : public CItemSubtypeIT<Item_ref, Item::Type::REF_ITEM> { ...@@ -264,7 +255,6 @@ static class ANON : public CItemSubtypeIT<Item_ref, Item::Type::REF_ITEM> {
virtual RewritePlan * virtual RewritePlan *
do_gather_type(const Item_ref &i, Analysis &a) const do_gather_type(const Item_ref &i, Analysis &a) const
{ {
std::cout<<__PRETTY_FUNCTION__<<":"<<__LINE__<<":"<<__FILE__<<"AAAAAAAAA"<<std::endl;
std::vector<std::shared_ptr<RewritePlan> > std::vector<std::shared_ptr<RewritePlan> >
childr_rp({std::shared_ptr<RewritePlan>(gather(**i.ref, a))}); childr_rp({std::shared_ptr<RewritePlan>(gather(**i.ref, a))});
...@@ -281,7 +271,6 @@ static class ANON : public CItemSubtypeIT<Item_ref, Item::Type::REF_ITEM> { ...@@ -281,7 +271,6 @@ static class ANON : public CItemSubtypeIT<Item_ref, Item::Type::REF_ITEM> {
do_rewrite_type(const Item_ref &i, const OLK &constr, do_rewrite_type(const Item_ref &i, const OLK &constr,
const RewritePlan &rp, Analysis &a) const const RewritePlan &rp, Analysis &a) const
{ {
std::cout<<__PRETTY_FUNCTION__<<":"<<__LINE__<<":"<<__FILE__<<"AAAAAAAA"<<std::endl;
const std::string &db_name = a.getDatabaseName(); const std::string &db_name = a.getDatabaseName();
// SUPPORT // SUPPORT
TEST_Text(Item::Type::FIELD_ITEM == (*i.ref)->type(), TEST_Text(Item::Type::FIELD_ITEM == (*i.ref)->type(),
...@@ -305,7 +294,6 @@ static class ANON : public CItemSubtypeIT<Item_null, Item::Type::NULL_ITEM> { ...@@ -305,7 +294,6 @@ static class ANON : public CItemSubtypeIT<Item_null, Item::Type::NULL_ITEM> {
virtual RewritePlan * virtual RewritePlan *
do_gather_type(const Item_null &i, Analysis &a) const do_gather_type(const Item_null &i, Analysis &a) const
{ {
std::cout<<__PRETTY_FUNCTION__<<":"<<__LINE__<<":"<<__FILE__<<"AAAAAAAAA"<<std::endl;
const std::string why = "is null"; const std::string why = "is null";
reason rsn(FULL_EncSet, why, i); reason rsn(FULL_EncSet, why, i);
return new RewritePlan(FULL_EncSet, rsn); return new RewritePlan(FULL_EncSet, rsn);
...@@ -315,7 +303,6 @@ static class ANON : public CItemSubtypeIT<Item_null, Item::Type::NULL_ITEM> { ...@@ -315,7 +303,6 @@ static class ANON : public CItemSubtypeIT<Item_null, Item::Type::NULL_ITEM> {
do_rewrite_type(const Item_null &i, const OLK &constr, do_rewrite_type(const Item_null &i, const OLK &constr,
const RewritePlan &rp, Analysis &a) const const RewritePlan &rp, Analysis &a) const
{ {
std::cout<<__PRETTY_FUNCTION__<<":"<<__LINE__<<":"<<__FILE__<<"AAAAAAAA"<<std::endl;
return RiboldMYSQL::clone_item(i); return RiboldMYSQL::clone_item(i);
} }
...@@ -323,7 +310,6 @@ static class ANON : public CItemSubtypeIT<Item_null, Item::Type::NULL_ITEM> { ...@@ -323,7 +310,6 @@ static class ANON : public CItemSubtypeIT<Item_null, Item::Type::NULL_ITEM> {
do_rewrite_insert_type(const Item_null &i, const FieldMeta &fm, do_rewrite_insert_type(const Item_null &i, const FieldMeta &fm,
Analysis &a, std::vector<Item *> *l) const Analysis &a, std::vector<Item *> *l) const
{ {
std::cout<<__PRETTY_FUNCTION__<<":"<<__LINE__<<":"<<__FILE__<<"AAAAAAAAAA"<<std::endl;
for (uint j = 0; j < fm.getChildren().size(); ++j) { for (uint j = 0; j < fm.getChildren().size(); ++j) {
l->push_back(RiboldMYSQL::clone_item(i)); l->push_back(RiboldMYSQL::clone_item(i));
} }
......
...@@ -34,7 +34,6 @@ rewrite(const Item &i, const EncSet &req_enc, Analysis &a) { ...@@ -34,7 +34,6 @@ rewrite(const Item &i, const EncSet &req_enc, Analysis &a) {
TABLE_LIST * TABLE_LIST *
rewrite_table_list(const TABLE_LIST * const t, const Analysis &a) { rewrite_table_list(const TABLE_LIST * const t, const Analysis &a) {
std::cout<<__PRETTY_FUNCTION__<<":"<<__LINE__<<":"<<__FILE__<<":"<<__LINE__<<std::endl<<std::endl;
// Table name can only be empty when grouping a nested join. // Table name can only be empty when grouping a nested join.
assert(t->table_name || t->nested_join); assert(t->table_name || t->nested_join);
if (t->table_name) { if (t->table_name) {
...@@ -46,7 +45,6 @@ rewrite_table_list(const TABLE_LIST * const t, const Analysis &a) { ...@@ -46,7 +45,6 @@ rewrite_table_list(const TABLE_LIST * const t, const Analysis &a) {
TEST_DatabaseDiscrepancy(t->db, a.getDatabaseName()); TEST_DatabaseDiscrepancy(t->db, a.getDatabaseName());
const std::string anon_name = const std::string anon_name =
a.translateNonAliasPlainToAnonTableName(t->db, plain_name); a.translateNonAliasPlainToAnonTableName(t->db, plain_name);
std::cout<<"table name: "<<plain_name<<"anno: "<<anon_name<<std::endl;
return rewrite_table_list(t, anon_name); return rewrite_table_list(t, anon_name);
} else { } else {
return copyWithTHD(t); return copyWithTHD(t);
...@@ -57,7 +55,6 @@ TABLE_LIST * ...@@ -57,7 +55,6 @@ TABLE_LIST *
rewrite_table_list(const TABLE_LIST * const t, rewrite_table_list(const TABLE_LIST * const t,
const std::string &anon_name) const std::string &anon_name)
{ {
std::cout<<__PRETTY_FUNCTION__<<":"<<__LINE__<<":"<<__FILE__<<":"<<__LINE__<<std::endl<<std::endl;
TABLE_LIST *const new_t = copyWithTHD(t); TABLE_LIST *const new_t = copyWithTHD(t);
new_t->table_name = make_thd_string(anon_name); new_t->table_name = make_thd_string(anon_name);
new_t->table_name_length = anon_name.size(); new_t->table_name_length = anon_name.size();
...@@ -76,7 +73,6 @@ SQL_I_List<TABLE_LIST> ...@@ -76,7 +73,6 @@ SQL_I_List<TABLE_LIST>
rewrite_table_list(const SQL_I_List<TABLE_LIST> &tlist, Analysis &a, rewrite_table_list(const SQL_I_List<TABLE_LIST> &tlist, Analysis &a,
bool if_exists) bool if_exists)
{ {
std::cout<<__PRETTY_FUNCTION__<<":"<<__LINE__<<":"<<__FILE__<<":"<<__LINE__<<std::endl<<std::endl;
if (!tlist.elements) { if (!tlist.elements) {
return SQL_I_List<TABLE_LIST>(); return SQL_I_List<TABLE_LIST>();
} }
...@@ -115,7 +111,6 @@ rewrite_table_list(const SQL_I_List<TABLE_LIST> &tlist, Analysis &a, ...@@ -115,7 +111,6 @@ rewrite_table_list(const SQL_I_List<TABLE_LIST> &tlist, Analysis &a,
List<TABLE_LIST> List<TABLE_LIST>
rewrite_table_list(List<TABLE_LIST> tll, Analysis &a) { rewrite_table_list(List<TABLE_LIST> tll, Analysis &a) {
std::cout<<__PRETTY_FUNCTION__<<":"<<__LINE__<<":"<<__FILE__<<":"<<__LINE__<<std::endl<<std::endl;
List<TABLE_LIST> * const new_tll = new List<TABLE_LIST>(); List<TABLE_LIST> * const new_tll = new List<TABLE_LIST>();
List_iterator<TABLE_LIST> join_it(tll); List_iterator<TABLE_LIST> join_it(tll);
...@@ -253,9 +248,8 @@ rewrite_create_field(const FieldMeta * const fm, ...@@ -253,9 +248,8 @@ rewrite_create_field(const FieldMeta * const fm,
// Restore the default to the original Create_field parameter. // Restore the default to the original Create_field parameter.
f->def = save_def; f->def = save_def;
for(auto item:output_cfields){ //for(auto item:output_cfields){
std::cout<<RED_BEGIN<<item->field_name<<":"<<item->sql_type<<COLOR_END<<std::endl; //}
}
return output_cfields; return output_cfields;
} }
...@@ -663,11 +657,8 @@ void ...@@ -663,11 +657,8 @@ void
encrypt_item_all_onions(const Item &i, const FieldMeta &fm, encrypt_item_all_onions(const Item &i, const FieldMeta &fm,
uint64_t IV, Analysis &a, std::vector<Item*> *l) uint64_t IV, Analysis &a, std::vector<Item*> *l)
{ {
std::cout<<__PRETTY_FUNCTION__<<":"<<__LINE__<<":"<<__FILE__<<":"<<__LINE__<<std::endl<<std::endl;
int numOfOnion = 0;
for (auto it : fm.orderedOnionMetas()) { for (auto it : fm.orderedOnionMetas()) {
numOfOnion++;
std::cout<<"l size: "<<l->size()<<std::endl;
const onion o = it.first->getValue(); const onion o = it.first->getValue();
OnionMeta * const om = it.second; OnionMeta * const om = it.second;
//一个fieldmeta表示一个field, 内部的不同洋葱表现在onionMeta,每个onionMeta的不同层次表现 //一个fieldmeta表示一个field, 内部的不同洋葱表现在onionMeta,每个onionMeta的不同层次表现
...@@ -675,14 +666,12 @@ std::cout<<__PRETTY_FUNCTION__<<":"<<__LINE__<<":"<<__FILE__<<":"<<__LINE__<<std ...@@ -675,14 +666,12 @@ std::cout<<__PRETTY_FUNCTION__<<":"<<__LINE__<<":"<<__FILE__<<":"<<__LINE__<<std
//枚举的洋葱类型. //枚举的洋葱类型.
l->push_back(encrypt_item_layers(i, o, *om, a, IV)); l->push_back(encrypt_item_layers(i, o, *om, a, IV));
} }
std::cout<<"numOfOnions: "<<numOfOnion<<std::endl;
} }
void void
typical_rewrite_insert_type(const Item &i, const FieldMeta &fm, typical_rewrite_insert_type(const Item &i, const FieldMeta &fm,
Analysis &a, std::vector<Item *> *l) { Analysis &a, std::vector<Item *> *l) {
std::cout<<__PRETTY_FUNCTION__<<":"<<__LINE__<<":"<<__FILE__<<":"<<__LINE__<<std::endl<<std::endl;
const uint64_t salt = fm.getHasSalt() ? randomValue() : 0; const uint64_t salt = fm.getHasSalt() ? randomValue() : 0;
......
...@@ -36,7 +36,6 @@ DBMeta::doFetchChildren(const std::unique_ptr<Connect> &e_conn, ...@@ -36,7 +36,6 @@ DBMeta::doFetchChildren(const std::unique_ptr<Connect> &e_conn,
" WHERE " + table_name + ".parent_id" " WHERE " + table_name + ".parent_id"
" = " + parent_id + ";"; " = " + parent_id + ";";
//all the metadata are fetched here. //all the metadata are fetched here.
//std::cout<<serials_query<<"serial query:"<<std::endl;
TEST_TextMessageError(e_conn->execute(serials_query, &db_res), TEST_TextMessageError(e_conn->execute(serials_query, &db_res),
"doFetchChildren query failed"); "doFetchChildren query failed");
MYSQL_ROW row; MYSQL_ROW row;
...@@ -91,7 +90,6 @@ std::unique_ptr<OnionMeta> ...@@ -91,7 +90,6 @@ std::unique_ptr<OnionMeta>
OnionMeta::deserialize(unsigned int id, const std::string &serial) OnionMeta::deserialize(unsigned int id, const std::string &serial)
{ {
assert(id != 0); assert(id != 0);
//std::cout<<"string before unserialize: "<<serial<<std::endl;
const auto vec = unserialize_string(serial); const auto vec = unserialize_string(serial);
//OnionMeta序列化的结果有三个. //OnionMeta序列化的结果有三个.
assert(3 == vec.size()); assert(3 == vec.size());
...@@ -116,7 +114,6 @@ std::string OnionMeta::serialize(const DBObject &parent) const ...@@ -116,7 +114,6 @@ std::string OnionMeta::serialize(const DBObject &parent) const
serialize_string(this->onionname) + serialize_string(this->onionname) +
serialize_string(std::to_string(this->uniq_count)) + serialize_string(std::to_string(this->uniq_count)) +
serialize_string(TypeText<SECLEVEL>::toText(this->minimum_seclevel)); serialize_string(TypeText<SECLEVEL>::toText(this->minimum_seclevel));
std::cout<<"onionmeta serialize: "<<serial<<std::endl;
return serial; return serial;
} }
...@@ -289,12 +286,10 @@ init_onions_layout(const AES_KEY *const m_key, FieldMeta *const fm, ...@@ -289,12 +286,10 @@ init_onions_layout(const AES_KEY *const m_key, FieldMeta *const fm,
const onionlayout onion_layout = fm->getOnionLayout(); const onionlayout onion_layout = fm->getOnionLayout();
if (fm->getHasSalt() != (static_cast<bool>(m_key) if (fm->getHasSalt() != (static_cast<bool>(m_key)
&& PLAIN_ONION_LAYOUT != onion_layout)) { && PLAIN_ONION_LAYOUT != onion_layout)) {
std::cout<<"unable to get salt?"<<std::endl;
return false; return false;
} }
if (0 != fm->getChildren().size()) { if (0 != fm->getChildren().size()) {
std::cout<<"already has children"<<std::endl;
return false; return false;
} }
...@@ -356,7 +351,6 @@ std::string FieldMeta::serialize(const DBObject &parent) const ...@@ -356,7 +351,6 @@ std::string FieldMeta::serialize(const DBObject &parent) const
serialize_string(std::to_string(counter)) + serialize_string(std::to_string(counter)) +
serialize_string(bool_to_string(has_default)) + serialize_string(bool_to_string(has_default)) +
serialize_string(default_value); serialize_string(default_value);
std::cout<<"field serial name: "<<serial<<std::endl<<std::endl;
return serial; return serial;
} }
...@@ -418,7 +412,6 @@ onionlayout FieldMeta::determineOnionLayout(const AES_KEY *const m_key, ...@@ -418,7 +412,6 @@ onionlayout FieldMeta::determineOnionLayout(const AES_KEY *const m_key,
TEST_TextMessageError(m_key, TEST_TextMessageError(m_key,
"Should be using SECURITY_RATING::PLAIN!"); "Should be using SECURITY_RATING::PLAIN!");
if (false == encryptionSupported(f)) { if (false == encryptionSupported(f)) {
std::cout<<"encryption not supported for this field, remain plain"<<std::endl;
//TEST_TextMessageError(SECURITY_RATING::SENSITIVE != sec_rating, //TEST_TextMessageError(SECURITY_RATING::SENSITIVE != sec_rating,
// "A SENSITIVE security rating requires the" // "A SENSITIVE security rating requires the"
// " field to be supported with cryptography!"); // " field to be supported with cryptography!");
...@@ -509,7 +502,6 @@ std::string TableMeta::serialize(const DBObject &parent) const ...@@ -509,7 +502,6 @@ std::string TableMeta::serialize(const DBObject &parent) const
serialize_string(bool_to_string(has_salt)) + serialize_string(bool_to_string(has_salt)) +
serialize_string(salt_name) + serialize_string(salt_name) +
serialize_string(std::to_string(counter)); serialize_string(std::to_string(counter));
std::cout<<"serial tablemeta: "<<serial<<std::endl<<std::endl;
return serial; return serial;
} }
...@@ -609,18 +601,14 @@ SchemaCache::getSchema(const std::unique_ptr<Connect> &conn, ...@@ -609,18 +601,14 @@ SchemaCache::getSchema(const std::unique_ptr<Connect> &conn,
//设置当前id对应的stale的值为true. //设置当前id对应的stale的值为true.
TEST_SchemaFailure(initialStaleness(e_conn)); TEST_SchemaFailure(initialStaleness(e_conn));
this->no_loads = false; this->no_loads = false;
std::cout<<GREEN_BEGIN<<"no_loads = true"<<COLOR_END<<std::endl;
}else{ }else{
std::cout<<GREEN_BEGIN<<"no_loads = false"<<COLOR_END<<std::endl;
} }
//查询当前ID对应的Stale的值 //查询当前ID对应的Stale的值
if (true == lowLevelGetCurrentStaleness(e_conn, this->id)) { if (true == lowLevelGetCurrentStaleness(e_conn, this->id)) {
std::cout<<GREEN_BEGIN<<"stale = true and load"<<COLOR_END<<std::endl;
this->schema = this->schema =
std::shared_ptr<SchemaInfo>(loadSchemaInfo(conn, e_conn)); std::shared_ptr<SchemaInfo>(loadSchemaInfo(conn, e_conn));
}else{ }else{
std::cout<<GREEN_BEGIN<<"stale = false and do not load"<<COLOR_END<<std::endl;
} }
assert(this->schema); assert(this->schema);
...@@ -633,7 +621,6 @@ lowLevelAllStale(const std::unique_ptr<Connect> &e_conn) ...@@ -633,7 +621,6 @@ lowLevelAllStale(const std::unique_ptr<Connect> &e_conn)
const std::string &query = const std::string &query =
" UPDATE " + MetaData::Table::staleness() + " UPDATE " + MetaData::Table::staleness() +
" SET stale = TRUE;"; " SET stale = TRUE;";
std::cout<<"stale query: "<<query<<std::endl;
TEST_SchemaFailure(e_conn->execute(query)); TEST_SchemaFailure(e_conn->execute(query));
} }
...@@ -681,7 +668,6 @@ lowLevelToggleCurrentStaleness(const std::unique_ptr<Connect> &e_conn, ...@@ -681,7 +668,6 @@ lowLevelToggleCurrentStaleness(const std::unique_ptr<Connect> &e_conn,
" UPDATE " + MetaData::Table::staleness() + " UPDATE " + MetaData::Table::staleness() +
" SET stale = " + bool_to_string(staleness) + " SET stale = " + bool_to_string(staleness) +
" WHERE cache_id = " + std::to_string(cache_id) + ";"; " WHERE cache_id = " + std::to_string(cache_id) + ";";
std::cout<<query<<std::endl;
RFIF(e_conn->execute(query)); RFIF(e_conn->execute(query));
return true; return true;
......
...@@ -317,74 +317,11 @@ struct rawReturnValue{ ...@@ -317,74 +317,11 @@ struct rawReturnValue{
std::vector<std::string> fieldNames; std::vector<std::string> fieldNames;
std::vector<int> fieldTypes; std::vector<int> fieldTypes;
}; };
/*
static
void printrawReturnValue(rawReturnValue & cur) {
int len = cur.fieldTypes.size();
if(len==0){
std::cout<<"zero output"<<std::endl;
return ;
}
if(static_cast<int>(cur.fieldNames.size())!=len||static_cast<int>(cur.rowValues[0].size())!=len){
std::cout<<RED_BEGIN<<"size mismatch in printrawReturnValue"<<COLOR_END<<std::endl;
return ;
}
for(int i=0;i<len;i++){
std::cout<<cur.fieldNames[i]<<":"<<cur.fieldTypes[i]<<"\t";
}
std::cout<<std::endl;
for(auto row:cur.rowValues){
for(auto rowItem:row){
std::cout<<rowItem<<"\t";
}
std::cout<<std::endl;
}
}*/
//printResType for testing purposes
/*static
void parseResType(const ResType &rd) {
std::cout<<RED_BEGIN<<"rd.affected_rows: "<<rd.affected_rows<<COLOR_END<<std::endl;
std::cout<<RED_BEGIN<<"rd.insert_id: "<<rd.insert_id<<COLOR_END<<std::endl;
for(auto name:rd.names){
std::cout<<name<<"\t";
}
std::cout<<std::endl;
for(auto row:rd.rows){
for(auto item:row){
std::cout<<ItemToString(*item)<<"\t";
}
std::cout<<std::endl;
}
}
*/
/*
static
void parseResType2(const ResType &rd) {
std::cout<<RED_BEGIN<<"rd.affected_rows: "<<rd.affected_rows<<COLOR_END<<std::endl;
std::cout<<RED_BEGIN<<"rd.insert_id: "<<rd.insert_id<<COLOR_END<<std::endl;
int len = rd.names.size();
for(int i=0;i<len;i++){
std::cout<<rd.names[i]<<std::endl;
for(auto row:rd.rows){
std::cout<<row[i]<<std::endl;
}
}
}
*/
static ResType static ResType
getResTypeFromLuaTable(lua_State *const L, int fields_index, getResTypeFromLuaTable(lua_State *const L, int fields_index,
int rows_index, int affected_rows_index, int rows_index, int affected_rows_index,
int insert_id_index, int status_index) { int insert_id_index, int status_index) {
//std::cout<<"decide to show luaTable to ResType:"<<std::endl;
const bool status = lua_toboolean(L, status_index); const bool status = lua_toboolean(L, status_index);
if (false == status) { if (false == status) {
return ResType(false, 0, 0); return ResType(false, 0, 0);
...@@ -396,20 +333,16 @@ getResTypeFromLuaTable(lua_State *const L, int fields_index, ...@@ -396,20 +333,16 @@ getResTypeFromLuaTable(lua_State *const L, int fields_index,
std::vector<enum_field_types> types; std::vector<enum_field_types> types;
/* iterate over the fields argument */ /* iterate over the fields argument */
lua_pushnil(L); lua_pushnil(L);
//std::cout<<"start to get fields"<<std::endl;
while (lua_next(L, fields_index)) { while (lua_next(L, fields_index)) {
std::cout<<"1"<<std::endl;
if (!lua_istable(L, -1)) if (!lua_istable(L, -1))
LOG(warn) << "mismatch"; LOG(warn) << "mismatch";
lua_pushnil(L); lua_pushnil(L);
while (lua_next(L, -2)) { while (lua_next(L, -2)) {
const std::string k = xlua_tolstring(L, -2); const std::string k = xlua_tolstring(L, -2);
if ("name" == k) { if ("name" == k) {
std::cout<<"field name"<<std::endl;
names.push_back(xlua_tolstring(L, -1)); names.push_back(xlua_tolstring(L, -1));
myRawFromLua.fieldNames.push_back(xlua_tolstring(L, -1)); myRawFromLua.fieldNames.push_back(xlua_tolstring(L, -1));
} else if ("type" == k) { } else if ("type" == k) {
std::cout<<"field type"<<std::endl;
types.push_back(static_cast<enum_field_types>(luaL_checkint(L, -1))); types.push_back(static_cast<enum_field_types>(luaL_checkint(L, -1)));
myRawFromLua.fieldTypes.push_back(static_cast<enum_field_types>(luaL_checkint(L, -1)) ); myRawFromLua.fieldTypes.push_back(static_cast<enum_field_types>(luaL_checkint(L, -1)) );
} else { } else {
...@@ -441,7 +374,6 @@ getResTypeFromLuaTable(lua_State *const L, int fields_index, ...@@ -441,7 +374,6 @@ getResTypeFromLuaTable(lua_State *const L, int fields_index,
assert(key >= 0 && static_cast<uint>(key) < types.size()); assert(key >= 0 && static_cast<uint>(key) < types.size());
const std::string data = xlua_tolstring(L, -1); const std::string data = xlua_tolstring(L, -1);
curRow.push_back(data); curRow.push_back(data);
// std::cout<<"transform to typed data"<<std::endl;
row[key] = MySQLFieldTypeToItem(types[key], data); row[key] = MySQLFieldTypeToItem(types[key], data);
lua_pop(L, 1); lua_pop(L, 1);
} }
...@@ -450,7 +382,6 @@ getResTypeFromLuaTable(lua_State *const L, int fields_index, ...@@ -450,7 +382,6 @@ getResTypeFromLuaTable(lua_State *const L, int fields_index,
lua_pop(L, 1); lua_pop(L, 1);
} }
std::cout<<RED_BEGIN<<"ADD TRANSFORM TEST"<<COLOR_END<<std::endl;
//printrawReturnValue(myRawFromLua); //printrawReturnValue(myRawFromLua);
return ResType(status, lua_tointeger(L, affected_rows_index), return ResType(status, lua_tointeger(L, affected_rows_index),
...@@ -468,20 +399,16 @@ nilBuffer(lua_State *const L, size_t count) ...@@ -468,20 +399,16 @@ nilBuffer(lua_State *const L, size_t count)
return; return;
} }
/* /*
*return mete for dectypting data. *return mete for dectypting data.
* */ * */
static void static void
parseReturnMeta(const ReturnMeta & rtm){ parseReturnMeta(const ReturnMeta & rtm){
std::cout<<RED_BEGIN<<"parseReturnMeta!!!"<<COLOR_END<<std::endl;
} }
static int static int
next(lua_State *const L) { next(lua_State *const L) {
// ANON_REGION(__func__, &perf_cg);
scoped_lock l(&big_lock); scoped_lock l(&big_lock);
assert(0 == mysql_thread_init()); assert(0 == mysql_thread_init());
//查找client //查找client
...@@ -526,7 +453,6 @@ next(lua_State *const L) { ...@@ -526,7 +453,6 @@ next(lua_State *const L) {
case AbstractQueryExecutor::ResultType::QUERY_COME_AGAIN: { case AbstractQueryExecutor::ResultType::QUERY_COME_AGAIN: {
// more to do before we have the client's results // more to do before we have the client's results
xlua_pushlstring(L, "again"); xlua_pushlstring(L, "again");
std::cout<<"QUERY_COME_AGAIN:11111111111111111111111"<<std::endl<<std::endl;
const auto &output = const auto &output =
std::get<1>(new_results)->extract<std::pair<bool, std::string> >(); std::get<1>(new_results)->extract<std::pair<bool, std::string> >();
const auto &want_interim = output.first; const auto &want_interim = output.first;
...@@ -540,7 +466,6 @@ next(lua_State *const L) { ...@@ -540,7 +466,6 @@ next(lua_State *const L) {
// the results of executing this query should be send directly // the results of executing this query should be send directly
// back to the client // back to the client
xlua_pushlstring(L, "query-results"); xlua_pushlstring(L, "query-results");
std::cout<<"QUERY_USE_RESULTS:22222222222222222222222222"<<std::endl<<std::endl;
const auto &new_query = const auto &new_query =
std::get<1>(new_results)->extract<std::string>(); std::get<1>(new_results)->extract<std::string>();
xlua_pushlstring(L, new_query); xlua_pushlstring(L, new_query);
...@@ -550,7 +475,6 @@ next(lua_State *const L) { ...@@ -550,7 +475,6 @@ next(lua_State *const L) {
case AbstractQueryExecutor::ResultType::RESULTS: { case AbstractQueryExecutor::ResultType::RESULTS: {
// ready to return results to the client // ready to return results to the client
xlua_pushlstring(L, "results"); xlua_pushlstring(L, "results");
std::cout<<"RESULTS:33333333333333333333333333333333333333"<<std::endl<<std::endl;
const auto &res = new_results.second->extract<ResType>(); const auto &res = new_results.second->extract<ResType>();
returnResultSet(L, res); // pushes 4 items on stack returnResultSet(L, res); // pushes 4 items on stack
return 5; return 5;
......
cd ../..
find . | grep '\.cc$\|\.c$\|\.h$\|\.hh$' | xargs ctags
rm cscope*
find . | grep '\.cc$\|\.c$\|\.h$\|\.hh$' > cscope.files
cscope -R -b -i cscope.files
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment