129
164
repo_size = myWriteRepo->getRepoFileSize();
130
165
temp_time = myWriteRepo->myLastTempTime;
133
head_size = myWriteRepo->getDefaultHeaderSize(metadata_size);
134
if (getDB()->myBlobType == MS_STANDARD_STORAGE) {
167
// If an exception occurs the cleanup operation will be called.
168
cleanup->setCleanUp(this, myWriteRepo, repo_size);
170
head_size = myWriteRepo->getDefaultHeaderSize(metadata_size);
171
if (getDB()->myBlobType == MS_STANDARD_STORAGE) {
173
repo_offset = myWriteRepo->receiveBlob(this, head_size, blob_size, checksum, stream);
175
ASSERT(getDB()->myBlobType == MS_CLOUD_STORAGE);
176
CloudDB *cloud = getDB()->myBlobCloud;
179
CSException::throwException(CS_CONTEXT, CS_ERR_GENERIC_ERROR, "Creating cloud BLOB without cloud.");
181
repo_offset = repo_size + head_size;
182
memset(checksum, 0, sizeof(Md5Digest)); // The checksum is only for local storage.
184
// If there is a stream then the data has not been sent to the cloud yet.
186
cloud_key = &cloud_key_rec;
187
cloud->cl_getNewKey(cloud_key);
136
repo_offset = myWriteRepo->receiveBlob(this, head_size, blob_size, checksum, stream);
138
ASSERT(getDB()->myBlobType == MS_CLOUD_STORAGE);
139
CloudDB *cloud = getDB()->myBlobCloud;
142
CSException::throwException(CS_CONTEXT, CS_ERR_GENERIC_ERROR, "Creating cloud BLOB without cloud.");
144
repo_offset = repo_size + head_size;
145
memset(checksum, 0, sizeof(Md5Digest)); // The checksum is only for local storage.
147
// If there is a stream then the data has not been sent to the cloud yet.
149
cloud_key = &cloud_key_rec;
150
cloud->cl_getNewKey(cloud_key);
152
cloud->cl_putData(cloud_key, stream, blob_size);
157
repo_id = myWriteRepo->myRepoID;
159
getDB()->queueForDeletion(this, MS_TL_REPO_REF, repo_id, repo_offset, auth_code, &log_id, &log_offset, &temp_time);
160
formatRepoURL(bh, repo_id, repo_offset, auth_code, blob_size);
163
blob_id = getDBTable()->createBlobHandle(this, myWriteRepo->myRepoID, repo_offset, blob_size, head_size, auth_code);
164
getDB()->queueForDeletion(this, MS_TL_BLOB_REF, getDBTable()->myTableID, blob_id, auth_code, &log_id, &log_offset, &temp_time);
165
formatBlobURL(bh, blob_id, auth_code, blob_size, 0);
168
myWriteRepo->writeBlobHead(this, repo_offset, myWriteRepo->myRepoDefRefSize, head_size, blob_size, checksum, metadata, metadata_size, blob_id, auth_code, log_id, log_offset, getDB()->myBlobType, cloud_key);
172
// In the event of an error reset the repository size to its original size.
173
myWriteRepo->setRepoFileSize(this, repo_size);
189
cloud->cl_putData(cloud_key, stream, blob_size);
194
repo_id = myWriteRepo->myRepoID;
196
getDB()->queueForDeletion(this, MS_TL_REPO_REF, repo_id, repo_offset, auth_code, &log_id, &log_offset, &temp_time);
197
formatRepoURL(bh, repo_id, repo_offset, auth_code, blob_size);
200
blob_id = getDBTable()->createBlobHandle(this, myWriteRepo->myRepoID, repo_offset, blob_size, head_size, auth_code);
201
getDB()->queueForDeletion(this, MS_TL_BLOB_REF, getDBTable()->myTableID, blob_id, auth_code, &log_id, &log_offset, &temp_time);
202
formatBlobURL(bh, blob_id, auth_code, blob_size, 0);
205
myWriteRepo->writeBlobHead(this, repo_offset, myWriteRepo->myRepoDefRefSize, head_size, blob_size, checksum, metadata, metadata_size, blob_id, auth_code, log_id, log_offset, getDB()->myBlobType, cloud_key);
207
cleanup->cancelCleanUp();
189
222
uint32_t log_offset;
190
223
uint32_t temp_time;
224
CreateBlobCleanUp *cleanup;
227
new_(cleanup, CreateBlobCleanUp());
193
230
openForWriting();
194
231
ASSERT(myWriteRepo);
195
232
auth_code = random();
197
234
repo_size = myWriteRepo->getRepoFileSize();
199
head_size = myWriteRepo->getDefaultHeaderSize(metadata_size);
201
repo_offset = myWriteRepo->receiveBlob(this, head_size, blob_size);
202
repo_id = myWriteRepo->myRepoID;
203
temp_time = myWriteRepo->myLastTempTime;
204
getDB()->queueForDeletion(this, MS_TL_REPO_REF, repo_id, repo_offset, auth_code, &log_id, &log_offset, &temp_time);
205
myWriteRepo->myLastTempTime = temp_time;
206
myWriteRepo->writeBlobHead(this, repo_offset, myWriteRepo->myRepoDefRefSize, head_size, blob_size, NULL, metadata, metadata_size, 0, auth_code, log_id, log_offset, MS_STANDARD_STORAGE, NULL);
207
// myWriteRepo->setRepoFileSize(this, repo_offset + head_size + blob_size);This is now set by writeBlobHead()
209
blob_id->bi_db_id = getDB()->myDatabaseID;
210
blob_id->bi_blob_id = repo_offset;
211
blob_id->bi_tab_id = repo_id;
212
blob_id->bi_auth_code = auth_code;
213
blob_id->bi_blob_size = blob_size;
214
blob_id->bi_blob_type = MS_URL_TYPE_REPO;
215
blob_id->bi_blob_ref_id = 0;
220
// BLOBs created with this method are always created as standard local BLOBs. (No cloud storage)
221
myWriteRepo->setRepoFileSize(this, repo_size);
236
// If an exception occurs the cleanup operation will be called.
237
cleanup->setCleanUp(this, myWriteRepo, repo_size);
239
head_size = myWriteRepo->getDefaultHeaderSize(metadata_size);
241
repo_offset = myWriteRepo->receiveBlob(this, head_size, blob_size);
242
repo_id = myWriteRepo->myRepoID;
243
temp_time = myWriteRepo->myLastTempTime;
244
getDB()->queueForDeletion(this, MS_TL_REPO_REF, repo_id, repo_offset, auth_code, &log_id, &log_offset, &temp_time);
245
myWriteRepo->myLastTempTime = temp_time;
246
myWriteRepo->writeBlobHead(this, repo_offset, myWriteRepo->myRepoDefRefSize, head_size, blob_size, NULL, metadata, metadata_size, 0, auth_code, log_id, log_offset, MS_STANDARD_STORAGE, NULL);
247
// myWriteRepo->setRepoFileSize(this, repo_offset + head_size + blob_size);This is now set by writeBlobHead()
249
blob_id->bi_db_id = getDB()->myDatabaseID;
250
blob_id->bi_blob_id = repo_offset;
251
blob_id->bi_tab_id = repo_id;
252
blob_id->bi_auth_code = auth_code;
253
blob_id->bi_blob_size = blob_size;
254
blob_id->bi_blob_type = MS_URL_TYPE_REPO;
255
blob_id->bi_blob_ref_id = 0;
257
cleanup->cancelCleanUp();