Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Changes In Branch multi-process Excluding Merge-Ins
This is equivalent to a diff from 3ffef65b7c to 8d149a52d3
2012-09-05
| ||
11:23 | Merge in multi-process branch. check-in: ecae27d73a user: dan tags: trunk | |
10:32 | Fix a bug in intra-process connection locking. Turn on multi-process mode by default. Leaf check-in: 8d149a52d3 user: dan tags: multi-process | |
2012-09-04
| ||
20:17 | Defer closing file descriptors until all fcntl() locks have been dropped. check-in: 3d0cf4bb36 user: dan tags: multi-process | |
2012-07-16
| ||
00:03 | Fix errors in the examples of numeric encoding on the key-encoding wiki page. check-in: 10befd97f8 user: drh tags: trunk | |
2012-07-07
| ||
19:52 | Merge trunk changes. check-in: d8523ddd93 user: dan tags: multi-process | |
12:21 | minor doc update. check-in: 3ffef65b7c user: stephan tags: trunk | |
11:44 | merged in lsm_env-xsize branch. check-in: 3dd0037efb user: stephan tags: trunk | |
Changes to lsm-test/lsmtest1.c.
︙ | |||
56 57 58 59 60 61 62 | 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 | - + + + + + + + + + + + + + + | return zRet; } static int testControlDb(TestDb **ppDb){ #ifdef HAVE_KYOTOCABINET return tdb_open("kyotocabinet", "tmp.db", 1, ppDb); #else |
︙ |
Changes to lsm-test/lsmtest5.c.
︙ | |||
522 523 524 525 526 527 528 | 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 | + - + + | } /* Open a new database connection. Initialize the pseudo-random number ** argument based on the thread number. */ iPrng = testPrngValue(iThread); pDb = testOpen(p->zSystem, 0, &rc); if( rc==0 ){ |
︙ |
Changes to lsm-test/lsmtest_main.c.
︙ | |||
169 170 171 172 173 174 175 | 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 | - + + + - + + | res = memcmp(pKey1, pKey2, MIN(nKey1, nKey2)); if( res==0 ){ res = nKey1 - nKey2; } return res; } |
︙ | |||
456 457 458 459 460 461 462 | 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 | - + | return (nFail!=0); } static lsm_db *configure_lsm_db(TestDb *pDb){ lsm_db *pLsm; pLsm = tdb_lsm(pDb); if( pLsm ){ |
︙ |
Changes to lsm-test/lsmtest_tdb3.c.
︙ | |||
308 309 310 311 312 313 314 315 316 317 318 319 320 321 | 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 | + + + + + + + + + + + + + + + + + + + + + | } static int testEnvUnlink(lsm_env *pEnv, const char *zFile){ lsm_env *pRealEnv = tdb_lsm_env(); unused_parameter(pEnv); return pRealEnv->xUnlink(pRealEnv, zFile); } static int testEnvLock(lsm_file *pFile, int iLock, int eType){ LsmFile *p = (LsmFile *)pFile; lsm_env *pRealEnv = tdb_lsm_env(); return pRealEnv->xLock(p->pReal, iLock, eType); } static int testEnvShmMap(lsm_file *pFile, int iRegion, int sz, void **pp){ LsmFile *p = (LsmFile *)pFile; lsm_env *pRealEnv = tdb_lsm_env(); return pRealEnv->xShmMap(p->pReal, iRegion, sz, pp); } static void testEnvShmBarrier(void){ } static int testEnvShmUnmap(lsm_file *pFile, int bDel){ LsmFile *p = (LsmFile *)pFile; lsm_env *pRealEnv = tdb_lsm_env(); return pRealEnv->xShmUnmap(p->pReal, bDel); } static void doSystemCrash(LsmDb *pDb){ lsm_env *pEnv = tdb_lsm_env(); int iFile; int iSeed = pDb->aFile[0].nSector + pDb->aFile[1].nSector; char *zFile = pDb->zName; |
︙ | |||
572 573 574 575 576 577 578 579 580 581 582 583 584 585 | 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 | + + | { "block_size", 0, LSM_CONFIG_BLOCK_SIZE }, { "safety", 0, LSM_CONFIG_SAFETY }, { "autowork", 0, LSM_CONFIG_AUTOWORK }, { "log_size", 0, LSM_CONFIG_LOG_SIZE }, { "mmap", 0, LSM_CONFIG_MMAP }, { "use_log", 0, LSM_CONFIG_USE_LOG }, { "nmerge", 0, LSM_CONFIG_NMERGE }, { "max_freelist", 0, LSM_CONFIG_MAX_FREELIST }, { "multi_proc", 0, LSM_CONFIG_MULTIPLE_PROCESSES }, { "worker_nmerge", 1, LSM_CONFIG_NMERGE }, { 0, 0 } }; const char *z = zStr; while( z[0] && pDb ){ const char *zStart; |
︙ | |||
691 692 693 694 695 696 697 698 699 700 701 702 703 704 | 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 | + + + + | pDb->env.xTruncate = testEnvTruncate; pDb->env.xSync = testEnvSync; pDb->env.xSectorSize = testEnvSectorSize; pDb->env.xRemap = testEnvRemap; pDb->env.xFileid = testEnvFileid; pDb->env.xClose = testEnvClose; pDb->env.xUnlink = testEnvUnlink; pDb->env.xLock = testEnvLock; pDb->env.xShmBarrier = testEnvShmBarrier; pDb->env.xShmMap = testEnvShmMap; pDb->env.xShmUnmap = testEnvShmUnmap; rc = lsm_new(&pDb->env, &pDb->db); if( rc==LSM_OK ){ lsm_config_log(pDb->db, xLog, 0); lsm_config_work_hook(pDb->db, xWorkHook, (void *)pDb); tdb_lsm_config_str((TestDb *)pDb, zCfg); rc = lsm_open(pDb->db, zFilename); |
︙ | |||
726 727 728 729 730 731 732 | 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 | + - + | } int test_lsm_lomem_open( const char *zFilename, int bClear, TestDb **ppDb ){ const char *zCfg = |
︙ |
Changes to src/build.c.
︙ | |||
1394 1395 1396 1397 1398 1399 1400 | 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 | - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + - + - - + + | zExtra = (char *)(&pIndex->zName[nName+1]); memcpy(pIndex->zName, zName, nName+1); pIndex->pTable = pTab; pIndex->nColumn = nCol; pIndex->onError = (u8)onError; pIndex->pSchema = pTab->pSchema; |
︙ | |||
2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 | 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 | + | ** in-memory database structures. */ if( db->init.busy ){ db->flags |= SQLITE4_InternChanges; if( pTblName!=0 || bPrimaryKey ){ pIndex->tnum = db->init.newTnum; } if( addIndexToHash(db, pIndex) ) goto exit_create_index; } /* If the db->init.busy is 0 then create the index on disk. This ** involves writing the index into the master table and filling in the ** index with the current table contents. ** ** The db->init.busy is 0 when the user first enters a CREATE INDEX |
︙ |
Changes to src/kvlsm.c.
︙ | |||
438 439 440 441 442 443 444 445 446 447 | 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 | + + + + + + + - + + + + + + + + + | KVLsm *pNew; int rc = SQLITE4_OK; pNew = (KVLsm *)sqlite4_malloc(pEnv, sizeof(KVLsm)); if( pNew==0 ){ rc = SQLITE4_NOMEM; }else{ struct Config { const char *zParam; int eParam; } aConfig[] = { { "lsm_block_size", LSM_CONFIG_BLOCK_SIZE } }; memset(pNew, 0, sizeof(KVLsm)); pNew->base.pStoreVfunc = &kvlsmMethods; pNew->base.pEnv = pEnv; |
︙ |
Changes to src/lsm.h.
︙ | |||
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 | 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 | + + + + + + + + + - - | /* 64-bit integer type used for file offsets. */ typedef long long int lsm_i64; /* 64-bit signed integer type */ /* Forward reference */ typedef struct lsm_env lsm_env; /* Runtime environment */ /* Candidate values for the 3rd argument to lsm_env.xLock() */ #define LSM_LOCK_UNLOCK 0 #define LSM_LOCK_SHARED 1 #define LSM_LOCK_EXCL 2 /* ** Run-time environment used by LSM */ struct lsm_env { int nByte; /* Size of this structure in bytes */ int iVersion; /* Version number of this structure */ /****** file i/o ***********************************************/ void *pVfsCtx; int (*xFullpath)(lsm_env*, const char *, char *, int *); int (*xOpen)(lsm_env*, const char *, lsm_file **); int (*xRead)(lsm_file *, lsm_i64, void *, int); int (*xWrite)(lsm_file *, lsm_i64, void *, int); int (*xTruncate)(lsm_file *, lsm_i64); int (*xSync)(lsm_file *); int (*xSectorSize)(lsm_file *); int (*xRemap)(lsm_file *, lsm_i64, void **, lsm_i64*); int (*xFileid)(lsm_file *, void *pBuf, int *pnBuf); int (*xClose)(lsm_file *); int (*xUnlink)(lsm_env*, const char *); int (*xLock)(lsm_file*, int, int); int (*xShmMap)(lsm_file*, int, int, void **); void (*xShmBarrier)(void); int (*xShmUnmap)(lsm_file*, int); /****** memory allocation ****************************************/ void *pMemCtx; void *(*xMalloc)(lsm_env*, int); /* malloc(3) function */ void *(*xRealloc)(lsm_env*, void *, int); /* realloc(3) function */ void (*xFree)(lsm_env*, void *); /* free(3) function */ |
︙ | |||
163 164 165 166 167 168 169 170 | 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 | + + + + + + + + + + + - - - - - - - - - + + + + + + + + + + + | ** LSM_CONFIG_USE_LOG ** A read/write boolean parameter. True (the default) to use the log ** file normally. False otherwise. ** ** LSM_CONFIG_NMERGE ** A read/write integer parameter. The minimum number of segments to ** merge together at a time. Default value 4. ** ** LSM_CONFIG_MAX_FREELIST ** A read/write integer parameter. The maximum number of free-list ** entries that are stored in a database checkpoint (the others are ** stored elsewhere in the database). ** ** There is no reason for an application to configure or query this ** parameter. It is only present because configuring a small value ** makes certain parts of the lsm code easier to test. ** ** LSM_CONFIG_MULTIPLE_PROCESSES */ |
︙ |
Changes to src/lsmInt.h.
︙ | |||
41 42 43 44 45 46 47 | 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 | - + + + + + + + + + + | /* ** Default values for various data structure parameters. These may be ** overridden by calls to lsm_config(). */ #define LSM_PAGE_SIZE 4096 #define LSM_BLOCK_SIZE (2 * 1024 * 1024) #define LSM_TREE_BYTES (2 * 1024 * 1024) |
︙ | |||
84 85 86 87 88 89 90 91 92 93 94 95 96 97 | 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 | + + + + + | typedef struct Tree Tree; typedef struct TreeMark TreeMark; typedef struct TreeVersion TreeVersion; typedef struct TreeCursor TreeCursor; typedef struct Merge Merge; typedef struct MergeInput MergeInput; typedef struct TreeHeader TreeHeader; typedef struct ShmHeader ShmHeader; typedef struct ShmChunk ShmChunk; typedef struct ShmReader ShmReader; typedef unsigned char u8; typedef unsigned short int u16; typedef unsigned int u32; typedef lsm_i64 i64; typedef unsigned long long int u64; /* A page number is an integer. */ |
︙ | |||
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 | 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 | + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - + + - - - - - - + + + + + + | #define LSM_NOMEM_BKPT lsmErrorBkpt(LSM_NOMEM) #define LSM_CORRUPT_BKPT lsmErrorBkpt(LSM_CORRUPT) #define LSM_MISUSE_BKPT lsmErrorBkpt(LSM_MISUSE) #define unused_parameter(x) (void)(x) #define array_size(x) (sizeof(x)/sizeof(x[0])) /* The size of each shared-memory chunk */ #define LSM_SHM_CHUNK_SIZE (32*1024) /* The number of bytes reserved at the start of each shm chunk for MM. */ #define LSM_SHM_CHUNK_HDR (3 * 4) /* The number of available read locks. */ #define LSM_LOCK_NREADER 6 /* Lock definitions */ #define LSM_LOCK_DMS1 1 #define LSM_LOCK_DMS2 2 #define LSM_LOCK_WRITER 3 #define LSM_LOCK_WORKER 4 #define LSM_LOCK_CHECKPOINTER 5 #define LSM_LOCK_READER(i) ((i) + LSM_LOCK_CHECKPOINTER + 1) /* ** Hard limit on the number of free-list entries that may be stored in ** a checkpoint (the remainder are stored as a system record in the LSM). ** See also LSM_CONFIG_MAX_FREELIST. */ #define LSM_MAX_FREELIST_ENTRIES 100 /* ** A string that can grow by appending. */ struct LsmString { lsm_env *pEnv; /* Run-time environment */ int n; /* Size of string. -1 indicates error */ int nAlloc; /* Space allocated for z[] */ char *z; /* The string content */ }; typedef struct LsmFile LsmFile; struct LsmFile { lsm_file *pFile; LsmFile *pNext; }; /* ** An instance of the following type is used to store an ordered list of ** u32 values. ** ** Note: This is a place-holder implementation. It should be replaced by ** a version that avoids making a single large allocation when the array ** contains a large number of values. For this reason, the internals of ** this object should only manipulated by the intArrayXXX() functions in ** lsm_tree.c. */ typedef struct IntArray IntArray; struct IntArray { int nAlloc; int nArray; u32 *aArray; }; /* ** An instance of this structure represents a point in the history of the |
︙ | |||
163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 | 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 | + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - + + - + + + + - + - + + + + + + + + + + + - + | struct DbLog { u32 cksum0; /* Checksum 0 at offset iOff */ u32 cksum1; /* Checksum 1 at offset iOff */ LogRegion aRegion[3]; /* Log file regions (see docs in lsm_log.c) */ }; /* ** Tree header structure. */ struct TreeHeader { u32 iTreeId; /* Current tree id */ u32 iTransId; /* Current transaction id */ u32 iRoot; /* Offset of root node in shm file */ u32 nHeight; /* Current height of tree structure */ u32 iWrite; /* Write offset in shm file */ u32 nChunk; /* Number of chunks in shared-memory file */ u32 iFirst; /* First chunk in linked list */ u32 nByte; /* Size of current tree structure in bytes */ DbLog log; /* Current layout of log file */ i64 iCkpt; /* Id of ckpt log space is reclaimed for */ u32 aCksum[2]; /* Checksums 1 and 2. */ }; /* ** Database handle structure. ** ** mLock: ** A bitmask representing the locks currently held by the connection. ** An LSM database supports N distinct locks, where N is some number less ** than or equal to 16. Locks are numbered starting from 1 (see the ** definitions for LSM_LOCK_WRITER and co.). ** ** The least significant 16-bits in mLock represent EXCLUSIVE locks. The ** most significant are SHARED locks. So, if a connection holds a SHARED ** lock on lock region iLock, then the following is true: ** ** (mLock & ((iLock+16-1) << 1)) ** ** Or for an EXCLUSIVE lock: ** ** (mLock & ((iLock-1) << 1)) */ struct lsm_db { /* Database handle configuration */ lsm_env *pEnv; /* runtime environment */ int (*xCmp)(void *, int, void *, int); /* Compare function */ |
︙ | |||
266 267 268 269 270 271 272 | 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 | + + + + + + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + + + + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - + - + + + + + + + + + + + + + + + + + + + + + + + + - - + + + + - + - + - - - - - - - - | ** The first argument to this macro is a pointer to a Segment structure. ** Returns true if the structure instance indicates that the separators ** array is valid. */ #define segmentHasSeparators(pSegment) ((pSegment)->sep.iFirst>0) /* ** The values that accompany the lock held by a database reader. */ struct ShmReader { i64 iTreeId; i64 iLsmId; }; |
︙ | |||
384 385 386 387 388 389 390 | 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 | - - + - - + + + + + + + + - + - - + | lsm_env *lsmFsEnv(FileSystem *); lsm_env *lsmPageEnv(Page *); FileSystem *lsmPageFS(Page *); int lsmFsSectorSize(FileSystem *); void lsmSortedSplitkey(lsm_db *, Level *, int *); |
︙ | |||
496 497 498 499 500 501 502 | 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 | - + - + - + + - + - + + + - - - - - - - - - - + - - - - + + - - - + + + + + + + + + + - + + + + - + + + + + + + + + + + + + | */ void lsmLogMessage(lsm_db *, int, const char *, ...); int lsmFlushToDisk(lsm_db *); /* ** Functions from file "lsm_log.c". */ |
︙ |
Changes to src/lsm_ckpt.c.
︙ | |||
32 33 34 35 36 37 38 | 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 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 | - + - + + + + + - + - + - - - - - + + + + + - - - + + + - - - + - - - - - + + + - - - - + + + + + + + + + + + + + + + + + + + + + - - - + + + + + + + - - - - + + + + + - - + + + - + + + + + - - - - - + + + + + + - - - - - - - - - + - - - + - - - - - + - - - + - - - - - - - + + - - - - - - - - + - - + - - - - - - - - - + - - - - + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + - + + + + + + - + - - | ** 2. The checkpoint id LSW. ** 3. The number of integer values in the entire checkpoint, including ** the two checksum values. ** 4. The total number of blocks in the database. ** 5. The block size. ** 6. The number of levels. ** 7. The nominal database page size. |
︙ | |||
248 249 250 251 252 253 254 | 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 | - - - - + + + + | ckptSetValue(p, iOut++, pSeg->iRoot, pRc); ckptSetValue(p, iOut++, pSeg->nSize, pRc); *piOut = iOut; } static void ckptExportLevel( |
︙ | |||
284 285 286 287 288 289 290 | 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 | - + - + + + + + + + - + + + + + - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + - + - - - - - - + - - - - - - - - - - - - - - - - - - - - - + + - - - + + - + - - - + + + + + + + + + + + - - + + - + - - - + - + - + - - - - - + + + + - - - - - - + - - + - - - + - + - + + + + + + + | ckptSetValue(p, iOut++, pMerge->splitkey.iCell, pRc); } *piOut = iOut; } /* |
︙ | |||
523 524 525 526 527 528 529 | 557 558 559 560 561 562 563 564 565 566 567 568 569 570 | - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | } *ppLevel = pRet; *piIn = iIn; return rc; } |
︙ | |||
625 626 627 628 629 630 631 | 591 592 593 594 595 596 597 598 599 600 601 602 603 604 | - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | } } } return rc; } |
︙ | |||
769 770 771 772 773 774 775 | 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 | - + - - - - - + + - - - + + - + + + + - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - + + + + + + + + + + + + + + + + + + + + + + + - + + + + + + + + + + + + + + + + + + + + + + - - - + + + - - - - - - - + - - - + - - + - - - - - - + + + - - - + - - - - - - - - + + + + - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + - - + + + + + + + + + | *paVal = 0; } return rc; } /* |
Changes to src/lsm_file.c.
︙ | |||
29 30 31 32 33 34 35 | 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 | - + + - + | ** exist - since it would always overlap with the meta pages. If the ** page-size is (say) 512 bytes, then the first usable page in the database ** is page 33. ** ** It is assumed that the first two meta pages and the data that follows ** them are located on different disk sectors. So that if a power failure ** while writing to a meta page there is no risk of damage to the other |
︙ | |||
73 74 75 76 77 78 79 80 81 82 83 84 85 86 | 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 | + | ** THE LOG FILE ** ** This file opens and closes the log file. But it does not contain any ** logic related to the log file format. Instead, it exports the following ** functions that are used by the code in lsm_log.c to read and write the ** log file: ** ** lsmFsOpenLog ** lsmFsWriteLog ** lsmFsSyncLog ** lsmFsReadLog ** lsmFsTruncateLog ** lsmFsCloseAndDeleteLog ** */ |
︙ | |||
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 | 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 | + + | ** ** In non-mmap() mode, this list is an LRU list of cached pages with nRef==0. */ struct FileSystem { lsm_db *pDb; /* Database handle that owns this object */ lsm_env *pEnv; /* Environment pointer */ char *zDb; /* Database file name */ char *zLog; /* Database file name */ int nMetasize; /* Size of meta pages in bytes */ int nPagesize; /* Database page-size in bytes */ int nBlocksize; /* Database block-size in bytes */ /* r/w file descriptors for both files. */ LsmFile *pLsmFile; lsm_file *fdDb; /* Database file */ lsm_file *fdLog; /* Log file */ /* mmap() mode things */ int bUseMmap; /* True to use mmap() to access db file */ void *pMap; /* Current mapping of database file */ i64 nMap; /* Bytes mapped at pMap */ |
︙ | |||
189 190 191 192 193 194 195 | 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 | - + | ** lsmEnvSync() ** lsmEnvSectorSize() ** lsmEnvClose() ** lsmEnvTruncate() ** lsmEnvUnlink() ** lsmEnvRemap() */ |
︙ | |||
216 217 218 219 220 221 222 | 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 | - + + + + + + + + + + + + + + + + + + + + + + + + + + + - - + + + | } static int lsmEnvSync(lsm_env *pEnv, lsm_file *pFile){ return pEnv->xSync(pFile); } static int lsmEnvSectorSize(lsm_env *pEnv, lsm_file *pFile){ return pEnv->xSectorSize(pFile); } |
︙ | |||
308 309 310 311 312 313 314 | 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 | - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + - + + + - - - + + + + + - + - | static lsm_file *fsOpenFile( FileSystem *pFS, /* File system object */ int bLog, /* True for log, false for db */ int *pRc /* IN/OUT: Error code */ ){ lsm_file *pFile = 0; if( *pRc==LSM_OK ){ |
︙ | |||
381 382 383 384 385 386 387 | 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 | + + + + + - - - + + + + + | Page *pNext = pPg->pLruNext; if( pPg->flags & PAGE_FREE ) lsmFree(pEnv, pPg->aData); lsmFree(pEnv, pPg); pPg = pNext; } if( pFS->fdDb ) lsmEnvClose(pFS->pEnv, pFS->fdDb ); if( pFS->fdLog ){ if( lsmDbMultiProc(pFS->pDb) ){ lsmDbDeferredClose(pFS->pDb, pFS->fdLog, pFS->pLsmFile); pFS->pLsmFile = 0; }else{ |
︙ | |||
623 624 625 626 627 628 629 630 631 632 633 634 635 | 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 | + - | FileSystem *pFS, i64 iSz, int *pRc ){ if( *pRc==LSM_OK && iSz>pFS->nMap ){ Page *pFix; int rc; u8 *aOld = pFS->pMap; rc = lsmEnvRemap(pFS->pEnv, pFS->fdDb, iSz, &pFS->pMap, &pFS->nMap); if( rc==LSM_OK ){ u8 *aData = (u8 *)pFS->pMap; for(pFix=pFS->pLruFirst; pFix; pFix=pFix->pLruNext){ pFix->aData = &aData[pFS->nPagesize * (i64)(pFix->iPg-1)]; } |
︙ | |||
779 780 781 782 783 784 785 | 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 | - - - + + + - - - + + - - + + | Snapshot *pSnapshot, Segment *pIgnore, /* Ignore this run when searching */ int iBlk ){ int rc = LSM_OK; /* Return code */ int iFirst; /* First page on block iBlk */ int iLast; /* Last page on block iBlk */ |
︙ | |||
931 932 933 934 935 936 937 | 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 | - + - - - - + - - - - - - - - - - + - - - + - - + - - - + - - - - - - - - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + - + | iPg++; } } return fsPageGet(pFS, iPg, 0, ppNext); } |
︙ | |||
1131 1132 1133 1134 1135 1136 1137 | 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 | + + + + - + + + + | if( rc==LSM_OK ){ int iPg = (int)lsmGetU32(&pLast->aData[pFS->nPagesize-4]); int iBlk = fsPageToBlock(pFS, iPg); lsmBlockRefree(pFS->pDb, iBlk); lsmFsPageRelease(pLast); } }else{ int i; u32 *aiAppend = pFS->pDb->pWorker->aiAppend; for(i=0; i<LSM_APPLIST_SZ; i++){ if( aiAppend[i]==0 ){ |
︙ | |||
1399 1400 1401 1402 1403 1404 1405 | 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 | - + + + - + + | ** eventually free the string using lsmFree(). ** ** If an error occurs, *pzOut is set to NULL and an LSM error code returned. */ int lsmInfoArrayStructure(lsm_db *pDb, Pgno iFirst, char **pzOut){ int rc = LSM_OK; Snapshot *pWorker; /* Worker snapshot */ |
︙ | |||
1447 1448 1449 1450 1451 1452 1453 | 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 | + + - + + - - - + + + - - - - - - + + - - - - + + + + - - - - - - - - - - + + + + + + + + + + - - - + + + - - - + - - + + + + + - - - - + + + + + + + + + - + - - + - - - - - - - - - + + + + + + + + + + + + + + + + + + - | lsmStringAppendf(&str, " %d", fsFirstPageOnBlock(pFS, iBlk)); } lsmStringAppendf(&str, " %d", pArray->iLast); *pzOut = str.z; } if( bUnlock ){ int rcwork = LSM_BUSY; |
Changes to src/lsm_log.c.
︙ | |||
300 301 302 303 304 305 306 | 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 | - + - - + | ** is assumed that the caller is holding the client-mutex when it is ** called. ** ** Before returning, this function allocates the LogWriter object that ** will be used to write to the log file during the write transaction. ** LSM_OK is returned if no error occurs, otherwise an LSM error code. */ |
︙ | |||
342 343 344 345 346 347 348 | 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 | - + - - + + | ** ** 2) Region 1 is zero bytes in size and region 2 occurs earlier in the ** file than region 0. In this case, append data to region 2, but ** remember to jump over region 1 if required. ** ** 3) Region 2 is the last in the file. Append to it. */ |
︙ | |||
399 400 401 402 403 404 405 | 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 | - + + - + | ** or false otherwise. The caller must hold the client-mutex to call ** this function. ** ** A call to this function deletes the LogWriter object allocated by ** lsmLogBegin(). If the transaction is being committed, the shared state ** in *pLog is updated before returning. */ |
︙ | |||
432 433 434 435 436 437 438 | 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 | - + + - | /* ** This function is called after a checkpoint is synced into the database ** file. The checkpoint specifies that the log starts at offset iOff. ** The shared state in *pLog is updated to reflect the fact that space ** in the log file that occurs logically before offset iOff may now ** be reused. */ |
︙ | |||
723 724 725 726 727 728 729 | 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 | - + | if( pMark->iOff > pLog->iRegion2Start ) pLog->iRegion2Start = 0; } /* ** TODO: Thread safety of this function? */ int lsmLogStructure(lsm_db *pDb, char **pzVal){ |
︙ | |||
885 886 887 888 889 890 891 | 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 | - + - + + + + - + | /* ** Recover the contents of the log file. */ int lsmLogRecover(lsm_db *pDb){ LsmString buf1; /* Key buffer */ LsmString buf2; /* Value buffer */ LogReader reader; /* Log reader object */ |
︙ | |||
1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 | 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 | + | if( rc==LSM_OK && iPass==0 ){ if( nCommit==0 ){ if( pLog->aRegion[2].iStart==0 ){ iPass = 1; }else{ pLog->aRegion[2].iStart = 0; iPass = -1; lsmCheckpointZeroLogoffset(pDb); } } logReaderInit(pDb, pLog, 0, &reader); nCommit = nCommit * -1; } } |
︙ |
Changes to src/lsm_main.c.
︙ | |||
37 38 39 40 41 42 43 | 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 | - - - | /* If there is at least one cursor or a write transaction open, the database ** handle must be holding a pointer to a client snapshot. And the reverse ** - if there are no open cursors and no write transactions then there must ** not be a client snapshot. */ assert( (pDb->pCsr!=0 || pDb->nTransOpen>0)==(pDb->pClient!=0) ); |
︙ | |||
80 81 82 83 84 85 86 87 | 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 | + - + + - - - - - - - - - - - - - - - - - - - - - + + - - + + - - - - - - - - - - - - - - - - - + - - - + - - - + - - - - - + - - - - - + - - - - + - - - - - - - - - - - - - - | pDb->bAutowork = 1; pDb->eSafety = LSM_SAFETY_NORMAL; pDb->xCmp = xCmp; pDb->nLogSz = LSM_DEFAULT_LOG_SIZE; pDb->nDfltPgsz = LSM_PAGE_SIZE; pDb->nDfltBlksz = LSM_BLOCK_SIZE; pDb->nMerge = LSM_DEFAULT_NMERGE; pDb->nMaxFreelist = LSM_MAX_FREELIST_ENTRIES; pDb->bUseLog = 1; |
︙ | |||
234 235 236 237 238 239 240 | 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 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 | - + - + - + + + + + - + - + + - + - - + + - - - + + + + + - + - - - + + + + + + + - - - - - + + + + + + - - - + + + - - - + - - - - | ** than one purpose - to open both the database and log files, and ** perhaps to unlink the log file during disconnection. An absolute ** path is required to ensure that the correct files are operated ** on even if the application changes the cwd. */ rc = getFullpathname(pDb->pEnv, zFilename, &zFull); assert( rc==LSM_OK || zFull==0 ); |
︙ | |||
419 420 421 422 423 424 425 426 427 428 429 430 431 432 | 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 | + + + + + + + + + + + + + + + + + + + + + + | case LSM_CONFIG_NMERGE: { int *piVal = va_arg(ap, int *); if( *piVal>1 ) pDb->nMerge = *piVal; *piVal = pDb->nMerge; break; } case LSM_CONFIG_MAX_FREELIST: { int *piVal = va_arg(ap, int *); if( *piVal>=2 && *piVal<=LSM_MAX_FREELIST_ENTRIES ){ pDb->nMaxFreelist = *piVal; } *piVal = pDb->nMaxFreelist; break; } case LSM_CONFIG_MULTIPLE_PROCESSES: { int *piVal = va_arg(ap, int *); if( pDb->pDatabase ){ /* If lsm_open() has been called, this is a read-only parameter. ** Set the output variable to true if this connection is currently ** in multi-process mode. */ *piVal = lsmDbMultiProc(pDb); }else{ pDb->bMultiProc = *piVal = (*piVal!=0); } break; } default: rc = LSM_MISUSE; break; } va_end(ap); |
︙ | |||
444 445 446 447 448 449 450 | 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 | - + + + - + + + + - + + | char **pzOut /* OUT: Nul-terminated string (tcl list) */ ){ Level *pTopLevel = 0; /* Top level of snapshot to report on */ int rc = LSM_OK; Level *p; LsmString s; Snapshot *pWorker; /* Worker snapshot */ |
︙ | |||
543 544 545 546 547 548 549 | 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 | - - + - + - | if( pDb->nTransOpen==0 ){ bCommit = 1; rc = lsm_begin(pDb, 1); } if( rc==LSM_OK ){ |
︙ | |||
737 738 739 740 741 742 743 | 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 | - + + + - + + + + + + + | if( rc==LSM_OK && pDb->nTransOpen==0 ){ rc = lsmBeginWriteTrans(pDb); } if( rc==LSM_OK ){ for(i=pDb->nTransOpen; i<iLevel; i++){ |
︙ |
Changes to src/lsm_mem.c.
︙ | |||
105 106 107 108 109 110 111 | 105 106 107 108 109 110 111 112 113 114 115 116 117 118 | - | lsmFree(pEnv, p); }else{ pRet = lsmReallocOrFree(pEnv, p, N); if( !pRet ) *pRc = LSM_NOMEM_BKPT; } return pRet; } |
︙ |
Changes to src/lsm_shared.c.
︙ | |||
11 12 13 14 15 16 17 | 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 | - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + - - - - - - + + - - - - - - + - - - + + - - + - - - + - - - - - + - - + - - - - - - - - + | ************************************************************************* ** ** Utilities used to help multiple LSM clients to coexist within the ** same process space. */ #include "lsmInt.h" |
︙ | |||
225 226 227 228 229 230 231 | 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 | - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + | } static void assertNotInFreelist(Freelist *p, int iBlk){ int i; for(i=0; i<p->nEntry; i++){ assert( p->aEntry[i].iBlk!=iBlk ); } } |
︙ | |||
312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 | 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 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 | + + + + + + + + + + + + - + + + + - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + | /* Append the new entry to the freelist */ p->aEntry[p->nEntry].iBlk = iBlk; p->aEntry[p->nEntry].iId = iId; p->nEntry++; return LSM_OK; } static int flInsertEntry(lsm_env *pEnv, Freelist *p, int iBlk){ int rc; rc = lsmFreelistAppend(pEnv, p, iBlk, 1); if( rc==LSM_OK ){ memmove(&p->aEntry[1], &p->aEntry[0], sizeof(FreelistEntry)*(p->nEntry-1)); p->aEntry[0].iBlk = iBlk; p->aEntry[0].iId = 1; } return rc; } /* ** Remove the first entry of the free-list. */ static void flRemoveEntry0(Freelist *p){ int nNew = p->nEntry - 1; assert( nNew>=0 ); memmove(&p->aEntry[0], &p->aEntry[1], sizeof(FreelistEntry) * nNew); p->nEntry = nNew; } /* |
︙ | |||
380 381 382 383 384 385 386 | 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 | - - - - - - - - - + + + - + - - - - + + + + + + + + + + + + + + - - - + + - - - + - - - - - - - + + + - - - + + + + + + + + + + + + + + - - - + - - - + - - - + - - - - - - + + + + + - - + - - + - - - + - - - - - + + + - - - - - - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + - + - - + + + - + - - - + - - - + - - - - + - + - - + + - - - - - + - + + - + - - - - - - + + - - - + - - - + + - - + - - + - - - - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + - - - - - - - - - - - - - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + - - - + + + - - - + - - - - - - - - - - + + + + + + - - + - - + + - - - - - + + + + + + + + + + + + - - - + + - - - - - - - - - - - - + + + + + + + + + + + + + + + - - - - - - + + - - - - - + + + + + + + + + + + - - - - - - - - - - + + + + + + + + + + - - - - - + + + + - - - + - - + - - + + - - - - + + + + + + - - - + + + - - - - + + + - - - + + - - - - - + - + - - - - - - - + + + + + + + + + - - - - + + + - - - + - - + - - - - - + - - + + + - - - + - - + - - - + + + + + + + + + + + + + + + + + + + + + + - - - - + + + + + + - - - - - - + + + - + - + + - - - + - + - - - - - + + - - - + + + + + + - - + + + + + + + + + + - - - + + + - - - - + + - - - - - + - - - - + + - - - - - - - - - - - - - - - - + - - + + + - + + + + + - - - - - - - - - - + - - - - - + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + | } /* If no suitable Database object was found, allocate a new one. */ if( p==0 ){ int nName = strlen(zName); p = (Database *)lsmMallocZeroRc(pEnv, sizeof(Database)+nId+nName+1, &rc); |
Changes to src/lsm_sorted.c.
︙ | |||
260 261 262 263 264 265 266 | 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 | - + | int nTree; int *aTree; BtreeCursor *pBtCsr; Snapshot *pSnap; /* Used by cursors flushing the in-memory tree only */ |
︙ | |||
284 285 286 287 288 289 290 | 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 | - - - - - | ** flushing the in-memory tree to disk - the new free-list and levels record ** are flushed along with it. ** ** CURSOR_AT_FREELIST ** This flag is set when sub-cursor CURSOR_DATA_SYSTEM is actually ** pointing at a free list. ** |
︙ | |||
483 484 485 486 487 488 489 490 491 492 493 494 495 496 | 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 | + + + + + + + + + | static int pageGetFlags(u8 *aData, int nData){ return (int)lsmGetU16(&aData[SEGMENT_FLAGS_OFFSET(nData)]); } static u8 *pageGetCell(u8 *aData, int nData, int iCell){ return &aData[lsmGetU16(&aData[SEGMENT_CELLPTR_OFFSET(nData, iCell)])]; } /* ** Return the number of cells on page pPg. */ static int pageObjGetNRec(Page *pPg){ int nData; u8 *aData = lsmFsPageData(pPg, &nData); return pageGetNRec(aData, nData); } /* ** Return the decoded (possibly relative) pointer value stored in cell ** iCell from page aData/nData. */ static int pageGetRecordPtr(u8 *aData, int nData, int iCell){ int iRet; /* Return value */ |
︙ | |||
565 566 567 568 569 570 571 572 573 574 575 576 577 578 | 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 | + | u8 *aData; int nData; u8 *aCell; int eType; aData = fsPageData(pPg, &nData); assert( SEGMENT_BTREE_FLAG & pageGetFlags(aData, nData) ); assert( iKey>=0 && iKey<pageGetNRec(aData, nData) ); aCell = pageGetCell(aData, nData, iKey); eType = *aCell++; aCell += lsmVarintGet32(aCell, piPtr); if( eType==0 ){ int rc; |
︙ | |||
597 598 599 600 601 602 603 | 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 | + + + + - - - - - - + + + + + + + + + + + | static int btreeCursorLoadKey(BtreeCursor *pCsr){ int rc = LSM_OK; if( pCsr->iPg<0 ){ pCsr->pKey = 0; pCsr->nKey = 0; pCsr->eType = 0; }else{ int iPg; for(iPg=pCsr->iPg; iPg>=0; iPg--){ int iCell = pCsr->aPg[pCsr->iPg].iCell; if( iCell>=0 ){ |
︙ | |||
822 823 824 825 826 827 828 | 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 | - + - - - - + + + + + + + + + + + + + + | /* Populate any other aPg[] array entries */ if( rc==LSM_OK && nDepth>1 ){ Blob blob = {0,0,0}; void *pSeek; int nSeek; int iTopicSeek; int dummy; |
︙ | |||
1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 | 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 | + + + + | pCsr->aPtr[0].pSeg = &pLevel->lhs; pCsr->nPtr = nPtr; for(i=0; i<pLevel->nRight; i++){ pCsr->aPtr[i+1].pSeg = &pLevel->aRhs[i]; } } if( nPtr>1 && pLevel->pSplitKey==0 ){ lsmSortedSplitkey(pDb, pLevel, &rc); } return rc; } static int levelCursorInitRun( lsm_db *pDb, Segment *pSeg, |
︙ | |||
1539 1540 1541 1542 1543 1544 1545 | 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 | + + - - + + | ){ int iRet; if( pLeft->pPg==0 ){ iRet = 1; }else if( pRight->pPg==0 ){ iRet = 0; }else{ int res = rtTopic(pLeft->eType) - rtTopic(pRight->eType); if( res==0 ){ |
︙ | |||
1971 1972 1973 1974 1975 1976 1977 | 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 | - | pCsr->pNext = pDb->pCsr; pDb->pCsr = pCsr; } } if( rc==LSM_OK ){ if( useTree ){ |
︙ | |||
2024 2025 2026 2027 2028 2029 2030 | 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 | - + + | } /* ** If the free-block list is not empty, then have this cursor visit a key ** with (a) the system bit set, and (b) the key "F" and (c) a value blob ** containing the entire serialized free-block list. */ |
︙ | |||
2114 2115 2116 2117 2118 2119 2120 | 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 | - - - - - | case CURSOR_DATA_SYSTEM: if( pCsr->flags & CURSOR_AT_FREELIST ){ pKey = (void *)"FREELIST"; nKey = 8; eType = SORTED_SYSTEM_WRITE; } |
︙ | |||
2156 2157 2158 2159 2160 2161 2162 | 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 | - + + - - - + + + - - - - - - + + + + + - - - - + - - - - - - - - - - - - + + + + - - - + + - - + + + + + | lsmTreeCursorValue(pCsr->pTreeCsr, ppVal, pnVal); }else{ *ppVal = 0; *pnVal = 0; } }else if( iVal==CURSOR_DATA_SYSTEM ){ if( pCsr->flags & CURSOR_AT_FREELIST ){ |
︙ | |||
2423 2424 2425 2426 2427 2428 2429 | 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 | - | int iPtr = 0; if( eESeek==LSM_SEEK_LEFAST ) eESeek = LSM_SEEK_LE; assert( eESeek==LSM_SEEK_EQ || eESeek==LSM_SEEK_LE || eESeek==LSM_SEEK_GE ); assert( (pCsr->flags & CURSOR_NEW_SYSTEM)==0 ); assert( (pCsr->flags & CURSOR_AT_FREELIST)==0 ); |
︙ | |||
2552 2553 2554 2555 2556 2557 2558 | 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 | - + - - - + - - - - | if( iKey==CURSOR_DATA_TREE ){ if( bReverse ){ rc = lsmTreeCursorPrev(pCsr->pTreeCsr); }else{ rc = lsmTreeCursorNext(pCsr->pTreeCsr); } }else if( iKey==CURSOR_DATA_SYSTEM ){ |
︙ | |||
3439 3440 3441 3442 3443 3444 3445 3446 3447 3448 3449 3450 3451 3452 3453 3454 3455 3456 3457 | 3448 3449 3450 3451 3452 3453 3454 3455 3456 3457 3458 3459 3460 3461 3462 3463 3464 3465 3466 3467 3468 3469 3470 3471 3472 3473 3474 3475 3476 3477 3478 3479 3480 3481 3482 3483 3484 3485 3486 3487 3488 3489 3490 3491 3492 3493 3494 3495 3496 3497 3498 3499 3500 3501 3502 3503 3504 3505 3506 3507 3508 3509 3510 3511 3512 3513 3514 3515 3516 3517 3518 3519 3520 3521 3522 3523 | + - + - - + + + + - - - - + + + + + - - - - + - - | static int mergeWorkerDone(MergeWorker *pMW){ return pMW->pCsr==0 || !lsmMCursorValid(pMW->pCsr); } static void sortedFreeLevel(lsm_env *pEnv, Level *p){ if( p ){ lsmFree(pEnv, p->pSplitKey); lsmFree(pEnv, p->pMerge); lsmFree(pEnv, p->aRhs); lsmFree(pEnv, p); } } static void sortedInvokeWorkHook(lsm_db *pDb){ if( pDb->xWork ){ pDb->xWork(pDb, pDb->pWorkCtx); } } |
︙ | |||
3534 3535 3536 3537 3538 3539 3540 | 3542 3543 3544 3545 3546 3547 3548 3549 3550 3551 3552 3553 3554 3555 | - | while( rc==LSM_OK && mergeWorkerDone(&mergeworker)==0 ){ rc = mergeWorkerStep(&mergeworker); } mergeWorkerShutdown(&mergeworker, &rc); pNew->pMerge = 0; } |
︙ | |||
3569 3570 3571 3572 3573 3574 3575 | 3576 3577 3578 3579 3580 3581 3582 3583 3584 3585 3586 3587 3588 3589 3590 3591 3592 3593 3594 3595 3596 3597 3598 3599 3600 3601 3602 3603 3604 3605 3606 3607 | - + - - - - - - + + - - - + + - - + - - + - - - - | ** ** In both cases, the connection hold a worker snapshot reference. In ** the first, the connection also holds the in-memory tree write-version. ** In the second, no in-memory tree version reference is held at all. */ int lsmSortedFlushTree( lsm_db *pDb, /* Connection handle */ |
︙ | |||
3641 3642 3643 3644 3645 3646 3647 | 3637 3638 3639 3640 3641 3642 3643 3644 3645 3646 3647 3648 3649 3650 3651 | - + | Level *p = pLevel; Level **pp; pNew->nRight = nMerge; pNew->iAge = pLevel->iAge+1; for(i=0; i<nMerge; i++){ pNext = p->pNext; pNew->aRhs[i] = p->lhs; |
︙ | |||
3796 3797 3798 3799 3800 3801 3802 | 3792 3793 3794 3795 3796 3797 3798 3799 3800 3801 3802 3803 3804 3805 | - | int nRemaining = nWork; /* Units of work to do before returning */ Snapshot *pWorker = pDb->pWorker; assert( lsmFsIntegrityCheck(pDb) ); assert( pWorker ); if( lsmDbSnapshotLevel(pWorker)==0 ) return LSM_OK; |
︙ | |||
3937 3938 3939 3940 3941 3942 3943 | 3932 3933 3934 3935 3936 3937 3938 3939 3940 3941 3942 3943 3944 3945 3946 | - + | /* Clean up the MergeWorker object initialized above. If no error ** has occurred, invoke the work-hook to inform the application that ** the database structure has changed. */ mergeWorkerShutdown(&mergeworker, &rc); if( rc==LSM_OK ) sortedInvokeWorkHook(pDb); #if 0 |
︙ | |||
4034 4035 4036 4037 4038 4039 4040 | 4029 4030 4031 4032 4033 4034 4035 4036 4037 4038 4039 4040 4041 4042 4043 4044 4045 4046 4047 4048 4049 4050 4051 4052 4053 4054 4055 4056 4057 4058 4059 4060 4061 4062 4063 4064 4065 4066 4067 4068 4069 4070 4071 4072 4073 4074 4075 4076 4077 4078 4079 4080 4081 4082 | - + - - + + - + + + - - - + + + + + - - - - + - - - - - - + + + + + + + + + + + + + | /* ** Perform work to merge database segments together. */ int lsm_work(lsm_db *pDb, int flags, int nPage, int *pnWrite){ int rc = LSM_OK; /* Return code */ /* This function may not be called if pDb has an open read or write |
︙ | |||
4272 4273 4274 4275 4276 4277 4278 4279 4280 4281 4282 4283 4284 4285 | 4275 4276 4277 4278 4279 4280 4281 4282 4283 4284 4285 4286 4287 4288 4289 4290 4291 4292 4293 4294 4295 4296 4297 4298 4299 4300 4301 4302 4303 | + + + + - + + + | int lsmInfoPageDump(lsm_db *pDb, Pgno iPg, int bHex, char **pzOut){ int rc = LSM_OK; /* Return code */ Snapshot *pWorker; /* Worker snapshot */ Snapshot *pRelease = 0; /* Snapshot to release */ Page *pPg = 0; /* Handle for page iPg */ int i, j; /* Loop counters */ const int perLine = 16; /* Bytes per line in the raw hex dump */ int bEndWork = 0; *pzOut = 0; if( iPg==0 ) return LSM_ERROR; /* Obtain the worker snapshot */ #if 0 pWorker = pDb->pWorker; if( !pWorker ){ rc = lsmBeginWork(pDb); if( rc!=LSM_OK ) return rc; |
︙ | |||
4369 4370 4371 4372 4373 4374 4375 | 4378 4379 4380 4381 4382 4383 4384 4385 4386 4387 4388 4389 4390 4391 | - | } *pzOut = str.z; sortedBlobFree(&blob); lsmFsPageRelease(pPg); } |
︙ | |||
4408 4409 4410 4411 4412 4413 4414 | 4416 4417 4418 4419 4420 4421 4422 4423 4424 4425 4426 4427 4428 4429 4430 | - - + - - - | int bKeys, /* Output the keys from each segment */ int bVals, /* Output the values from each segment */ const char *zWhy /* Caption to print near top of dump */ ){ Snapshot *pDump = pSnap; Level *pTopLevel; |
︙ | |||
4479 4480 4481 4482 4483 4484 4485 | 4483 4484 4485 4486 4487 4488 4489 4490 4491 4492 4493 4494 4495 4496 | - - - - | sortedDumpSegment(pDb, &pLevel->lhs, bVals); for(i=0; i<pLevel->nRight; i++){ sortedDumpSegment(pDb, &pLevel->aRhs[i], bVals); } } } } |
︙ |
Changes to src/lsm_tree.c.
︙ | |||
46 47 48 49 50 51 52 | 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 | - + | ** ** To reduce this overhead, the data structure used for a tree node is ** designed so that it may be edited in place exactly once without ** affecting existing users. In other words, the node structure is capable ** of storing two separate versions of the node at the same time. ** When a node is to be edited, if the node structure already contains ** two versions, a copy is made as in the append-only approach. Or, if |
︙ | |||
91 92 93 94 95 96 97 | 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 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 | - + + + + + - - + + + - + - + + - - - + + + - - + - - - - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + - - - - - + - - - - - + - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + | typedef struct TreeKey TreeKey; typedef struct TreeNode TreeNode; typedef struct TreeLeaf TreeLeaf; typedef struct NodeVersion NodeVersion; /* |
︙ | |||
243 244 245 246 247 248 249 250 251 | 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 | + + + + + + + + - + + + + - - + + + + + + - - - + + + - - - - - + - - - - - - - + - - + - - - + + - - - - - - + + - - + - - - - - - - - - - - - - + - - + - - - + - - + - - - - - - - + + + - - - + - - - - - - - - - + + + + - - - - + + + + - - + + - - - - - - + - - + - - + - - + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + - - - - + - - - - + - - - - - + + + - - + - - - - - + + - + + - + + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + - - + + + - + + + - + - + - - - - - - - + + + + + + + + - + + - + - + + + + + - + - - - - + + + - - - - + + + + + + + - - + + + + + + + + + + + - + - + - - - + - - + - - - - + - - - - - + + - - - - - - - - - - - - + + - - - + + + - - - + + + - - - + + + - - - + + + - - + + + + + - - - - - + + + + + - - - - - - + + + + + + - - + + - - - - - - - - - - - - - + + + + + + + + + + + + + + + + - - - + + - - - - - + - + - + - + + - + - - + + - - - - - - - + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - + + + - + - + + - + - - + - - - - - - - - + - - - - + - + - - - - + + - - - - - - + + + + - - + + - + + - - + + - - - - + + + + + - + - + + + - + + - + - - - + - - - - - - - - - + - + + - - - - + + + - + - - - + + + + + + - - + + + + - + + + - - + + + - + + - + - - + + - + - + + - + - + + - - - + + + - + + - + + - + + - + - + - + - + - - - + + - + + - - - + + + - + + - + + - + + + - + - + - + - - - + + - + - - + + + + + + - + + + + + + - + - + - - - + + - + - + + - + + + - + - - - - + + + + + + - + - + - - - + + + + + + + + + - + + + + + + + + + + + + + + + + - - - - + + + + + - - - - - + + - - - - - + - - - + + + - - - - + + + - - - + - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - + + - - - - - + + + + + + - - + - - - + + - + - - + - - - + + + - - + - - - + - - - - - - - - + + + + + - - + + - - - - + + + + + - - - - + + + + + - - + + - + - - - - - - + + + - - + + + - - + + - - - + - - + + + + + + + - + - - - - - - - + + + + + + - - - + - - - - + + - + - - - - - - + + + + + + + + - - - - + + - - - - - - - - - - + + + + - - + - + - - - + - - + - - - - + + | } } #else # define assert_tree_looks_ok(x,y) #endif #ifdef LSM_DEBUG /* ** Pointer pBlob points to a buffer containing a blob of binary data ** nBlob bytes long. Append the contents of this blob to *pStr, with ** each octet represented by a 2-digit hexadecimal number. For example, ** if the input blob is three bytes in size and contains {0x01, 0x44, 0xFF}, ** then "0144ff" is appended to *pStr. */ static void lsmAppendStrBlob(LsmString *pStr, void *pBlob, int nBlob){ int i; |
Changes to src/lsm_unix.c.
︙ | |||
32 33 34 35 36 37 38 | 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 | - - - - - + + + + + + + + + + + + + + + + + + + + | #include <stdio.h> #include <ctype.h> #include <unistd.h> #include <errno.h> #include <sys/mman.h> |
︙ | |||
260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 | 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 | + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - | prc = fstat(p->fd, &buf); if( prc!=0 ) return LSM_IOERR_BKPT; memcpy(pBuf, &buf.st_dev, sizeof(buf.st_dev)); memcpy(&(((u8 *)pBuf)[sizeof(buf.st_dev)]), &buf.st_ino, sizeof(buf.st_ino)); return LSM_OK; } static int lsmPosixOsUnlink(lsm_env *pEnv, const char *zFile){ int prc = unlink(zFile); return prc ? LSM_IOERR_BKPT : LSM_OK; } int lsmPosixOsLock(lsm_file *pFile, int iLock, int eType){ int rc = LSM_OK; PosixFile *p = (PosixFile *)pFile; static const short aType[3] = { F_UNLCK, F_RDLCK, F_WRLCK }; struct flock lock; assert( aType[LSM_LOCK_UNLOCK]==F_UNLCK ); assert( aType[LSM_LOCK_SHARED]==F_RDLCK ); assert( aType[LSM_LOCK_EXCL]==F_WRLCK ); assert( eType>=0 && eType<array_size(aType) ); assert( iLock>0 && iLock<=16 ); memset(&lock, 0, sizeof(lock)); lock.l_whence = SEEK_SET; lock.l_len = 1; lock.l_type = aType[eType]; lock.l_start = (4096-iLock); if( fcntl(p->fd, F_SETLK, &lock) ){ int e = errno; if( e==EACCES || e==EAGAIN ){ rc = LSM_BUSY; }else{ rc = LSM_IOERR; } } return LSM_OK; } int lsmPosixOsShmMap(lsm_file *pFile, int iChunk, int sz, void **ppShm){ PosixFile *p = (PosixFile *)pFile; *ppShm = 0; assert( sz==LSM_SHM_CHUNK_SIZE ); if( iChunk>=p->nShm ){ int i; void **apNew; int nNew = iChunk+1; off_t nReq = nNew * LSM_SHM_CHUNK_SIZE; struct stat sStat; /* If the shared-memory file has not been opened, open it now. */ if( p->shmfd<=0 ){ char *zShm = posixShmFile(p); if( !zShm ) return LSM_NOMEM_BKPT; p->shmfd = open(zShm, O_RDWR|O_CREAT, 0644); lsmFree(p->pEnv, zShm); if( p->shmfd<0 ){ return LSM_IOERR_BKPT; } } /* If the shared-memory file is not large enough to contain the ** requested chunk, cause it to grow. */ if( fstat(p->shmfd, &sStat) ){ return LSM_IOERR_BKPT; } if( sStat.st_size<nReq ){ if( ftruncate(p->shmfd, nReq) ){ return LSM_IOERR_BKPT; } } apNew = (void **)lsmRealloc(p->pEnv, p->apShm, sizeof(void *) * nNew); if( !apNew ) return LSM_NOMEM_BKPT; for(i=p->nShm; i<nNew; i++){ apNew[i] = 0; } p->apShm = apNew; p->nShm = nNew; } if( p->apShm[iChunk]==0 ){ p->apShm[iChunk] = mmap(0, LSM_SHM_CHUNK_SIZE, PROT_READ|PROT_WRITE, MAP_SHARED, p->shmfd, iChunk*LSM_SHM_CHUNK_SIZE ); if( p->apShm[iChunk]==0 ) return LSM_IOERR; } *ppShm = p->apShm[iChunk]; return LSM_OK; } void lsmPosixOsShmBarrier(void){ } int lsmPosixOsShmUnmap(lsm_file *pFile, int bDelete){ PosixFile *p = (PosixFile *)pFile; if( p->shmfd>0 ){ int i; for(i=0; i<p->nShm; i++){ if( p->apShm[i] ){ munmap(p->apShm[i], LSM_SHM_CHUNK_SIZE); p->apShm[i] = 0; } } close(p->shmfd); p->shmfd = 0; if( bDelete ){ char *zShm = posixShmFile(p); if( zShm ) unlink(zShm); } } return LSM_OK; } static int lsmPosixOsClose(lsm_file *pFile){ PosixFile *p = (PosixFile *)pFile; lsmPosixOsShmUnmap(pFile, 0); if( p->pMap ) munmap(p->pMap, p->nMap); close(p->fd); lsm_free(p->pEnv, p); return LSM_OK; } |
︙ | |||
528 529 530 531 532 533 534 535 536 537 538 539 540 541 | 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 | + + + + | lsmPosixOsTruncate, /* xTruncate */ lsmPosixOsSync, /* xSync */ lsmPosixOsSectorSize, /* xSectorSize */ lsmPosixOsRemap, /* xRemap */ lsmPosixOsFileid, /* xFileid */ lsmPosixOsClose, /* xClose */ lsmPosixOsUnlink, /* xUnlink */ lsmPosixOsLock, /* xLock */ lsmPosixOsShmMap, /* xShmMap */ lsmPosixOsShmBarrier, /* xShmBarrier */ lsmPosixOsShmUnmap, /* xShmUnmap */ /***** memory allocation *********/ 0, /* pMemCtx */ lsmPosixOsMalloc, /* xMalloc */ lsmPosixOsRealloc, /* xRealloc */ lsmPosixOsFree, /* xFree */ lsmPosixOsMSize, /* xSize */ /***** mutexes *********************/ |
︙ |
Changes to test/attach.test.
︙ | |||
20 21 22 23 24 25 26 | 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | - + - | ifcapable !attach { finish_test return } for {set i 2} {$i<=15} {incr i} { |
︙ |
Added test/ckpt1.test.