MCPcopy Create free account
hub / github.com/bloomberg/comdb2 / insert

Function insert

tests/tools/insert.c:92–315  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

90enum { OK = 1, FAILED = 2, CHECKED = 3, RECOVERED = 4, LOST = 5, UNKNOWN = 6 };
91
92int insert(cdb2_hndl_tp **indb, const char *readnode)
93{
94 static pthread_mutex_t lk = PTHREAD_MUTEX_INITIALIZER;
95 int i, val;
96 cdb2_hndl_tp *db = (*indb);
97 char cnonce_begin[100];
98 int rc;
99 char sql[100];
100
101 pthread_mutex_lock(&lk);
102 i = id;
103 val = value;
104
105 id += inserts_per_txn;
106 value += inserts_per_txn;
107
108 if (value > largest) largest = value;
109 if (value >= allocated) {
110 fprintf(stderr, "Exceeded allocated amount: exiting\n");
111 myexit(__func__, __LINE__, 1);
112 }
113 pthread_mutex_unlock(&lk);
114
115 /* turning this off you can use this test to detect the error where we
116 * return
117 * IX_DUP rather than "SERIALIZABLE_ERROR" */
118 if (is_hasql) {
119 rc = cdb2_run_statement(db, "set hasql on");
120 if (rc) {
121 fprintf(stderr, "set 2: %d run rc %d %s\n", val, rc,
122 cdb2_errstr(db));
123 for (int jj = 0; jj < inserts_per_txn; jj++)
124 state[val + jj] = FAILED;
125 if (exit_at_failure) myexit(__func__, __LINE__, 1);
126 return rc;
127 }
128 }
129
130 rc = cdb2_run_statement(db, "set transaction serializable");
131 if (rc) {
132 fprintf(stderr, "set 1: %d run rc %d %s\n", val, rc, cdb2_errstr(db));
133 for (int jj = 0; jj < inserts_per_txn; jj++)
134 state[val + jj] = FAILED;
135 if (exit_at_failure) myexit(__func__, __LINE__, 1);
136 return rc;
137 }
138
139 rc = cdb2_run_statement(db, "begin");
140
141 if (rc) {
142 tdprintf(stderr, db, __func__, __LINE__,
143 "begin: %d run rc %d %s read node %s\n", val, rc,
144 cdb2_errstr(db), readnode);
145 for (int jj = 0; jj < inserts_per_txn; jj++)
146 state[val + jj] = FAILED;
147
148 if (exit_at_failure) myexit(__func__, __LINE__, 1);
149 return rc;

Callers 1

thdFunction · 0.85

Calls 8

myexitFunction · 0.85
cdb2_run_statementFunction · 0.85
cdb2_errstrFunction · 0.85
tdprintfFunction · 0.85
cdb2_cnonceFunction · 0.85
cdb2_next_recordFunction · 0.85
cdb2_column_valueFunction · 0.85
exitFunction · 0.85

Tested by

no test coverage detected