00001
00002
00003 #include "db_config.h"
00004
00005 #ifndef NO_SYSTEM_INCLUDES
00006 #include <sys/types.h>
00007
00008 #include <ctype.h>
00009 #include <string.h>
00010 #endif
00011
00012 #include "db_int.h"
00013 #include "dbinc/crypto.h"
00014 #include "dbinc/db_page.h"
00015 #include "dbinc/db_dispatch.h"
00016 #include "dbinc/db_am.h"
00017 #include "dbinc/hash.h"
00018 #include "dbinc/log.h"
00019 #include "dbinc/txn.h"
00020
00021
00022
00023
00024
00025
00026 int
00027 __ham_insdel_log(dbp, txnid, ret_lsnp, flags,
00028 opcode, pgno, ndx, pagelsn, key,
00029 data)
00030 DB *dbp;
00031 DB_TXN *txnid;
00032 DB_LSN *ret_lsnp;
00033 u_int32_t flags;
00034 u_int32_t opcode;
00035 db_pgno_t pgno;
00036 u_int32_t ndx;
00037 DB_LSN * pagelsn;
00038 const DBT *key;
00039 const DBT *data;
00040 {
00041 DBT logrec;
00042 DB_ENV *dbenv;
00043 DB_TXNLOGREC *lr;
00044 DB_LSN *lsnp, null_lsn, *rlsnp;
00045 u_int32_t zero, uinttmp, rectype, txn_num;
00046 u_int npad;
00047 u_int8_t *bp;
00048 int is_durable, ret;
00049
00050 dbenv = dbp->dbenv;
00051 COMPQUIET(lr, NULL);
00052
00053 rectype = DB___ham_insdel;
00054 npad = 0;
00055 rlsnp = ret_lsnp;
00056
00057 ret = 0;
00058
00059 if (LF_ISSET(DB_LOG_NOT_DURABLE) ||
00060 F_ISSET(dbp, DB_AM_NOT_DURABLE)) {
00061 is_durable = 0;
00062 } else
00063 is_durable = 1;
00064
00065 if (txnid == NULL) {
00066 txn_num = 0;
00067 lsnp = &null_lsn;
00068 null_lsn.file = null_lsn.offset = 0;
00069 } else {
00070 if (TAILQ_FIRST(&txnid->kids) != NULL &&
00071 (ret = __txn_activekids(dbenv, rectype, txnid)) != 0)
00072 return (ret);
00073
00074
00075
00076
00077
00078
00079 DB_SET_TXN_LSNP(txnid, &rlsnp, &lsnp);
00080 txn_num = txnid->txnid;
00081 }
00082
00083 DB_ASSERT(dbp->log_filename != NULL);
00084 if (dbp->log_filename->id == DB_LOGFILEID_INVALID &&
00085 (ret = __dbreg_lazy_id(dbp)) != 0)
00086 return (ret);
00087
00088 logrec.size = sizeof(rectype) + sizeof(txn_num) + sizeof(DB_LSN)
00089 + sizeof(u_int32_t)
00090 + sizeof(u_int32_t)
00091 + sizeof(u_int32_t)
00092 + sizeof(u_int32_t)
00093 + sizeof(*pagelsn)
00094 + sizeof(u_int32_t) + (key == NULL ? 0 : key->size)
00095 + sizeof(u_int32_t) + (data == NULL ? 0 : data->size);
00096 if (CRYPTO_ON(dbenv)) {
00097 npad =
00098 ((DB_CIPHER *)dbenv->crypto_handle)->adj_size(logrec.size);
00099 logrec.size += npad;
00100 }
00101
00102 if (is_durable || txnid == NULL) {
00103 if ((ret =
00104 __os_malloc(dbenv, logrec.size, &logrec.data)) != 0)
00105 return (ret);
00106 } else {
00107 if ((ret = __os_malloc(dbenv,
00108 logrec.size + sizeof(DB_TXNLOGREC), &lr)) != 0)
00109 return (ret);
00110 #ifdef DIAGNOSTIC
00111 if ((ret =
00112 __os_malloc(dbenv, logrec.size, &logrec.data)) != 0) {
00113 __os_free(dbenv, lr);
00114 return (ret);
00115 }
00116 #else
00117 logrec.data = lr->data;
00118 #endif
00119 }
00120 if (npad > 0)
00121 memset((u_int8_t *)logrec.data + logrec.size - npad, 0, npad);
00122
00123 bp = logrec.data;
00124
00125 memcpy(bp, &rectype, sizeof(rectype));
00126 bp += sizeof(rectype);
00127
00128 memcpy(bp, &txn_num, sizeof(txn_num));
00129 bp += sizeof(txn_num);
00130
00131 memcpy(bp, lsnp, sizeof(DB_LSN));
00132 bp += sizeof(DB_LSN);
00133
00134 uinttmp = (u_int32_t)opcode;
00135 memcpy(bp, &uinttmp, sizeof(uinttmp));
00136 bp += sizeof(uinttmp);
00137
00138 uinttmp = (u_int32_t)dbp->log_filename->id;
00139 memcpy(bp, &uinttmp, sizeof(uinttmp));
00140 bp += sizeof(uinttmp);
00141
00142 uinttmp = (u_int32_t)pgno;
00143 memcpy(bp, &uinttmp, sizeof(uinttmp));
00144 bp += sizeof(uinttmp);
00145
00146 uinttmp = (u_int32_t)ndx;
00147 memcpy(bp, &uinttmp, sizeof(uinttmp));
00148 bp += sizeof(uinttmp);
00149
00150 if (pagelsn != NULL)
00151 memcpy(bp, pagelsn, sizeof(*pagelsn));
00152 else
00153 memset(bp, 0, sizeof(*pagelsn));
00154 bp += sizeof(*pagelsn);
00155
00156 if (key == NULL) {
00157 zero = 0;
00158 memcpy(bp, &zero, sizeof(u_int32_t));
00159 bp += sizeof(u_int32_t);
00160 } else {
00161 memcpy(bp, &key->size, sizeof(key->size));
00162 bp += sizeof(key->size);
00163 memcpy(bp, key->data, key->size);
00164 bp += key->size;
00165 }
00166
00167 if (data == NULL) {
00168 zero = 0;
00169 memcpy(bp, &zero, sizeof(u_int32_t));
00170 bp += sizeof(u_int32_t);
00171 } else {
00172 memcpy(bp, &data->size, sizeof(data->size));
00173 bp += sizeof(data->size);
00174 memcpy(bp, data->data, data->size);
00175 bp += data->size;
00176 }
00177
00178 DB_ASSERT((u_int32_t)(bp - (u_int8_t *)logrec.data) <= logrec.size);
00179
00180 if (is_durable || txnid == NULL) {
00181 if ((ret = __log_put(dbenv, rlsnp,(DBT *)&logrec,
00182 flags | DB_LOG_NOCOPY)) == 0 && txnid != NULL) {
00183 *lsnp = *rlsnp;
00184 if (rlsnp != ret_lsnp)
00185 *ret_lsnp = *rlsnp;
00186 }
00187 } else {
00188 #ifdef DIAGNOSTIC
00189
00190
00191
00192
00193 memcpy(lr->data, logrec.data, logrec.size);
00194 rectype |= DB_debug_FLAG;
00195 memcpy(logrec.data, &rectype, sizeof(rectype));
00196
00197 ret = __log_put(dbenv,
00198 rlsnp, (DBT *)&logrec, flags | DB_LOG_NOCOPY);
00199 #else
00200 ret = 0;
00201 #endif
00202 STAILQ_INSERT_HEAD(&txnid->logs, lr, links);
00203 F_SET((TXN_DETAIL *)txnid->td, TXN_DTL_INMEMORY);
00204 LSN_NOT_LOGGED(*ret_lsnp);
00205 }
00206
00207 #ifdef LOG_DIAGNOSTIC
00208 if (ret != 0)
00209 (void)__ham_insdel_print(dbenv,
00210 (DBT *)&logrec, ret_lsnp, DB_TXN_PRINT, NULL);
00211 #endif
00212
00213 #ifdef DIAGNOSTIC
00214 __os_free(dbenv, logrec.data);
00215 #else
00216 if (is_durable || txnid == NULL)
00217 __os_free(dbenv, logrec.data);
00218 #endif
00219 return (ret);
00220 }
00221
00222
00223
00224
00225 int
00226 __ham_insdel_read(dbenv, recbuf, argpp)
00227 DB_ENV *dbenv;
00228 void *recbuf;
00229 __ham_insdel_args **argpp;
00230 {
00231 __ham_insdel_args *argp;
00232 u_int32_t uinttmp;
00233 u_int8_t *bp;
00234 int ret;
00235
00236 if ((ret = __os_malloc(dbenv,
00237 sizeof(__ham_insdel_args) + sizeof(DB_TXN), &argp)) != 0)
00238 return (ret);
00239 bp = recbuf;
00240 argp->txnid = (DB_TXN *)&argp[1];
00241
00242 memcpy(&argp->type, bp, sizeof(argp->type));
00243 bp += sizeof(argp->type);
00244
00245 memcpy(&argp->txnid->txnid, bp, sizeof(argp->txnid->txnid));
00246 bp += sizeof(argp->txnid->txnid);
00247
00248 memcpy(&argp->prev_lsn, bp, sizeof(DB_LSN));
00249 bp += sizeof(DB_LSN);
00250
00251 memcpy(&uinttmp, bp, sizeof(uinttmp));
00252 argp->opcode = (u_int32_t)uinttmp;
00253 bp += sizeof(uinttmp);
00254
00255 memcpy(&uinttmp, bp, sizeof(uinttmp));
00256 argp->fileid = (int32_t)uinttmp;
00257 bp += sizeof(uinttmp);
00258
00259 memcpy(&uinttmp, bp, sizeof(uinttmp));
00260 argp->pgno = (db_pgno_t)uinttmp;
00261 bp += sizeof(uinttmp);
00262
00263 memcpy(&uinttmp, bp, sizeof(uinttmp));
00264 argp->ndx = (u_int32_t)uinttmp;
00265 bp += sizeof(uinttmp);
00266
00267 memcpy(&argp->pagelsn, bp, sizeof(argp->pagelsn));
00268 bp += sizeof(argp->pagelsn);
00269
00270 memset(&argp->key, 0, sizeof(argp->key));
00271 memcpy(&argp->key.size, bp, sizeof(u_int32_t));
00272 bp += sizeof(u_int32_t);
00273 argp->key.data = bp;
00274 bp += argp->key.size;
00275
00276 memset(&argp->data, 0, sizeof(argp->data));
00277 memcpy(&argp->data.size, bp, sizeof(u_int32_t));
00278 bp += sizeof(u_int32_t);
00279 argp->data.data = bp;
00280 bp += argp->data.size;
00281
00282 *argpp = argp;
00283 return (0);
00284 }
00285
00286
00287
00288
00289
00290
00291 int
00292 __ham_newpage_log(dbp, txnid, ret_lsnp, flags,
00293 opcode, prev_pgno, prevlsn, new_pgno, pagelsn,
00294 next_pgno, nextlsn)
00295 DB *dbp;
00296 DB_TXN *txnid;
00297 DB_LSN *ret_lsnp;
00298 u_int32_t flags;
00299 u_int32_t opcode;
00300 db_pgno_t prev_pgno;
00301 DB_LSN * prevlsn;
00302 db_pgno_t new_pgno;
00303 DB_LSN * pagelsn;
00304 db_pgno_t next_pgno;
00305 DB_LSN * nextlsn;
00306 {
00307 DBT logrec;
00308 DB_ENV *dbenv;
00309 DB_TXNLOGREC *lr;
00310 DB_LSN *lsnp, null_lsn, *rlsnp;
00311 u_int32_t uinttmp, rectype, txn_num;
00312 u_int npad;
00313 u_int8_t *bp;
00314 int is_durable, ret;
00315
00316 dbenv = dbp->dbenv;
00317 COMPQUIET(lr, NULL);
00318
00319 rectype = DB___ham_newpage;
00320 npad = 0;
00321 rlsnp = ret_lsnp;
00322
00323 ret = 0;
00324
00325 if (LF_ISSET(DB_LOG_NOT_DURABLE) ||
00326 F_ISSET(dbp, DB_AM_NOT_DURABLE)) {
00327 is_durable = 0;
00328 } else
00329 is_durable = 1;
00330
00331 if (txnid == NULL) {
00332 txn_num = 0;
00333 lsnp = &null_lsn;
00334 null_lsn.file = null_lsn.offset = 0;
00335 } else {
00336 if (TAILQ_FIRST(&txnid->kids) != NULL &&
00337 (ret = __txn_activekids(dbenv, rectype, txnid)) != 0)
00338 return (ret);
00339
00340
00341
00342
00343
00344
00345 DB_SET_TXN_LSNP(txnid, &rlsnp, &lsnp);
00346 txn_num = txnid->txnid;
00347 }
00348
00349 DB_ASSERT(dbp->log_filename != NULL);
00350 if (dbp->log_filename->id == DB_LOGFILEID_INVALID &&
00351 (ret = __dbreg_lazy_id(dbp)) != 0)
00352 return (ret);
00353
00354 logrec.size = sizeof(rectype) + sizeof(txn_num) + sizeof(DB_LSN)
00355 + sizeof(u_int32_t)
00356 + sizeof(u_int32_t)
00357 + sizeof(u_int32_t)
00358 + sizeof(*prevlsn)
00359 + sizeof(u_int32_t)
00360 + sizeof(*pagelsn)
00361 + sizeof(u_int32_t)
00362 + sizeof(*nextlsn);
00363 if (CRYPTO_ON(dbenv)) {
00364 npad =
00365 ((DB_CIPHER *)dbenv->crypto_handle)->adj_size(logrec.size);
00366 logrec.size += npad;
00367 }
00368
00369 if (is_durable || txnid == NULL) {
00370 if ((ret =
00371 __os_malloc(dbenv, logrec.size, &logrec.data)) != 0)
00372 return (ret);
00373 } else {
00374 if ((ret = __os_malloc(dbenv,
00375 logrec.size + sizeof(DB_TXNLOGREC), &lr)) != 0)
00376 return (ret);
00377 #ifdef DIAGNOSTIC
00378 if ((ret =
00379 __os_malloc(dbenv, logrec.size, &logrec.data)) != 0) {
00380 __os_free(dbenv, lr);
00381 return (ret);
00382 }
00383 #else
00384 logrec.data = lr->data;
00385 #endif
00386 }
00387 if (npad > 0)
00388 memset((u_int8_t *)logrec.data + logrec.size - npad, 0, npad);
00389
00390 bp = logrec.data;
00391
00392 memcpy(bp, &rectype, sizeof(rectype));
00393 bp += sizeof(rectype);
00394
00395 memcpy(bp, &txn_num, sizeof(txn_num));
00396 bp += sizeof(txn_num);
00397
00398 memcpy(bp, lsnp, sizeof(DB_LSN));
00399 bp += sizeof(DB_LSN);
00400
00401 uinttmp = (u_int32_t)opcode;
00402 memcpy(bp, &uinttmp, sizeof(uinttmp));
00403 bp += sizeof(uinttmp);
00404
00405 uinttmp = (u_int32_t)dbp->log_filename->id;
00406 memcpy(bp, &uinttmp, sizeof(uinttmp));
00407 bp += sizeof(uinttmp);
00408
00409 uinttmp = (u_int32_t)prev_pgno;
00410 memcpy(bp, &uinttmp, sizeof(uinttmp));
00411 bp += sizeof(uinttmp);
00412
00413 if (prevlsn != NULL)
00414 memcpy(bp, prevlsn, sizeof(*prevlsn));
00415 else
00416 memset(bp, 0, sizeof(*prevlsn));
00417 bp += sizeof(*prevlsn);
00418
00419 uinttmp = (u_int32_t)new_pgno;
00420 memcpy(bp, &uinttmp, sizeof(uinttmp));
00421 bp += sizeof(uinttmp);
00422
00423 if (pagelsn != NULL)
00424 memcpy(bp, pagelsn, sizeof(*pagelsn));
00425 else
00426 memset(bp, 0, sizeof(*pagelsn));
00427 bp += sizeof(*pagelsn);
00428
00429 uinttmp = (u_int32_t)next_pgno;
00430 memcpy(bp, &uinttmp, sizeof(uinttmp));
00431 bp += sizeof(uinttmp);
00432
00433 if (nextlsn != NULL)
00434 memcpy(bp, nextlsn, sizeof(*nextlsn));
00435 else
00436 memset(bp, 0, sizeof(*nextlsn));
00437 bp += sizeof(*nextlsn);
00438
00439 DB_ASSERT((u_int32_t)(bp - (u_int8_t *)logrec.data) <= logrec.size);
00440
00441 if (is_durable || txnid == NULL) {
00442 if ((ret = __log_put(dbenv, rlsnp,(DBT *)&logrec,
00443 flags | DB_LOG_NOCOPY)) == 0 && txnid != NULL) {
00444 *lsnp = *rlsnp;
00445 if (rlsnp != ret_lsnp)
00446 *ret_lsnp = *rlsnp;
00447 }
00448 } else {
00449 #ifdef DIAGNOSTIC
00450
00451
00452
00453
00454 memcpy(lr->data, logrec.data, logrec.size);
00455 rectype |= DB_debug_FLAG;
00456 memcpy(logrec.data, &rectype, sizeof(rectype));
00457
00458 ret = __log_put(dbenv,
00459 rlsnp, (DBT *)&logrec, flags | DB_LOG_NOCOPY);
00460 #else
00461 ret = 0;
00462 #endif
00463 STAILQ_INSERT_HEAD(&txnid->logs, lr, links);
00464 F_SET((TXN_DETAIL *)txnid->td, TXN_DTL_INMEMORY);
00465 LSN_NOT_LOGGED(*ret_lsnp);
00466 }
00467
00468 #ifdef LOG_DIAGNOSTIC
00469 if (ret != 0)
00470 (void)__ham_newpage_print(dbenv,
00471 (DBT *)&logrec, ret_lsnp, DB_TXN_PRINT, NULL);
00472 #endif
00473
00474 #ifdef DIAGNOSTIC
00475 __os_free(dbenv, logrec.data);
00476 #else
00477 if (is_durable || txnid == NULL)
00478 __os_free(dbenv, logrec.data);
00479 #endif
00480 return (ret);
00481 }
00482
00483
00484
00485
00486
00487 int
00488 __ham_newpage_read(dbenv, recbuf, argpp)
00489 DB_ENV *dbenv;
00490 void *recbuf;
00491 __ham_newpage_args **argpp;
00492 {
00493 __ham_newpage_args *argp;
00494 u_int32_t uinttmp;
00495 u_int8_t *bp;
00496 int ret;
00497
00498 if ((ret = __os_malloc(dbenv,
00499 sizeof(__ham_newpage_args) + sizeof(DB_TXN), &argp)) != 0)
00500 return (ret);
00501 bp = recbuf;
00502 argp->txnid = (DB_TXN *)&argp[1];
00503
00504 memcpy(&argp->type, bp, sizeof(argp->type));
00505 bp += sizeof(argp->type);
00506
00507 memcpy(&argp->txnid->txnid, bp, sizeof(argp->txnid->txnid));
00508 bp += sizeof(argp->txnid->txnid);
00509
00510 memcpy(&argp->prev_lsn, bp, sizeof(DB_LSN));
00511 bp += sizeof(DB_LSN);
00512
00513 memcpy(&uinttmp, bp, sizeof(uinttmp));
00514 argp->opcode = (u_int32_t)uinttmp;
00515 bp += sizeof(uinttmp);
00516
00517 memcpy(&uinttmp, bp, sizeof(uinttmp));
00518 argp->fileid = (int32_t)uinttmp;
00519 bp += sizeof(uinttmp);
00520
00521 memcpy(&uinttmp, bp, sizeof(uinttmp));
00522 argp->prev_pgno = (db_pgno_t)uinttmp;
00523 bp += sizeof(uinttmp);
00524
00525 memcpy(&argp->prevlsn, bp, sizeof(argp->prevlsn));
00526 bp += sizeof(argp->prevlsn);
00527
00528 memcpy(&uinttmp, bp, sizeof(uinttmp));
00529 argp->new_pgno = (db_pgno_t)uinttmp;
00530 bp += sizeof(uinttmp);
00531
00532 memcpy(&argp->pagelsn, bp, sizeof(argp->pagelsn));
00533 bp += sizeof(argp->pagelsn);
00534
00535 memcpy(&uinttmp, bp, sizeof(uinttmp));
00536 argp->next_pgno = (db_pgno_t)uinttmp;
00537 bp += sizeof(uinttmp);
00538
00539 memcpy(&argp->nextlsn, bp, sizeof(argp->nextlsn));
00540 bp += sizeof(argp->nextlsn);
00541
00542 *argpp = argp;
00543 return (0);
00544 }
00545
00546
00547
00548
00549
00550 int
00551 __ham_splitdata_log(dbp, txnid, ret_lsnp, flags, opcode, pgno, pageimage, pagelsn)
00552 DB *dbp;
00553 DB_TXN *txnid;
00554 DB_LSN *ret_lsnp;
00555 u_int32_t flags;
00556 u_int32_t opcode;
00557 db_pgno_t pgno;
00558 const DBT *pageimage;
00559 DB_LSN * pagelsn;
00560 {
00561 DBT logrec;
00562 DB_ENV *dbenv;
00563 DB_TXNLOGREC *lr;
00564 DB_LSN *lsnp, null_lsn, *rlsnp;
00565 u_int32_t zero, uinttmp, rectype, txn_num;
00566 u_int npad;
00567 u_int8_t *bp;
00568 int is_durable, ret;
00569
00570 dbenv = dbp->dbenv;
00571 COMPQUIET(lr, NULL);
00572
00573 rectype = DB___ham_splitdata;
00574 npad = 0;
00575 rlsnp = ret_lsnp;
00576
00577 ret = 0;
00578
00579 if (LF_ISSET(DB_LOG_NOT_DURABLE) ||
00580 F_ISSET(dbp, DB_AM_NOT_DURABLE)) {
00581 is_durable = 0;
00582 } else
00583 is_durable = 1;
00584
00585 if (txnid == NULL) {
00586 txn_num = 0;
00587 lsnp = &null_lsn;
00588 null_lsn.file = null_lsn.offset = 0;
00589 } else {
00590 if (TAILQ_FIRST(&txnid->kids) != NULL &&
00591 (ret = __txn_activekids(dbenv, rectype, txnid)) != 0)
00592 return (ret);
00593
00594
00595
00596
00597
00598
00599 DB_SET_TXN_LSNP(txnid, &rlsnp, &lsnp);
00600 txn_num = txnid->txnid;
00601 }
00602
00603 DB_ASSERT(dbp->log_filename != NULL);
00604 if (dbp->log_filename->id == DB_LOGFILEID_INVALID &&
00605 (ret = __dbreg_lazy_id(dbp)) != 0)
00606 return (ret);
00607
00608 logrec.size = sizeof(rectype) + sizeof(txn_num) + sizeof(DB_LSN)
00609 + sizeof(u_int32_t)
00610 + sizeof(u_int32_t)
00611 + sizeof(u_int32_t)
00612 + sizeof(u_int32_t) + (pageimage == NULL ? 0 : pageimage->size)
00613 + sizeof(*pagelsn);
00614 if (CRYPTO_ON(dbenv)) {
00615 npad =
00616 ((DB_CIPHER *)dbenv->crypto_handle)->adj_size(logrec.size);
00617 logrec.size += npad;
00618 }
00619
00620 if (is_durable || txnid == NULL) {
00621 if ((ret =
00622 __os_malloc(dbenv, logrec.size, &logrec.data)) != 0)
00623 return (ret);
00624 } else {
00625 if ((ret = __os_malloc(dbenv,
00626 logrec.size + sizeof(DB_TXNLOGREC), &lr)) != 0)
00627 return (ret);
00628 #ifdef DIAGNOSTIC
00629 if ((ret =
00630 __os_malloc(dbenv, logrec.size, &logrec.data)) != 0) {
00631 __os_free(dbenv, lr);
00632 return (ret);
00633 }
00634 #else
00635 logrec.data = lr->data;
00636 #endif
00637 }
00638 if (npad > 0)
00639 memset((u_int8_t *)logrec.data + logrec.size - npad, 0, npad);
00640
00641 bp = logrec.data;
00642
00643 memcpy(bp, &rectype, sizeof(rectype));
00644 bp += sizeof(rectype);
00645
00646 memcpy(bp, &txn_num, sizeof(txn_num));
00647 bp += sizeof(txn_num);
00648
00649 memcpy(bp, lsnp, sizeof(DB_LSN));
00650 bp += sizeof(DB_LSN);
00651
00652 uinttmp = (u_int32_t)dbp->log_filename->id;
00653 memcpy(bp, &uinttmp, sizeof(uinttmp));
00654 bp += sizeof(uinttmp);
00655
00656 uinttmp = (u_int32_t)opcode;
00657 memcpy(bp, &uinttmp, sizeof(uinttmp));
00658 bp += sizeof(uinttmp);
00659
00660 uinttmp = (u_int32_t)pgno;
00661 memcpy(bp, &uinttmp, sizeof(uinttmp));
00662 bp += sizeof(uinttmp);
00663
00664 if (pageimage == NULL) {
00665 zero = 0;
00666 memcpy(bp, &zero, sizeof(u_int32_t));
00667 bp += sizeof(u_int32_t);
00668 } else {
00669 memcpy(bp, &pageimage->size, sizeof(pageimage->size));
00670 bp += sizeof(pageimage->size);
00671 memcpy(bp, pageimage->data, pageimage->size);
00672 bp += pageimage->size;
00673 }
00674
00675 if (pagelsn != NULL)
00676 memcpy(bp, pagelsn, sizeof(*pagelsn));
00677 else
00678 memset(bp, 0, sizeof(*pagelsn));
00679 bp += sizeof(*pagelsn);
00680
00681 DB_ASSERT((u_int32_t)(bp - (u_int8_t *)logrec.data) <= logrec.size);
00682
00683 if (is_durable || txnid == NULL) {
00684 if ((ret = __log_put(dbenv, rlsnp,(DBT *)&logrec,
00685 flags | DB_LOG_NOCOPY)) == 0 && txnid != NULL) {
00686 *lsnp = *rlsnp;
00687 if (rlsnp != ret_lsnp)
00688 *ret_lsnp = *rlsnp;
00689 }
00690 } else {
00691 #ifdef DIAGNOSTIC
00692
00693
00694
00695
00696 memcpy(lr->data, logrec.data, logrec.size);
00697 rectype |= DB_debug_FLAG;
00698 memcpy(logrec.data, &rectype, sizeof(rectype));
00699
00700 ret = __log_put(dbenv,
00701 rlsnp, (DBT *)&logrec, flags | DB_LOG_NOCOPY);
00702 #else
00703 ret = 0;
00704 #endif
00705 STAILQ_INSERT_HEAD(&txnid->logs, lr, links);
00706 F_SET((TXN_DETAIL *)txnid->td, TXN_DTL_INMEMORY);
00707 LSN_NOT_LOGGED(*ret_lsnp);
00708 }
00709
00710 #ifdef LOG_DIAGNOSTIC
00711 if (ret != 0)
00712 (void)__ham_splitdata_print(dbenv,
00713 (DBT *)&logrec, ret_lsnp, DB_TXN_PRINT, NULL);
00714 #endif
00715
00716 #ifdef DIAGNOSTIC
00717 __os_free(dbenv, logrec.data);
00718 #else
00719 if (is_durable || txnid == NULL)
00720 __os_free(dbenv, logrec.data);
00721 #endif
00722 return (ret);
00723 }
00724
00725
00726
00727
00728
00729 int
00730 __ham_splitdata_read(dbenv, recbuf, argpp)
00731 DB_ENV *dbenv;
00732 void *recbuf;
00733 __ham_splitdata_args **argpp;
00734 {
00735 __ham_splitdata_args *argp;
00736 u_int32_t uinttmp;
00737 u_int8_t *bp;
00738 int ret;
00739
00740 if ((ret = __os_malloc(dbenv,
00741 sizeof(__ham_splitdata_args) + sizeof(DB_TXN), &argp)) != 0)
00742 return (ret);
00743 bp = recbuf;
00744 argp->txnid = (DB_TXN *)&argp[1];
00745
00746 memcpy(&argp->type, bp, sizeof(argp->type));
00747 bp += sizeof(argp->type);
00748
00749 memcpy(&argp->txnid->txnid, bp, sizeof(argp->txnid->txnid));
00750 bp += sizeof(argp->txnid->txnid);
00751
00752 memcpy(&argp->prev_lsn, bp, sizeof(DB_LSN));
00753 bp += sizeof(DB_LSN);
00754
00755 memcpy(&uinttmp, bp, sizeof(uinttmp));
00756 argp->fileid = (int32_t)uinttmp;
00757 bp += sizeof(uinttmp);
00758
00759 memcpy(&uinttmp, bp, sizeof(uinttmp));
00760 argp->opcode = (u_int32_t)uinttmp;
00761 bp += sizeof(uinttmp);
00762
00763 memcpy(&uinttmp, bp, sizeof(uinttmp));
00764 argp->pgno = (db_pgno_t)uinttmp;
00765 bp += sizeof(uinttmp);
00766
00767 memset(&argp->pageimage, 0, sizeof(argp->pageimage));
00768 memcpy(&argp->pageimage.size, bp, sizeof(u_int32_t));
00769 bp += sizeof(u_int32_t);
00770 argp->pageimage.data = bp;
00771 bp += argp->pageimage.size;
00772
00773 memcpy(&argp->pagelsn, bp, sizeof(argp->pagelsn));
00774 bp += sizeof(argp->pagelsn);
00775
00776 *argpp = argp;
00777 return (0);
00778 }
00779
00780
00781
00782
00783
00784
00785 int
00786 __ham_replace_log(dbp, txnid, ret_lsnp, flags, pgno, ndx, pagelsn, off, olditem,
00787 newitem, makedup)
00788 DB *dbp;
00789 DB_TXN *txnid;
00790 DB_LSN *ret_lsnp;
00791 u_int32_t flags;
00792 db_pgno_t pgno;
00793 u_int32_t ndx;
00794 DB_LSN * pagelsn;
00795 int32_t off;
00796 const DBT *olditem;
00797 const DBT *newitem;
00798 u_int32_t makedup;
00799 {
00800 DBT logrec;
00801 DB_ENV *dbenv;
00802 DB_TXNLOGREC *lr;
00803 DB_LSN *lsnp, null_lsn, *rlsnp;
00804 u_int32_t zero, uinttmp, rectype, txn_num;
00805 u_int npad;
00806 u_int8_t *bp;
00807 int is_durable, ret;
00808
00809 dbenv = dbp->dbenv;
00810 COMPQUIET(lr, NULL);
00811
00812 rectype = DB___ham_replace;
00813 npad = 0;
00814 rlsnp = ret_lsnp;
00815
00816 ret = 0;
00817
00818 if (LF_ISSET(DB_LOG_NOT_DURABLE) ||
00819 F_ISSET(dbp, DB_AM_NOT_DURABLE)) {
00820 is_durable = 0;
00821 } else
00822 is_durable = 1;
00823
00824 if (txnid == NULL) {
00825 txn_num = 0;
00826 lsnp = &null_lsn;
00827 null_lsn.file = null_lsn.offset = 0;
00828 } else {
00829 if (TAILQ_FIRST(&txnid->kids) != NULL &&
00830 (ret = __txn_activekids(dbenv, rectype, txnid)) != 0)
00831 return (ret);
00832
00833
00834
00835
00836
00837
00838 DB_SET_TXN_LSNP(txnid, &rlsnp, &lsnp);
00839 txn_num = txnid->txnid;
00840 }
00841
00842 DB_ASSERT(dbp->log_filename != NULL);
00843 if (dbp->log_filename->id == DB_LOGFILEID_INVALID &&
00844 (ret = __dbreg_lazy_id(dbp)) != 0)
00845 return (ret);
00846
00847 logrec.size = sizeof(rectype) + sizeof(txn_num) + sizeof(DB_LSN)
00848 + sizeof(u_int32_t)
00849 + sizeof(u_int32_t)
00850 + sizeof(u_int32_t)
00851 + sizeof(*pagelsn)
00852 + sizeof(u_int32_t)
00853 + sizeof(u_int32_t) + (olditem == NULL ? 0 : olditem->size)
00854 + sizeof(u_int32_t) + (newitem == NULL ? 0 : newitem->size)
00855 + sizeof(u_int32_t);
00856 if (CRYPTO_ON(dbenv)) {
00857 npad =
00858 ((DB_CIPHER *)dbenv->crypto_handle)->adj_size(logrec.size);
00859 logrec.size += npad;
00860 }
00861
00862 if (is_durable || txnid == NULL) {
00863 if ((ret =
00864 __os_malloc(dbenv, logrec.size, &logrec.data)) != 0)
00865 return (ret);
00866 } else {
00867 if ((ret = __os_malloc(dbenv,
00868 logrec.size + sizeof(DB_TXNLOGREC), &lr)) != 0)
00869 return (ret);
00870 #ifdef DIAGNOSTIC
00871 if ((ret =
00872 __os_malloc(dbenv, logrec.size, &logrec.data)) != 0) {
00873 __os_free(dbenv, lr);
00874 return (ret);
00875 }
00876 #else
00877 logrec.data = lr->data;
00878 #endif
00879 }
00880 if (npad > 0)
00881 memset((u_int8_t *)logrec.data + logrec.size - npad, 0, npad);
00882
00883 bp = logrec.data;
00884
00885 memcpy(bp, &rectype, sizeof(rectype));
00886 bp += sizeof(rectype);
00887
00888 memcpy(bp, &txn_num, sizeof(txn_num));
00889 bp += sizeof(txn_num);
00890
00891 memcpy(bp, lsnp, sizeof(DB_LSN));
00892 bp += sizeof(DB_LSN);
00893
00894 uinttmp = (u_int32_t)dbp->log_filename->id;
00895 memcpy(bp, &uinttmp, sizeof(uinttmp));
00896 bp += sizeof(uinttmp);
00897
00898 uinttmp = (u_int32_t)pgno;
00899 memcpy(bp, &uinttmp, sizeof(uinttmp));
00900 bp += sizeof(uinttmp);
00901
00902 uinttmp = (u_int32_t)ndx;
00903 memcpy(bp, &uinttmp, sizeof(uinttmp));
00904 bp += sizeof(uinttmp);
00905
00906 if (pagelsn != NULL)
00907 memcpy(bp, pagelsn, sizeof(*pagelsn));
00908 else
00909 memset(bp, 0, sizeof(*pagelsn));
00910 bp += sizeof(*pagelsn);
00911
00912 uinttmp = (u_int32_t)off;
00913 memcpy(bp, &uinttmp, sizeof(uinttmp));
00914 bp += sizeof(uinttmp);
00915
00916 if (olditem == NULL) {
00917 zero = 0;
00918 memcpy(bp, &zero, sizeof(u_int32_t));
00919 bp += sizeof(u_int32_t);
00920 } else {
00921 memcpy(bp, &olditem->size, sizeof(olditem->size));
00922 bp += sizeof(olditem->size);
00923 memcpy(bp, olditem->data, olditem->size);
00924 bp += olditem->size;
00925 }
00926
00927 if (newitem == NULL) {
00928 zero = 0;
00929 memcpy(bp, &zero, sizeof(u_int32_t));
00930 bp += sizeof(u_int32_t);
00931 } else {
00932 memcpy(bp, &newitem->size, sizeof(newitem->size));
00933 bp += sizeof(newitem->size);
00934 memcpy(bp, newitem->data, newitem->size);
00935 bp += newitem->size;
00936 }
00937
00938 uinttmp = (u_int32_t)makedup;
00939 memcpy(bp, &uinttmp, sizeof(uinttmp));
00940 bp += sizeof(uinttmp);
00941
00942 DB_ASSERT((u_int32_t)(bp - (u_int8_t *)logrec.data) <= logrec.size);
00943
00944 if (is_durable || txnid == NULL) {
00945 if ((ret = __log_put(dbenv, rlsnp,(DBT *)&logrec,
00946 flags | DB_LOG_NOCOPY)) == 0 && txnid != NULL) {
00947 *lsnp = *rlsnp;
00948 if (rlsnp != ret_lsnp)
00949 *ret_lsnp = *rlsnp;
00950 }
00951 } else {
00952 #ifdef DIAGNOSTIC
00953
00954
00955
00956
00957 memcpy(lr->data, logrec.data, logrec.size);
00958 rectype |= DB_debug_FLAG;
00959 memcpy(logrec.data, &rectype, sizeof(rectype));
00960
00961 ret = __log_put(dbenv,
00962 rlsnp, (DBT *)&logrec, flags | DB_LOG_NOCOPY);
00963 #else
00964 ret = 0;
00965 #endif
00966 STAILQ_INSERT_HEAD(&txnid->logs, lr, links);
00967 F_SET((TXN_DETAIL *)txnid->td, TXN_DTL_INMEMORY);
00968 LSN_NOT_LOGGED(*ret_lsnp);
00969 }
00970
00971 #ifdef LOG_DIAGNOSTIC
00972 if (ret != 0)
00973 (void)__ham_replace_print(dbenv,
00974 (DBT *)&logrec, ret_lsnp, DB_TXN_PRINT, NULL);
00975 #endif
00976
00977 #ifdef DIAGNOSTIC
00978 __os_free(dbenv, logrec.data);
00979 #else
00980 if (is_durable || txnid == NULL)
00981 __os_free(dbenv, logrec.data);
00982 #endif
00983 return (ret);
00984 }
00985
00986
00987
00988
00989
00990 int
00991 __ham_replace_read(dbenv, recbuf, argpp)
00992 DB_ENV *dbenv;
00993 void *recbuf;
00994 __ham_replace_args **argpp;
00995 {
00996 __ham_replace_args *argp;
00997 u_int32_t uinttmp;
00998 u_int8_t *bp;
00999 int ret;
01000
01001 if ((ret = __os_malloc(dbenv,
01002 sizeof(__ham_replace_args) + sizeof(DB_TXN), &argp)) != 0)
01003 return (ret);
01004 bp = recbuf;
01005 argp->txnid = (DB_TXN *)&argp[1];
01006
01007 memcpy(&argp->type, bp, sizeof(argp->type));
01008 bp += sizeof(argp->type);
01009
01010 memcpy(&argp->txnid->txnid, bp, sizeof(argp->txnid->txnid));
01011 bp += sizeof(argp->txnid->txnid);
01012
01013 memcpy(&argp->prev_lsn, bp, sizeof(DB_LSN));
01014 bp += sizeof(DB_LSN);
01015
01016 memcpy(&uinttmp, bp, sizeof(uinttmp));
01017 argp->fileid = (int32_t)uinttmp;
01018 bp += sizeof(uinttmp);
01019
01020 memcpy(&uinttmp, bp, sizeof(uinttmp));
01021 argp->pgno = (db_pgno_t)uinttmp;
01022 bp += sizeof(uinttmp);
01023
01024 memcpy(&uinttmp, bp, sizeof(uinttmp));
01025 argp->ndx = (u_int32_t)uinttmp;
01026 bp += sizeof(uinttmp);
01027
01028 memcpy(&argp->pagelsn, bp, sizeof(argp->pagelsn));
01029 bp += sizeof(argp->pagelsn);
01030
01031 memcpy(&uinttmp, bp, sizeof(uinttmp));
01032 argp->off = (int32_t)uinttmp;
01033 bp += sizeof(uinttmp);
01034
01035 memset(&argp->olditem, 0, sizeof(argp->olditem));
01036 memcpy(&argp->olditem.size, bp, sizeof(u_int32_t));
01037 bp += sizeof(u_int32_t);
01038 argp->olditem.data = bp;
01039 bp += argp->olditem.size;
01040
01041 memset(&argp->newitem, 0, sizeof(argp->newitem));
01042 memcpy(&argp->newitem.size, bp, sizeof(u_int32_t));
01043 bp += sizeof(u_int32_t);
01044 argp->newitem.data = bp;
01045 bp += argp->newitem.size;
01046
01047 memcpy(&uinttmp, bp, sizeof(uinttmp));
01048 argp->makedup = (u_int32_t)uinttmp;
01049 bp += sizeof(uinttmp);
01050
01051 *argpp = argp;
01052 return (0);
01053 }
01054
01055
01056
01057
01058
01059
01060 int
01061 __ham_copypage_log(dbp, txnid, ret_lsnp, flags, pgno, pagelsn, next_pgno, nextlsn, nnext_pgno,
01062 nnextlsn, page)
01063 DB *dbp;
01064 DB_TXN *txnid;
01065 DB_LSN *ret_lsnp;
01066 u_int32_t flags;
01067 db_pgno_t pgno;
01068 DB_LSN * pagelsn;
01069 db_pgno_t next_pgno;
01070 DB_LSN * nextlsn;
01071 db_pgno_t nnext_pgno;
01072 DB_LSN * nnextlsn;
01073 const DBT *page;
01074 {
01075 DBT logrec;
01076 DB_ENV *dbenv;
01077 DB_TXNLOGREC *lr;
01078 DB_LSN *lsnp, null_lsn, *rlsnp;
01079 u_int32_t zero, uinttmp, rectype, txn_num;
01080 u_int npad;
01081 u_int8_t *bp;
01082 int is_durable, ret;
01083
01084 dbenv = dbp->dbenv;
01085 COMPQUIET(lr, NULL);
01086
01087 rectype = DB___ham_copypage;
01088 npad = 0;
01089 rlsnp = ret_lsnp;
01090
01091 ret = 0;
01092
01093 if (LF_ISSET(DB_LOG_NOT_DURABLE) ||
01094 F_ISSET(dbp, DB_AM_NOT_DURABLE)) {
01095 is_durable = 0;
01096 } else
01097 is_durable = 1;
01098
01099 if (txnid == NULL) {
01100 txn_num = 0;
01101 lsnp = &null_lsn;
01102 null_lsn.file = null_lsn.offset = 0;
01103 } else {
01104 if (TAILQ_FIRST(&txnid->kids) != NULL &&
01105 (ret = __txn_activekids(dbenv, rectype, txnid)) != 0)
01106 return (ret);
01107
01108
01109
01110
01111
01112
01113 DB_SET_TXN_LSNP(txnid, &rlsnp, &lsnp);
01114 txn_num = txnid->txnid;
01115 }
01116
01117 DB_ASSERT(dbp->log_filename != NULL);
01118 if (dbp->log_filename->id == DB_LOGFILEID_INVALID &&
01119 (ret = __dbreg_lazy_id(dbp)) != 0)
01120 return (ret);
01121
01122 logrec.size = sizeof(rectype) + sizeof(txn_num) + sizeof(DB_LSN)
01123 + sizeof(u_int32_t)
01124 + sizeof(u_int32_t)
01125 + sizeof(*pagelsn)
01126 + sizeof(u_int32_t)
01127 + sizeof(*nextlsn)
01128 + sizeof(u_int32_t)
01129 + sizeof(*nnextlsn)
01130 + sizeof(u_int32_t) + (page == NULL ? 0 : page->size);
01131 if (CRYPTO_ON(dbenv)) {
01132 npad =
01133 ((DB_CIPHER *)dbenv->crypto_handle)->adj_size(logrec.size);
01134 logrec.size += npad;
01135 }
01136
01137 if (is_durable || txnid == NULL) {
01138 if ((ret =
01139 __os_malloc(dbenv, logrec.size, &logrec.data)) != 0)
01140 return (ret);
01141 } else {
01142 if ((ret = __os_malloc(dbenv,
01143 logrec.size + sizeof(DB_TXNLOGREC), &lr)) != 0)
01144 return (ret);
01145 #ifdef DIAGNOSTIC
01146 if ((ret =
01147 __os_malloc(dbenv, logrec.size, &logrec.data)) != 0) {
01148 __os_free(dbenv, lr);
01149 return (ret);
01150 }
01151 #else
01152 logrec.data = lr->data;
01153 #endif
01154 }
01155 if (npad > 0)
01156 memset((u_int8_t *)logrec.data + logrec.size - npad, 0, npad);
01157
01158 bp = logrec.data;
01159
01160 memcpy(bp, &rectype, sizeof(rectype));
01161 bp += sizeof(rectype);
01162
01163 memcpy(bp, &txn_num, sizeof(txn_num));
01164 bp += sizeof(txn_num);
01165
01166 memcpy(bp, lsnp, sizeof(DB_LSN));
01167 bp += sizeof(DB_LSN);
01168
01169 uinttmp = (u_int32_t)dbp->log_filename->id;
01170 memcpy(bp, &uinttmp, sizeof(uinttmp));
01171 bp += sizeof(uinttmp);
01172
01173 uinttmp = (u_int32_t)pgno;
01174 memcpy(bp, &uinttmp, sizeof(uinttmp));
01175 bp += sizeof(uinttmp);
01176
01177 if (pagelsn != NULL)
01178 memcpy(bp, pagelsn, sizeof(*pagelsn));
01179 else
01180 memset(bp, 0, sizeof(*pagelsn));
01181 bp += sizeof(*pagelsn);
01182
01183 uinttmp = (u_int32_t)next_pgno;
01184 memcpy(bp, &uinttmp, sizeof(uinttmp));
01185 bp += sizeof(uinttmp);
01186
01187 if (nextlsn != NULL)
01188 memcpy(bp, nextlsn, sizeof(*nextlsn));
01189 else
01190 memset(bp, 0, sizeof(*nextlsn));
01191 bp += sizeof(*nextlsn);
01192
01193 uinttmp = (u_int32_t)nnext_pgno;
01194 memcpy(bp, &uinttmp, sizeof(uinttmp));
01195 bp += sizeof(uinttmp);
01196
01197 if (nnextlsn != NULL)
01198 memcpy(bp, nnextlsn, sizeof(*nnextlsn));
01199 else
01200 memset(bp, 0, sizeof(*nnextlsn));
01201 bp += sizeof(*nnextlsn);
01202
01203 if (page == NULL) {
01204 zero = 0;
01205 memcpy(bp, &zero, sizeof(u_int32_t));
01206 bp += sizeof(u_int32_t);
01207 } else {
01208 memcpy(bp, &page->size, sizeof(page->size));
01209 bp += sizeof(page->size);
01210 memcpy(bp, page->data, page->size);
01211 bp += page->size;
01212 }
01213
01214 DB_ASSERT((u_int32_t)(bp - (u_int8_t *)logrec.data) <= logrec.size);
01215
01216 if (is_durable || txnid == NULL) {
01217 if ((ret = __log_put(dbenv, rlsnp,(DBT *)&logrec,
01218 flags | DB_LOG_NOCOPY)) == 0 && txnid != NULL) {
01219 *lsnp = *rlsnp;
01220 if (rlsnp != ret_lsnp)
01221 *ret_lsnp = *rlsnp;
01222 }
01223 } else {
01224 #ifdef DIAGNOSTIC
01225
01226
01227
01228
01229 memcpy(lr->data, logrec.data, logrec.size);
01230 rectype |= DB_debug_FLAG;
01231 memcpy(logrec.data, &rectype, sizeof(rectype));
01232
01233 ret = __log_put(dbenv,
01234 rlsnp, (DBT *)&logrec, flags | DB_LOG_NOCOPY);
01235 #else
01236 ret = 0;
01237 #endif
01238 STAILQ_INSERT_HEAD(&txnid->logs, lr, links);
01239 F_SET((TXN_DETAIL *)txnid->td, TXN_DTL_INMEMORY);
01240 LSN_NOT_LOGGED(*ret_lsnp);
01241 }
01242
01243 #ifdef LOG_DIAGNOSTIC
01244 if (ret != 0)
01245 (void)__ham_copypage_print(dbenv,
01246 (DBT *)&logrec, ret_lsnp, DB_TXN_PRINT, NULL);
01247 #endif
01248
01249 #ifdef DIAGNOSTIC
01250 __os_free(dbenv, logrec.data);
01251 #else
01252 if (is_durable || txnid == NULL)
01253 __os_free(dbenv, logrec.data);
01254 #endif
01255 return (ret);
01256 }
01257
01258
01259
01260
01261
01262 int
01263 __ham_copypage_read(dbenv, recbuf, argpp)
01264 DB_ENV *dbenv;
01265 void *recbuf;
01266 __ham_copypage_args **argpp;
01267 {
01268 __ham_copypage_args *argp;
01269 u_int32_t uinttmp;
01270 u_int8_t *bp;
01271 int ret;
01272
01273 if ((ret = __os_malloc(dbenv,
01274 sizeof(__ham_copypage_args) + sizeof(DB_TXN), &argp)) != 0)
01275 return (ret);
01276 bp = recbuf;
01277 argp->txnid = (DB_TXN *)&argp[1];
01278
01279 memcpy(&argp->type, bp, sizeof(argp->type));
01280 bp += sizeof(argp->type);
01281
01282 memcpy(&argp->txnid->txnid, bp, sizeof(argp->txnid->txnid));
01283 bp += sizeof(argp->txnid->txnid);
01284
01285 memcpy(&argp->prev_lsn, bp, sizeof(DB_LSN));
01286 bp += sizeof(DB_LSN);
01287
01288 memcpy(&uinttmp, bp, sizeof(uinttmp));
01289 argp->fileid = (int32_t)uinttmp;
01290 bp += sizeof(uinttmp);
01291
01292 memcpy(&uinttmp, bp, sizeof(uinttmp));
01293 argp->pgno = (db_pgno_t)uinttmp;
01294 bp += sizeof(uinttmp);
01295
01296 memcpy(&argp->pagelsn, bp, sizeof(argp->pagelsn));
01297 bp += sizeof(argp->pagelsn);
01298
01299 memcpy(&uinttmp, bp, sizeof(uinttmp));
01300 argp->next_pgno = (db_pgno_t)uinttmp;
01301 bp += sizeof(uinttmp);
01302
01303 memcpy(&argp->nextlsn, bp, sizeof(argp->nextlsn));
01304 bp += sizeof(argp->nextlsn);
01305
01306 memcpy(&uinttmp, bp, sizeof(uinttmp));
01307 argp->nnext_pgno = (db_pgno_t)uinttmp;
01308 bp += sizeof(uinttmp);
01309
01310 memcpy(&argp->nnextlsn, bp, sizeof(argp->nnextlsn));
01311 bp += sizeof(argp->nnextlsn);
01312
01313 memset(&argp->page, 0, sizeof(argp->page));
01314 memcpy(&argp->page.size, bp, sizeof(u_int32_t));
01315 bp += sizeof(u_int32_t);
01316 argp->page.data = bp;
01317 bp += argp->page.size;
01318
01319 *argpp = argp;
01320 return (0);
01321 }
01322
01323
01324
01325
01326
01327
01328 int
01329 __ham_metagroup_log(dbp, txnid, ret_lsnp, flags, bucket, mmpgno, mmetalsn, mpgno, metalsn,
01330 pgno, pagelsn, newalloc, last_pgno)
01331 DB *dbp;
01332 DB_TXN *txnid;
01333 DB_LSN *ret_lsnp;
01334 u_int32_t flags;
01335 u_int32_t bucket;
01336 db_pgno_t mmpgno;
01337 DB_LSN * mmetalsn;
01338 db_pgno_t mpgno;
01339 DB_LSN * metalsn;
01340 db_pgno_t pgno;
01341 DB_LSN * pagelsn;
01342 u_int32_t newalloc;
01343 db_pgno_t last_pgno;
01344 {
01345 DBT logrec;
01346 DB_ENV *dbenv;
01347 DB_TXNLOGREC *lr;
01348 DB_LSN *lsnp, null_lsn, *rlsnp;
01349 u_int32_t uinttmp, rectype, txn_num;
01350 u_int npad;
01351 u_int8_t *bp;
01352 int is_durable, ret;
01353
01354 dbenv = dbp->dbenv;
01355 COMPQUIET(lr, NULL);
01356
01357 rectype = DB___ham_metagroup;
01358 npad = 0;
01359 rlsnp = ret_lsnp;
01360
01361 ret = 0;
01362
01363 if (LF_ISSET(DB_LOG_NOT_DURABLE) ||
01364 F_ISSET(dbp, DB_AM_NOT_DURABLE)) {
01365 is_durable = 0;
01366 } else
01367 is_durable = 1;
01368
01369 if (txnid == NULL) {
01370 txn_num = 0;
01371 lsnp = &null_lsn;
01372 null_lsn.file = null_lsn.offset = 0;
01373 } else {
01374 if (TAILQ_FIRST(&txnid->kids) != NULL &&
01375 (ret = __txn_activekids(dbenv, rectype, txnid)) != 0)
01376 return (ret);
01377
01378
01379
01380
01381
01382
01383 DB_SET_TXN_LSNP(txnid, &rlsnp, &lsnp);
01384 txn_num = txnid->txnid;
01385 }
01386
01387 DB_ASSERT(dbp->log_filename != NULL);
01388 if (dbp->log_filename->id == DB_LOGFILEID_INVALID &&
01389 (ret = __dbreg_lazy_id(dbp)) != 0)
01390 return (ret);
01391
01392 logrec.size = sizeof(rectype) + sizeof(txn_num) + sizeof(DB_LSN)
01393 + sizeof(u_int32_t)
01394 + sizeof(u_int32_t)
01395 + sizeof(u_int32_t)
01396 + sizeof(*mmetalsn)
01397 + sizeof(u_int32_t)
01398 + sizeof(*metalsn)
01399 + sizeof(u_int32_t)
01400 + sizeof(*pagelsn)
01401 + sizeof(u_int32_t)
01402 + sizeof(u_int32_t);
01403 if (CRYPTO_ON(dbenv)) {
01404 npad =
01405 ((DB_CIPHER *)dbenv->crypto_handle)->adj_size(logrec.size);
01406 logrec.size += npad;
01407 }
01408
01409 if (is_durable || txnid == NULL) {
01410 if ((ret =
01411 __os_malloc(dbenv, logrec.size, &logrec.data)) != 0)
01412 return (ret);
01413 } else {
01414 if ((ret = __os_malloc(dbenv,
01415 logrec.size + sizeof(DB_TXNLOGREC), &lr)) != 0)
01416 return (ret);
01417 #ifdef DIAGNOSTIC
01418 if ((ret =
01419 __os_malloc(dbenv, logrec.size, &logrec.data)) != 0) {
01420 __os_free(dbenv, lr);
01421 return (ret);
01422 }
01423 #else
01424 logrec.data = lr->data;
01425 #endif
01426 }
01427 if (npad > 0)
01428 memset((u_int8_t *)logrec.data + logrec.size - npad, 0, npad);
01429
01430 bp = logrec.data;
01431
01432 memcpy(bp, &rectype, sizeof(rectype));
01433 bp += sizeof(rectype);
01434
01435 memcpy(bp, &txn_num, sizeof(txn_num));
01436 bp += sizeof(txn_num);
01437
01438 memcpy(bp, lsnp, sizeof(DB_LSN));
01439 bp += sizeof(DB_LSN);
01440
01441 uinttmp = (u_int32_t)dbp->log_filename->id;
01442 memcpy(bp, &uinttmp, sizeof(uinttmp));
01443 bp += sizeof(uinttmp);
01444
01445 uinttmp = (u_int32_t)bucket;
01446 memcpy(bp, &uinttmp, sizeof(uinttmp));
01447 bp += sizeof(uinttmp);
01448
01449 uinttmp = (u_int32_t)mmpgno;
01450 memcpy(bp, &uinttmp, sizeof(uinttmp));
01451 bp += sizeof(uinttmp);
01452
01453 if (mmetalsn != NULL)
01454 memcpy(bp, mmetalsn, sizeof(*mmetalsn));
01455 else
01456 memset(bp, 0, sizeof(*mmetalsn));
01457 bp += sizeof(*mmetalsn);
01458
01459 uinttmp = (u_int32_t)mpgno;
01460 memcpy(bp, &uinttmp, sizeof(uinttmp));
01461 bp += sizeof(uinttmp);
01462
01463 if (metalsn != NULL)
01464 memcpy(bp, metalsn, sizeof(*metalsn));
01465 else
01466 memset(bp, 0, sizeof(*metalsn));
01467 bp += sizeof(*metalsn);
01468
01469 uinttmp = (u_int32_t)pgno;
01470 memcpy(bp, &uinttmp, sizeof(uinttmp));
01471 bp += sizeof(uinttmp);
01472
01473 if (pagelsn != NULL)
01474 memcpy(bp, pagelsn, sizeof(*pagelsn));
01475 else
01476 memset(bp, 0, sizeof(*pagelsn));
01477 bp += sizeof(*pagelsn);
01478
01479 uinttmp = (u_int32_t)newalloc;
01480 memcpy(bp, &uinttmp, sizeof(uinttmp));
01481 bp += sizeof(uinttmp);
01482
01483 uinttmp = (u_int32_t)last_pgno;
01484 memcpy(bp, &uinttmp, sizeof(uinttmp));
01485 bp += sizeof(uinttmp);
01486
01487 DB_ASSERT((u_int32_t)(bp - (u_int8_t *)logrec.data) <= logrec.size);
01488
01489 if (is_durable || txnid == NULL) {
01490 if ((ret = __log_put(dbenv, rlsnp,(DBT *)&logrec,
01491 flags | DB_LOG_NOCOPY)) == 0 && txnid != NULL) {
01492 *lsnp = *rlsnp;
01493 if (rlsnp != ret_lsnp)
01494 *ret_lsnp = *rlsnp;
01495 }
01496 } else {
01497 #ifdef DIAGNOSTIC
01498
01499
01500
01501
01502 memcpy(lr->data, logrec.data, logrec.size);
01503 rectype |= DB_debug_FLAG;
01504 memcpy(logrec.data, &rectype, sizeof(rectype));
01505
01506 ret = __log_put(dbenv,
01507 rlsnp, (DBT *)&logrec, flags | DB_LOG_NOCOPY);
01508 #else
01509 ret = 0;
01510 #endif
01511 STAILQ_INSERT_HEAD(&txnid->logs, lr, links);
01512 F_SET((TXN_DETAIL *)txnid->td, TXN_DTL_INMEMORY);
01513 LSN_NOT_LOGGED(*ret_lsnp);
01514 }
01515
01516 #ifdef LOG_DIAGNOSTIC
01517 if (ret != 0)
01518 (void)__ham_metagroup_print(dbenv,
01519 (DBT *)&logrec, ret_lsnp, DB_TXN_PRINT, NULL);
01520 #endif
01521
01522 #ifdef DIAGNOSTIC
01523 __os_free(dbenv, logrec.data);
01524 #else
01525 if (is_durable || txnid == NULL)
01526 __os_free(dbenv, logrec.data);
01527 #endif
01528 return (ret);
01529 }
01530
01531
01532
01533
01534
01535 int
01536 __ham_metagroup_read(dbenv, recbuf, argpp)
01537 DB_ENV *dbenv;
01538 void *recbuf;
01539 __ham_metagroup_args **argpp;
01540 {
01541 __ham_metagroup_args *argp;
01542 u_int32_t uinttmp;
01543 u_int8_t *bp;
01544 int ret;
01545
01546 if ((ret = __os_malloc(dbenv,
01547 sizeof(__ham_metagroup_args) + sizeof(DB_TXN), &argp)) != 0)
01548 return (ret);
01549 bp = recbuf;
01550 argp->txnid = (DB_TXN *)&argp[1];
01551
01552 memcpy(&argp->type, bp, sizeof(argp->type));
01553 bp += sizeof(argp->type);
01554
01555 memcpy(&argp->txnid->txnid, bp, sizeof(argp->txnid->txnid));
01556 bp += sizeof(argp->txnid->txnid);
01557
01558 memcpy(&argp->prev_lsn, bp, sizeof(DB_LSN));
01559 bp += sizeof(DB_LSN);
01560
01561 memcpy(&uinttmp, bp, sizeof(uinttmp));
01562 argp->fileid = (int32_t)uinttmp;
01563 bp += sizeof(uinttmp);
01564
01565 memcpy(&uinttmp, bp, sizeof(uinttmp));
01566 argp->bucket = (u_int32_t)uinttmp;
01567 bp += sizeof(uinttmp);
01568
01569 memcpy(&uinttmp, bp, sizeof(uinttmp));
01570 argp->mmpgno = (db_pgno_t)uinttmp;
01571 bp += sizeof(uinttmp);
01572
01573 memcpy(&argp->mmetalsn, bp, sizeof(argp->mmetalsn));
01574 bp += sizeof(argp->mmetalsn);
01575
01576 memcpy(&uinttmp, bp, sizeof(uinttmp));
01577 argp->mpgno = (db_pgno_t)uinttmp;
01578 bp += sizeof(uinttmp);
01579
01580 memcpy(&argp->metalsn, bp, sizeof(argp->metalsn));
01581 bp += sizeof(argp->metalsn);
01582
01583 memcpy(&uinttmp, bp, sizeof(uinttmp));
01584 argp->pgno = (db_pgno_t)uinttmp;
01585 bp += sizeof(uinttmp);
01586
01587 memcpy(&argp->pagelsn, bp, sizeof(argp->pagelsn));
01588 bp += sizeof(argp->pagelsn);
01589
01590 memcpy(&uinttmp, bp, sizeof(uinttmp));
01591 argp->newalloc = (u_int32_t)uinttmp;
01592 bp += sizeof(uinttmp);
01593
01594 memcpy(&uinttmp, bp, sizeof(uinttmp));
01595 argp->last_pgno = (db_pgno_t)uinttmp;
01596 bp += sizeof(uinttmp);
01597
01598 *argpp = argp;
01599 return (0);
01600 }
01601
01602
01603
01604
01605
01606
01607 int
01608 __ham_groupalloc_log(dbp, txnid, ret_lsnp, flags, meta_lsn, start_pgno, num, free, last_pgno)
01609 DB *dbp;
01610 DB_TXN *txnid;
01611 DB_LSN *ret_lsnp;
01612 u_int32_t flags;
01613 DB_LSN * meta_lsn;
01614 db_pgno_t start_pgno;
01615 u_int32_t num;
01616 db_pgno_t free;
01617 db_pgno_t last_pgno;
01618 {
01619 DBT logrec;
01620 DB_ENV *dbenv;
01621 DB_TXNLOGREC *lr;
01622 DB_LSN *lsnp, null_lsn, *rlsnp;
01623 u_int32_t uinttmp, rectype, txn_num;
01624 u_int npad;
01625 u_int8_t *bp;
01626 int is_durable, ret;
01627
01628 dbenv = dbp->dbenv;
01629 COMPQUIET(lr, NULL);
01630
01631 rectype = DB___ham_groupalloc;
01632 npad = 0;
01633 rlsnp = ret_lsnp;
01634
01635 ret = 0;
01636
01637 if (LF_ISSET(DB_LOG_NOT_DURABLE) ||
01638 F_ISSET(dbp, DB_AM_NOT_DURABLE)) {
01639 is_durable = 0;
01640 } else
01641 is_durable = 1;
01642
01643 if (txnid == NULL) {
01644 txn_num = 0;
01645 lsnp = &null_lsn;
01646 null_lsn.file = null_lsn.offset = 0;
01647 } else {
01648 if (TAILQ_FIRST(&txnid->kids) != NULL &&
01649 (ret = __txn_activekids(dbenv, rectype, txnid)) != 0)
01650 return (ret);
01651
01652
01653
01654
01655
01656
01657 DB_SET_TXN_LSNP(txnid, &rlsnp, &lsnp);
01658 txn_num = txnid->txnid;
01659 }
01660
01661 DB_ASSERT(dbp->log_filename != NULL);
01662 if (dbp->log_filename->id == DB_LOGFILEID_INVALID &&
01663 (ret = __dbreg_lazy_id(dbp)) != 0)
01664 return (ret);
01665
01666 logrec.size = sizeof(rectype) + sizeof(txn_num) + sizeof(DB_LSN)
01667 + sizeof(u_int32_t)
01668 + sizeof(*meta_lsn)
01669 + sizeof(u_int32_t)
01670 + sizeof(u_int32_t)
01671 + sizeof(u_int32_t)
01672 + sizeof(u_int32_t);
01673 if (CRYPTO_ON(dbenv)) {
01674 npad =
01675 ((DB_CIPHER *)dbenv->crypto_handle)->adj_size(logrec.size);
01676 logrec.size += npad;
01677 }
01678
01679 if (is_durable || txnid == NULL) {
01680 if ((ret =
01681 __os_malloc(dbenv, logrec.size, &logrec.data)) != 0)
01682 return (ret);
01683 } else {
01684 if ((ret = __os_malloc(dbenv,
01685 logrec.size + sizeof(DB_TXNLOGREC), &lr)) != 0)
01686 return (ret);
01687 #ifdef DIAGNOSTIC
01688 if ((ret =
01689 __os_malloc(dbenv, logrec.size, &logrec.data)) != 0) {
01690 __os_free(dbenv, lr);
01691 return (ret);
01692 }
01693 #else
01694 logrec.data = lr->data;
01695 #endif
01696 }
01697 if (npad > 0)
01698 memset((u_int8_t *)logrec.data + logrec.size - npad, 0, npad);
01699
01700 bp = logrec.data;
01701
01702 memcpy(bp, &rectype, sizeof(rectype));
01703 bp += sizeof(rectype);
01704
01705 memcpy(bp, &txn_num, sizeof(txn_num));
01706 bp += sizeof(txn_num);
01707
01708 memcpy(bp, lsnp, sizeof(DB_LSN));
01709 bp += sizeof(DB_LSN);
01710
01711 uinttmp = (u_int32_t)dbp->log_filename->id;
01712 memcpy(bp, &uinttmp, sizeof(uinttmp));
01713 bp += sizeof(uinttmp);
01714
01715 if (meta_lsn != NULL)
01716 memcpy(bp, meta_lsn, sizeof(*meta_lsn));
01717 else
01718 memset(bp, 0, sizeof(*meta_lsn));
01719 bp += sizeof(*meta_lsn);
01720
01721 uinttmp = (u_int32_t)start_pgno;
01722 memcpy(bp, &uinttmp, sizeof(uinttmp));
01723 bp += sizeof(uinttmp);
01724
01725 uinttmp = (u_int32_t)num;
01726 memcpy(bp, &uinttmp, sizeof(uinttmp));
01727 bp += sizeof(uinttmp);
01728
01729 uinttmp = (u_int32_t)free;
01730 memcpy(bp, &uinttmp, sizeof(uinttmp));
01731 bp += sizeof(uinttmp);
01732
01733 uinttmp = (u_int32_t)last_pgno;
01734 memcpy(bp, &uinttmp, sizeof(uinttmp));
01735 bp += sizeof(uinttmp);
01736
01737 DB_ASSERT((u_int32_t)(bp - (u_int8_t *)logrec.data) <= logrec.size);
01738
01739 if (is_durable || txnid == NULL) {
01740 if ((ret = __log_put(dbenv, rlsnp,(DBT *)&logrec,
01741 flags | DB_LOG_NOCOPY)) == 0 && txnid != NULL) {
01742 *lsnp = *rlsnp;
01743 if (rlsnp != ret_lsnp)
01744 *ret_lsnp = *rlsnp;
01745 }
01746 } else {
01747 #ifdef DIAGNOSTIC
01748
01749
01750
01751
01752 memcpy(lr->data, logrec.data, logrec.size);
01753 rectype |= DB_debug_FLAG;
01754 memcpy(logrec.data, &rectype, sizeof(rectype));
01755
01756 ret = __log_put(dbenv,
01757 rlsnp, (DBT *)&logrec, flags | DB_LOG_NOCOPY);
01758 #else
01759 ret = 0;
01760 #endif
01761 STAILQ_INSERT_HEAD(&txnid->logs, lr, links);
01762 F_SET((TXN_DETAIL *)txnid->td, TXN_DTL_INMEMORY);
01763 LSN_NOT_LOGGED(*ret_lsnp);
01764 }
01765
01766 #ifdef LOG_DIAGNOSTIC
01767 if (ret != 0)
01768 (void)__ham_groupalloc_print(dbenv,
01769 (DBT *)&logrec, ret_lsnp, DB_TXN_PRINT, NULL);
01770 #endif
01771
01772 #ifdef DIAGNOSTIC
01773 __os_free(dbenv, logrec.data);
01774 #else
01775 if (is_durable || txnid == NULL)
01776 __os_free(dbenv, logrec.data);
01777 #endif
01778 return (ret);
01779 }
01780
01781
01782
01783
01784
01785 int
01786 __ham_groupalloc_read(dbenv, recbuf, argpp)
01787 DB_ENV *dbenv;
01788 void *recbuf;
01789 __ham_groupalloc_args **argpp;
01790 {
01791 __ham_groupalloc_args *argp;
01792 u_int32_t uinttmp;
01793 u_int8_t *bp;
01794 int ret;
01795
01796 if ((ret = __os_malloc(dbenv,
01797 sizeof(__ham_groupalloc_args) + sizeof(DB_TXN), &argp)) != 0)
01798 return (ret);
01799 bp = recbuf;
01800 argp->txnid = (DB_TXN *)&argp[1];
01801
01802 memcpy(&argp->type, bp, sizeof(argp->type));
01803 bp += sizeof(argp->type);
01804
01805 memcpy(&argp->txnid->txnid, bp, sizeof(argp->txnid->txnid));
01806 bp += sizeof(argp->txnid->txnid);
01807
01808 memcpy(&argp->prev_lsn, bp, sizeof(DB_LSN));
01809 bp += sizeof(DB_LSN);
01810
01811 memcpy(&uinttmp, bp, sizeof(uinttmp));
01812 argp->fileid = (int32_t)uinttmp;
01813 bp += sizeof(uinttmp);
01814
01815 memcpy(&argp->meta_lsn, bp, sizeof(argp->meta_lsn));
01816 bp += sizeof(argp->meta_lsn);
01817
01818 memcpy(&uinttmp, bp, sizeof(uinttmp));
01819 argp->start_pgno = (db_pgno_t)uinttmp;
01820 bp += sizeof(uinttmp);
01821
01822 memcpy(&uinttmp, bp, sizeof(uinttmp));
01823 argp->num = (u_int32_t)uinttmp;
01824 bp += sizeof(uinttmp);
01825
01826 memcpy(&uinttmp, bp, sizeof(uinttmp));
01827 argp->free = (db_pgno_t)uinttmp;
01828 bp += sizeof(uinttmp);
01829
01830 memcpy(&uinttmp, bp, sizeof(uinttmp));
01831 argp->last_pgno = (db_pgno_t)uinttmp;
01832 bp += sizeof(uinttmp);
01833
01834 *argpp = argp;
01835 return (0);
01836 }
01837
01838
01839
01840
01841
01842
01843 int
01844 __ham_curadj_log(dbp, txnid, ret_lsnp, flags, pgno, indx, len, dup_off, add,
01845 is_dup, order)
01846 DB *dbp;
01847 DB_TXN *txnid;
01848 DB_LSN *ret_lsnp;
01849 u_int32_t flags;
01850 db_pgno_t pgno;
01851 u_int32_t indx;
01852 u_int32_t len;
01853 u_int32_t dup_off;
01854 int add;
01855 int is_dup;
01856 u_int32_t order;
01857 {
01858 DBT logrec;
01859 DB_ENV *dbenv;
01860 DB_TXNLOGREC *lr;
01861 DB_LSN *lsnp, null_lsn, *rlsnp;
01862 u_int32_t uinttmp, rectype, txn_num;
01863 u_int npad;
01864 u_int8_t *bp;
01865 int is_durable, ret;
01866
01867 dbenv = dbp->dbenv;
01868 COMPQUIET(lr, NULL);
01869
01870 rectype = DB___ham_curadj;
01871 npad = 0;
01872 rlsnp = ret_lsnp;
01873
01874 ret = 0;
01875
01876 if (LF_ISSET(DB_LOG_NOT_DURABLE) ||
01877 F_ISSET(dbp, DB_AM_NOT_DURABLE)) {
01878 is_durable = 0;
01879 } else
01880 is_durable = 1;
01881
01882 if (txnid == NULL) {
01883 txn_num = 0;
01884 lsnp = &null_lsn;
01885 null_lsn.file = null_lsn.offset = 0;
01886 } else {
01887 if (TAILQ_FIRST(&txnid->kids) != NULL &&
01888 (ret = __txn_activekids(dbenv, rectype, txnid)) != 0)
01889 return (ret);
01890
01891
01892
01893
01894
01895
01896 DB_SET_TXN_LSNP(txnid, &rlsnp, &lsnp);
01897 txn_num = txnid->txnid;
01898 }
01899
01900 DB_ASSERT(dbp->log_filename != NULL);
01901 if (dbp->log_filename->id == DB_LOGFILEID_INVALID &&
01902 (ret = __dbreg_lazy_id(dbp)) != 0)
01903 return (ret);
01904
01905 logrec.size = sizeof(rectype) + sizeof(txn_num) + sizeof(DB_LSN)
01906 + sizeof(u_int32_t)
01907 + sizeof(u_int32_t)
01908 + sizeof(u_int32_t)
01909 + sizeof(u_int32_t)
01910 + sizeof(u_int32_t)
01911 + sizeof(u_int32_t)
01912 + sizeof(u_int32_t)
01913 + sizeof(u_int32_t);
01914 if (CRYPTO_ON(dbenv)) {
01915 npad =
01916 ((DB_CIPHER *)dbenv->crypto_handle)->adj_size(logrec.size);
01917 logrec.size += npad;
01918 }
01919
01920 if (is_durable || txnid == NULL) {
01921 if ((ret =
01922 __os_malloc(dbenv, logrec.size, &logrec.data)) != 0)
01923 return (ret);
01924 } else {
01925 if ((ret = __os_malloc(dbenv,
01926 logrec.size + sizeof(DB_TXNLOGREC), &lr)) != 0)
01927 return (ret);
01928 #ifdef DIAGNOSTIC
01929 if ((ret =
01930 __os_malloc(dbenv, logrec.size, &logrec.data)) != 0) {
01931 __os_free(dbenv, lr);
01932 return (ret);
01933 }
01934 #else
01935 logrec.data = lr->data;
01936 #endif
01937 }
01938 if (npad > 0)
01939 memset((u_int8_t *)logrec.data + logrec.size - npad, 0, npad);
01940
01941 bp = logrec.data;
01942
01943 memcpy(bp, &rectype, sizeof(rectype));
01944 bp += sizeof(rectype);
01945
01946 memcpy(bp, &txn_num, sizeof(txn_num));
01947 bp += sizeof(txn_num);
01948
01949 memcpy(bp, lsnp, sizeof(DB_LSN));
01950 bp += sizeof(DB_LSN);
01951
01952 uinttmp = (u_int32_t)dbp->log_filename->id;
01953 memcpy(bp, &uinttmp, sizeof(uinttmp));
01954 bp += sizeof(uinttmp);
01955
01956 uinttmp = (u_int32_t)pgno;
01957 memcpy(bp, &uinttmp, sizeof(uinttmp));
01958 bp += sizeof(uinttmp);
01959
01960 uinttmp = (u_int32_t)indx;
01961 memcpy(bp, &uinttmp, sizeof(uinttmp));
01962 bp += sizeof(uinttmp);
01963
01964 uinttmp = (u_int32_t)len;
01965 memcpy(bp, &uinttmp, sizeof(uinttmp));
01966 bp += sizeof(uinttmp);
01967
01968 uinttmp = (u_int32_t)dup_off;
01969 memcpy(bp, &uinttmp, sizeof(uinttmp));
01970 bp += sizeof(uinttmp);
01971
01972 uinttmp = (u_int32_t)add;
01973 memcpy(bp, &uinttmp, sizeof(uinttmp));
01974 bp += sizeof(uinttmp);
01975
01976 uinttmp = (u_int32_t)is_dup;
01977 memcpy(bp, &uinttmp, sizeof(uinttmp));
01978 bp += sizeof(uinttmp);
01979
01980 uinttmp = (u_int32_t)order;
01981 memcpy(bp, &uinttmp, sizeof(uinttmp));
01982 bp += sizeof(uinttmp);
01983
01984 DB_ASSERT((u_int32_t)(bp - (u_int8_t *)logrec.data) <= logrec.size);
01985
01986 if (is_durable || txnid == NULL) {
01987 if ((ret = __log_put(dbenv, rlsnp,(DBT *)&logrec,
01988 flags | DB_LOG_NOCOPY)) == 0 && txnid != NULL) {
01989 *lsnp = *rlsnp;
01990 if (rlsnp != ret_lsnp)
01991 *ret_lsnp = *rlsnp;
01992 }
01993 } else {
01994 #ifdef DIAGNOSTIC
01995
01996
01997
01998
01999 memcpy(lr->data, logrec.data, logrec.size);
02000 rectype |= DB_debug_FLAG;
02001 memcpy(logrec.data, &rectype, sizeof(rectype));
02002
02003 ret = __log_put(dbenv,
02004 rlsnp, (DBT *)&logrec, flags | DB_LOG_NOCOPY);
02005 #else
02006 ret = 0;
02007 #endif
02008 STAILQ_INSERT_HEAD(&txnid->logs, lr, links);
02009 F_SET((TXN_DETAIL *)txnid->td, TXN_DTL_INMEMORY);
02010 LSN_NOT_LOGGED(*ret_lsnp);
02011 }
02012
02013 #ifdef LOG_DIAGNOSTIC
02014 if (ret != 0)
02015 (void)__ham_curadj_print(dbenv,
02016 (DBT *)&logrec, ret_lsnp, DB_TXN_PRINT, NULL);
02017 #endif
02018
02019 #ifdef DIAGNOSTIC
02020 __os_free(dbenv, logrec.data);
02021 #else
02022 if (is_durable || txnid == NULL)
02023 __os_free(dbenv, logrec.data);
02024 #endif
02025 return (ret);
02026 }
02027
02028
02029
02030
02031 int
02032 __ham_curadj_read(dbenv, recbuf, argpp)
02033 DB_ENV *dbenv;
02034 void *recbuf;
02035 __ham_curadj_args **argpp;
02036 {
02037 __ham_curadj_args *argp;
02038 u_int32_t uinttmp;
02039 u_int8_t *bp;
02040 int ret;
02041
02042 if ((ret = __os_malloc(dbenv,
02043 sizeof(__ham_curadj_args) + sizeof(DB_TXN), &argp)) != 0)
02044 return (ret);
02045 bp = recbuf;
02046 argp->txnid = (DB_TXN *)&argp[1];
02047
02048 memcpy(&argp->type, bp, sizeof(argp->type));
02049 bp += sizeof(argp->type);
02050
02051 memcpy(&argp->txnid->txnid, bp, sizeof(argp->txnid->txnid));
02052 bp += sizeof(argp->txnid->txnid);
02053
02054 memcpy(&argp->prev_lsn, bp, sizeof(DB_LSN));
02055 bp += sizeof(DB_LSN);
02056
02057 memcpy(&uinttmp, bp, sizeof(uinttmp));
02058 argp->fileid = (int32_t)uinttmp;
02059 bp += sizeof(uinttmp);
02060
02061 memcpy(&uinttmp, bp, sizeof(uinttmp));
02062 argp->pgno = (db_pgno_t)uinttmp;
02063 bp += sizeof(uinttmp);
02064
02065 memcpy(&uinttmp, bp, sizeof(uinttmp));
02066 argp->indx = (u_int32_t)uinttmp;
02067 bp += sizeof(uinttmp);
02068
02069 memcpy(&uinttmp, bp, sizeof(uinttmp));
02070 argp->len = (u_int32_t)uinttmp;
02071 bp += sizeof(uinttmp);
02072
02073 memcpy(&uinttmp, bp, sizeof(uinttmp));
02074 argp->dup_off = (u_int32_t)uinttmp;
02075 bp += sizeof(uinttmp);
02076
02077 memcpy(&uinttmp, bp, sizeof(uinttmp));
02078 argp->add = (int)uinttmp;
02079 bp += sizeof(uinttmp);
02080
02081 memcpy(&uinttmp, bp, sizeof(uinttmp));
02082 argp->is_dup = (int)uinttmp;
02083 bp += sizeof(uinttmp);
02084
02085 memcpy(&uinttmp, bp, sizeof(uinttmp));
02086 argp->order = (u_int32_t)uinttmp;
02087 bp += sizeof(uinttmp);
02088
02089 *argpp = argp;
02090 return (0);
02091 }
02092
02093
02094
02095
02096
02097
02098 int
02099 __ham_chgpg_log(dbp, txnid, ret_lsnp, flags, mode, old_pgno, new_pgno, old_indx, new_indx)
02100 DB *dbp;
02101 DB_TXN *txnid;
02102 DB_LSN *ret_lsnp;
02103 u_int32_t flags;
02104 db_ham_mode mode;
02105 db_pgno_t old_pgno;
02106 db_pgno_t new_pgno;
02107 u_int32_t old_indx;
02108 u_int32_t new_indx;
02109 {
02110 DBT logrec;
02111 DB_ENV *dbenv;
02112 DB_TXNLOGREC *lr;
02113 DB_LSN *lsnp, null_lsn, *rlsnp;
02114 u_int32_t uinttmp, rectype, txn_num;
02115 u_int npad;
02116 u_int8_t *bp;
02117 int is_durable, ret;
02118
02119 dbenv = dbp->dbenv;
02120 COMPQUIET(lr, NULL);
02121
02122 rectype = DB___ham_chgpg;
02123 npad = 0;
02124 rlsnp = ret_lsnp;
02125
02126 ret = 0;
02127
02128 if (LF_ISSET(DB_LOG_NOT_DURABLE) ||
02129 F_ISSET(dbp, DB_AM_NOT_DURABLE)) {
02130 is_durable = 0;
02131 } else
02132 is_durable = 1;
02133
02134 if (txnid == NULL) {
02135 txn_num = 0;
02136 lsnp = &null_lsn;
02137 null_lsn.file = null_lsn.offset = 0;
02138 } else {
02139 if (TAILQ_FIRST(&txnid->kids) != NULL &&
02140 (ret = __txn_activekids(dbenv, rectype, txnid)) != 0)
02141 return (ret);
02142
02143
02144
02145
02146
02147
02148 DB_SET_TXN_LSNP(txnid, &rlsnp, &lsnp);
02149 txn_num = txnid->txnid;
02150 }
02151
02152 DB_ASSERT(dbp->log_filename != NULL);
02153 if (dbp->log_filename->id == DB_LOGFILEID_INVALID &&
02154 (ret = __dbreg_lazy_id(dbp)) != 0)
02155 return (ret);
02156
02157 logrec.size = sizeof(rectype) + sizeof(txn_num) + sizeof(DB_LSN)
02158 + sizeof(u_int32_t)
02159 + sizeof(u_int32_t)
02160 + sizeof(u_int32_t)
02161 + sizeof(u_int32_t)
02162 + sizeof(u_int32_t)
02163 + sizeof(u_int32_t);
02164 if (CRYPTO_ON(dbenv)) {
02165 npad =
02166 ((DB_CIPHER *)dbenv->crypto_handle)->adj_size(logrec.size);
02167 logrec.size += npad;
02168 }
02169
02170 if (is_durable || txnid == NULL) {
02171 if ((ret =
02172 __os_malloc(dbenv, logrec.size, &logrec.data)) != 0)
02173 return (ret);
02174 } else {
02175 if ((ret = __os_malloc(dbenv,
02176 logrec.size + sizeof(DB_TXNLOGREC), &lr)) != 0)
02177 return (ret);
02178 #ifdef DIAGNOSTIC
02179 if ((ret =
02180 __os_malloc(dbenv, logrec.size, &logrec.data)) != 0) {
02181 __os_free(dbenv, lr);
02182 return (ret);
02183 }
02184 #else
02185 logrec.data = lr->data;
02186 #endif
02187 }
02188 if (npad > 0)
02189 memset((u_int8_t *)logrec.data + logrec.size - npad, 0, npad);
02190
02191 bp = logrec.data;
02192
02193 memcpy(bp, &rectype, sizeof(rectype));
02194 bp += sizeof(rectype);
02195
02196 memcpy(bp, &txn_num, sizeof(txn_num));
02197 bp += sizeof(txn_num);
02198
02199 memcpy(bp, lsnp, sizeof(DB_LSN));
02200 bp += sizeof(DB_LSN);
02201
02202 uinttmp = (u_int32_t)dbp->log_filename->id;
02203 memcpy(bp, &uinttmp, sizeof(uinttmp));
02204 bp += sizeof(uinttmp);
02205
02206 uinttmp = (u_int32_t)mode;
02207 memcpy(bp, &uinttmp, sizeof(uinttmp));
02208 bp += sizeof(uinttmp);
02209
02210 uinttmp = (u_int32_t)old_pgno;
02211 memcpy(bp, &uinttmp, sizeof(uinttmp));
02212 bp += sizeof(uinttmp);
02213
02214 uinttmp = (u_int32_t)new_pgno;
02215 memcpy(bp, &uinttmp, sizeof(uinttmp));
02216 bp += sizeof(uinttmp);
02217
02218 uinttmp = (u_int32_t)old_indx;
02219 memcpy(bp, &uinttmp, sizeof(uinttmp));
02220 bp += sizeof(uinttmp);
02221
02222 uinttmp = (u_int32_t)new_indx;
02223 memcpy(bp, &uinttmp, sizeof(uinttmp));
02224 bp += sizeof(uinttmp);
02225
02226 DB_ASSERT((u_int32_t)(bp - (u_int8_t *)logrec.data) <= logrec.size);
02227
02228 if (is_durable || txnid == NULL) {
02229 if ((ret = __log_put(dbenv, rlsnp,(DBT *)&logrec,
02230 flags | DB_LOG_NOCOPY)) == 0 && txnid != NULL) {
02231 *lsnp = *rlsnp;
02232 if (rlsnp != ret_lsnp)
02233 *ret_lsnp = *rlsnp;
02234 }
02235 } else {
02236 #ifdef DIAGNOSTIC
02237
02238
02239
02240
02241 memcpy(lr->data, logrec.data, logrec.size);
02242 rectype |= DB_debug_FLAG;
02243 memcpy(logrec.data, &rectype, sizeof(rectype));
02244
02245 ret = __log_put(dbenv,
02246 rlsnp, (DBT *)&logrec, flags | DB_LOG_NOCOPY);
02247 #else
02248 ret = 0;
02249 #endif
02250 STAILQ_INSERT_HEAD(&txnid->logs, lr, links);
02251 F_SET((TXN_DETAIL *)txnid->td, TXN_DTL_INMEMORY);
02252 LSN_NOT_LOGGED(*ret_lsnp);
02253 }
02254
02255 #ifdef LOG_DIAGNOSTIC
02256 if (ret != 0)
02257 (void)__ham_chgpg_print(dbenv,
02258 (DBT *)&logrec, ret_lsnp, DB_TXN_PRINT, NULL);
02259 #endif
02260
02261 #ifdef DIAGNOSTIC
02262 __os_free(dbenv, logrec.data);
02263 #else
02264 if (is_durable || txnid == NULL)
02265 __os_free(dbenv, logrec.data);
02266 #endif
02267 return (ret);
02268 }
02269
02270
02271
02272
02273 int
02274 __ham_chgpg_read(dbenv, recbuf, argpp)
02275 DB_ENV *dbenv;
02276 void *recbuf;
02277 __ham_chgpg_args **argpp;
02278 {
02279 __ham_chgpg_args *argp;
02280 u_int32_t uinttmp;
02281 u_int8_t *bp;
02282 int ret;
02283
02284 if ((ret = __os_malloc(dbenv,
02285 sizeof(__ham_chgpg_args) + sizeof(DB_TXN), &argp)) != 0)
02286 return (ret);
02287 bp = recbuf;
02288 argp->txnid = (DB_TXN *)&argp[1];
02289
02290 memcpy(&argp->type, bp, sizeof(argp->type));
02291 bp += sizeof(argp->type);
02292
02293 memcpy(&argp->txnid->txnid, bp, sizeof(argp->txnid->txnid));
02294 bp += sizeof(argp->txnid->txnid);
02295
02296 memcpy(&argp->prev_lsn, bp, sizeof(DB_LSN));
02297 bp += sizeof(DB_LSN);
02298
02299 memcpy(&uinttmp, bp, sizeof(uinttmp));
02300 argp->fileid = (int32_t)uinttmp;
02301 bp += sizeof(uinttmp);
02302
02303 memcpy(&uinttmp, bp, sizeof(uinttmp));
02304 argp->mode = (db_ham_mode)uinttmp;
02305 bp += sizeof(uinttmp);
02306
02307 memcpy(&uinttmp, bp, sizeof(uinttmp));
02308 argp->old_pgno = (db_pgno_t)uinttmp;
02309 bp += sizeof(uinttmp);
02310
02311 memcpy(&uinttmp, bp, sizeof(uinttmp));
02312 argp->new_pgno = (db_pgno_t)uinttmp;
02313 bp += sizeof(uinttmp);
02314
02315 memcpy(&uinttmp, bp, sizeof(uinttmp));
02316 argp->old_indx = (u_int32_t)uinttmp;
02317 bp += sizeof(uinttmp);
02318
02319 memcpy(&uinttmp, bp, sizeof(uinttmp));
02320 argp->new_indx = (u_int32_t)uinttmp;
02321 bp += sizeof(uinttmp);
02322
02323 *argpp = argp;
02324 return (0);
02325 }
02326
02327
02328
02329
02330
02331 int
02332 __ham_init_recover(dbenv, dtabp, dtabsizep)
02333 DB_ENV *dbenv;
02334 int (***dtabp)__P((DB_ENV *, DBT *, DB_LSN *, db_recops, void *));
02335 size_t *dtabsizep;
02336 {
02337 int ret;
02338
02339 if ((ret = __db_add_recovery(dbenv, dtabp, dtabsizep,
02340 __ham_insdel_recover, DB___ham_insdel)) != 0)
02341 return (ret);
02342 if ((ret = __db_add_recovery(dbenv, dtabp, dtabsizep,
02343 __ham_newpage_recover, DB___ham_newpage)) != 0)
02344 return (ret);
02345 if ((ret = __db_add_recovery(dbenv, dtabp, dtabsizep,
02346 __ham_splitdata_recover, DB___ham_splitdata)) != 0)
02347 return (ret);
02348 if ((ret = __db_add_recovery(dbenv, dtabp, dtabsizep,
02349 __ham_replace_recover, DB___ham_replace)) != 0)
02350 return (ret);
02351 if ((ret = __db_add_recovery(dbenv, dtabp, dtabsizep,
02352 __ham_copypage_recover, DB___ham_copypage)) != 0)
02353 return (ret);
02354 if ((ret = __db_add_recovery(dbenv, dtabp, dtabsizep,
02355 __ham_metagroup_recover, DB___ham_metagroup)) != 0)
02356 return (ret);
02357 if ((ret = __db_add_recovery(dbenv, dtabp, dtabsizep,
02358 __ham_groupalloc_recover, DB___ham_groupalloc)) != 0)
02359 return (ret);
02360 if ((ret = __db_add_recovery(dbenv, dtabp, dtabsizep,
02361 __ham_curadj_recover, DB___ham_curadj)) != 0)
02362 return (ret);
02363 if ((ret = __db_add_recovery(dbenv, dtabp, dtabsizep,
02364 __ham_chgpg_recover, DB___ham_chgpg)) != 0)
02365 return (ret);
02366 return (0);
02367 }