23 #include <ndb_global.h>
25 #include "userInterface.h"
27 #include "dbPopulate.h"
43 static void getRandomSubscriberData(
int subscriberNo,
44 SubscriberNumber number,
47 static void populate(
const char *title,
52 static void populateServers(
UserHandle *uh,
int count);
53 static void populateSubscribers(
UserHandle *uh,
int count);
54 static void populateGroups(
UserHandle *uh,
int count);
77 static void getRandomSubscriberData(
int subscriberNo,
78 SubscriberNumber number,
81 char sbuf[SUBSCRIBER_NUMBER_LENGTH + 1];
82 sprintf(sbuf,
"%.*d", SUBSCRIBER_NUMBER_LENGTH, subscriberNo);
83 memcpy(number, sbuf, SUBSCRIBER_NUMBER_LENGTH);
85 memset(name, myRandom48(26)+
'A', SUBSCRIBER_NAME_LENGTH);
88 static void populate(
const char *title,
93 ndbout_c(
"Populating %d '%s' ... ",count, title);
99 static void populateServers(
UserHandle *uh,
int count)
104 int suffix_length = 1;
105 ServerName serverName;
106 SubscriberSuffix suffix;
110 for(i = 0; i < SUBSCRIBER_NUMBER_SUFFIX_LENGTH; i++)
113 for(i = 0; i < count; i++) {
114 sprintf(tmp,
"-Server %d-", i);
117 for(j = 0; j < SERVER_NAME_LENGTH; j++){
118 serverName[j] = tmp[j % len];
122 for(j = 0; j < suffix_length; j++){
123 char sbuf[SUBSCRIBER_NUMBER_SUFFIX_LENGTH + 1];
124 sprintf(sbuf,
"%.*d", SUBSCRIBER_NUMBER_SUFFIX_LENGTH, j);
125 memcpy(suffix, sbuf, SUBSCRIBER_NUMBER_SUFFIX_LENGTH);
126 userDbInsertServer(uh, i, suffix, serverName);
128 if((commitCount % OP_PER_TRANS) == 0)
132 if((commitCount % OP_PER_TRANS) != 0)
136 static void populateSubscribers(
UserHandle *uh,
int count)
138 SubscriberNumber number;
146 for(i = 0; i < NO_OF_GROUPS; i++) {
147 values[
i].length = 1;
151 values[
i].length = 0;
154 if( initSequence(&seq, values) != 0 ) {
155 ndbout_c(
"could not set the sequence of random groups");
161 for(i = 0; i < count; i+= OP_PER_TRANS) {
162 for(j = 0; j<RETRIES; j++){
163 for(k = 0; k<OP_PER_TRANS && i+k < count; k++){
164 getRandomSubscriberData(i+k, number, name);
165 userDbInsertSubscriber(uh, number, getNextRandom(&seq), name);
167 res = userDbCommit(uh);
171 ndbout_c(
"Terminating");
176 ndbout_c(
"Terminating");
182 static void populateGroups(
UserHandle *uh,
int count)
188 Permission allow[NO_OF_GROUPS];
194 if( initSequence(&seq, permissionsDefinition) != 0 ) {
195 ndbout_c(
"could not set the sequence of random permissions");
199 for(i = 0; i < NO_OF_GROUPS; i++)
202 for(i = 0; i < NO_OF_SERVERS; i++) {
205 for(j = 0; j < NO_OF_GROUPS; j++ ) {
206 if( getNextRandom(&seq) )
207 allow[j] |= serverBit;
211 for(i = 0; i < NO_OF_GROUPS; i++) {
212 sprintf(tmp,
"-Group %d-", i);
216 for(j = 0; j < GROUP_NAME_LENGTH; j++) {
217 groupName[j] = tmp[j % len];
221 userDbInsertGroup(uh,
228 if((commitCount % OP_PER_TRANS) == 0)
231 if((commitCount % OP_PER_TRANS) != 0)
243 populate(
"servers", NO_OF_SERVERS, populateServers, uh);
244 populate(
"subscribers", NO_OF_SUBSCRIBERS, populateSubscribers, uh);
245 populate(
"groups", NO_OF_GROUPS, populateGroups, uh);