-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDBClient.cpp
More file actions
228 lines (194 loc) · 4.85 KB
/
DBClient.cpp
File metadata and controls
228 lines (194 loc) · 4.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
#include <iostream>
#include <cstring>
#include <thread>
#include <vector>
#include "headers/DBClient.h"
using namespace std;
/**
* This method creates a value with a size of 6K bytes
*
* @return a pointer to a char array with a size of 6K bytes
*/
char* DBClient::getEntryVal(char recordChar, int record_size)
{
char* val = new char[record_size];
strncpy(val, "", 1);
for (int i = 0; i < record_size; i++)
{
const char* str_letter = &recordChar;
strncat(val, str_letter, 1);
}
return val;
}
/**
* This method calculates the elapsed time based on the given start and end time values
*
* @param start - the starting timestamp
* @param end - the ending timestamp
*
* @return a double value of the elapsed time
*/
double DBClient::calculateTime(chrono::time_point<std::chrono::high_resolution_clock> start, chrono::time_point<std::chrono::high_resolution_clock> end)
{
auto elapsed = chrono::duration_cast<chrono::microseconds>(end - start);
double time = elapsed.count() * 1e-6;
return time;
}
/**
* This method generates n random numbers within the lower to upper range
* and none of those random numbers are repeated
*
* @param n - the number of random numbers to generate
* @param min - the minimum number that the random number can be
* @param max - the maximum number that the random number can be
*
* @return - returns a set of n random numbers
*/
vector<int> DBClient::getRandomKeys(int n, int lower, int upper)
{
srand(time(0));
vector<int> keySet;
//int count = 0;
for (int i = 0; i < n; i++)
{
int randomNum = (rand() % (upper + 1 - lower)) + lower;
keySet.push_back(randomNum);
}
return keySet;
}
/**
* sets the threads
*
* @param n - the number to set for threads
*/
void DBClient::setThreads(int n)
{
threads = n;
}
/**
* sets the entries
*
* @param n - the number to set for entries
*/
void DBClient::setEntries(int n)
{
entries = n;
}
/**
* returns the threads
*
* @return the value set for threads
*/
int DBClient::getThreads()
{
return threads;
}
/**
* returns the entries
*
* @return the value set for entries
*/
int DBClient::getEntries()
{
return entries;
}
/**
* makes a connection to the DB
*
*/
void DBClient::connect()
{
cout << "Method is ran from the DBClient...." << endl;
exit(1);
}
/**
* Initializes the DB by inserting 1 million entries with each having a data
* of 6K bytes and a key of 64 bits
*
* @return the double value of the time it took to initialize the DB
**/
double DBClient::initializeDB()
{
cout << "Method is ran from the DBClient...." << endl;
return -1;
}
/**
* Does a simple read on an entry in the DB
*
* @param key - the key of the entry to be read
*
* @return the double value of the time it took to complete a read
**/
double DBClient::readEntry(bool randomOption)
{
cout << "Method is ran from the DBClient...." << endl;
return -1;
}
/**
* Does an insertion of an entry into the DB
*
* @param key - the key of the entry to be inserted into the DB
*
* @return the double value of the time it took to complete the insertion
**/
double DBClient::insertEntry(int key)
{
cout << "Method is ran from the DBClient...." << endl;
return -1;
}
/**
* Makes an update on an existing entry in the DB
*
* @param key - the key of the entry to update
* @param newVal - the value to update the provided key
*
* @return a double value of the time it took to complete an update
**/
double DBClient::updateEntry(int key, bool randomOption)
{
cout << "Method is ran from the DBClient...." << endl;
return -1;
}
/**
* Deletes an entry within the DB
*
* @param key - the key of the entry to be deleted
*
* @return a double value of the time it took to complete a deletion
**/
double DBClient::deleteEntry(int key, bool randomOption)
{
cout << "Method is ran from the DBClient...." << endl;
return -1;
}
/**
* Simulates having multiple of tasks happening at the same time.
* The tasks done are either reading or doing an update on an entry.
* The reading/modifying is split 50:50 and is based on the number
* of simultaneous tasks going on.
*
* @param n - the number of simultaneous tasks
*
* @return a double value of the time it took for all the
* simultaneous tasks to finish
**/
double DBClient::simultaneousTasks(bool randomOption)
{
cout << "Method is ran from the DBClient...." << endl;
return -1;
}
/**
* Simulates having multiple of transactions happening at the same time.
* A transactin consists of performing an insert and then a delete.
*
* @param n - the number of simultaneous threads
* @double p - the success percentage
*
* @return a double value of the time it took for all the
* simultaneous transactions going on
*/
double DBClient::performTransactions(int key)
{
cout << "Method is ran from the DBClient...." << endl;
return -1;
}