1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 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 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 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 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 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 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293 3294 3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432 3433 3434 3435 3436 3437 3438 3439 3440 3441 3442 3443 3444 3445 3446 3447 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 3524 3525 3526 3527 3528 3529 3530 3531 3532 3533 3534 3535 3536 3537 3538 3539 3540 3541 3542 3543 3544 3545 3546 3547 3548 3549 3550 3551 3552 3553 3554 3555 3556 3557 3558 3559 3560 3561 3562 3563 3564 3565 3566 3567 3568 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 3608 3609 3610 3611 3612 3613 3614 3615 3616 3617 3618 3619 3620 3621 3622 3623 3624 3625 3626 3627 3628 3629 3630 3631 3632 3633 3634 3635 3636 3637 3638 3639 3640 3641 3642 3643 3644 3645 3646 3647 3648 3649 3650 3651 3652 3653 3654 3655 3656 3657 3658 3659 3660 3661 3662 3663 3664 3665 3666 3667 3668 3669 3670 3671 3672 3673 3674 3675 3676 3677 3678 3679 3680 3681 3682 3683 3684 3685 3686 3687 3688 3689 3690 3691 3692 3693 3694 3695 3696 3697 3698 3699 3700 3701 3702 3703 3704 3705 3706 3707 3708 3709 3710 3711 3712 3713 3714 3715 3716 3717 3718 3719 3720 3721 3722 3723 3724 3725 3726 3727 3728 3729 3730 3731 3732 3733 3734 3735 3736 3737 3738 3739 3740 3741 3742 3743 3744 3745 3746 3747 3748 3749 3750 3751 3752 3753 3754 3755 3756 3757 3758 3759 3760 3761 3762 3763 3764 3765 3766 3767 3768 3769 3770 3771 3772 3773 3774 3775 3776 3777 3778 3779 3780 3781 3782 3783 3784 3785 3786 3787 3788 3789 3790 3791 3792 3793 3794 3795 3796 3797 3798 3799 3800 3801 3802 3803 3804 3805 3806 3807 3808 3809 3810 3811 3812 3813 3814 3815 3816 3817 3818 3819 3820 3821 3822 3823 3824 3825 3826 3827 3828 3829 3830 3831 3832 3833 3834 3835 3836 3837 3838 3839 3840 3841 3842 3843 3844 3845 3846 3847 3848 3849 3850 3851 3852 3853 3854 3855 3856 3857 3858 3859 3860 3861 3862 3863 3864 3865 3866 3867 3868 3869 3870 3871 3872 3873 3874 3875 3876 3877 3878 3879 3880 3881 3882 3883 3884 3885 3886 3887 3888 3889 3890 3891 3892 3893 3894 3895 3896 3897 3898 3899 3900 3901 3902 3903 3904 3905 3906 3907 3908 3909 3910 3911 3912 3913 3914 3915 3916 3917 3918 3919 3920 3921 3922 3923 3924 3925 3926 3927 3928 3929 3930 3931 3932 3933 3934 3935 3936 3937 3938 3939 3940 3941 3942 3943 3944 3945 3946 3947 3948 3949 3950 3951 3952 3953 3954 3955 3956 3957 3958 3959 3960 3961 3962 3963 3964 3965 3966 3967 3968 3969 3970 3971 3972 3973 3974 3975 3976 3977 3978 3979 3980 3981 3982 3983 3984 3985 3986 3987 3988 3989 3990 3991 3992 3993 3994 3995 3996 3997 3998 3999 4000 4001 4002 4003 4004 4005 4006 4007 4008 4009 4010 4011 4012 4013 4014 4015 4016 4017 4018 4019 4020 4021 4022 4023 4024 4025 4026 4027 4028 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 4083 4084 4085 4086 4087 4088 4089 4090 4091 4092 4093 4094 4095 4096 4097 4098 4099 4100 4101 4102 4103 4104 4105 4106 4107 4108 4109 4110 4111 4112 4113 4114 4115 4116 4117 4118 4119 4120 4121 4122 4123 4124 4125 4126 4127 4128 4129 4130 4131 4132 4133 4134 4135 4136 4137 4138 4139 4140 4141 4142 4143 4144 4145 4146 4147 4148 4149 4150 4151 4152 4153 4154 4155 4156 4157 4158 4159 4160 4161 4162 4163 4164 4165 4166 4167 4168 4169 4170 4171 4172 4173 4174 4175 4176 4177 4178 4179 4180 4181 4182 4183 4184 4185 4186 4187 4188 4189 4190 4191 4192 4193 4194 4195 4196 4197 4198 4199 4200 4201 4202 4203 4204 4205 4206 4207 4208 4209 4210 4211 4212 4213 4214 4215 4216 4217 4218 4219 4220 4221 4222 4223 4224 4225 4226 4227 4228 4229 4230 4231 4232 4233 4234 4235 4236 4237 4238 4239 4240 4241 4242 4243 4244 4245 4246 4247 4248 4249 4250 4251 4252 4253 4254 4255 4256 4257 4258 4259 4260 4261 4262 4263 4264 4265 4266 4267 4268 4269 4270 4271 4272 4273 4274 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 4304 4305 4306 4307 4308 4309 4310 4311 4312 4313 4314 4315 4316 4317 4318 4319 4320 4321 4322 4323 4324 4325 4326 4327 4328 4329 4330 4331 4332 4333 4334 4335 4336 4337 4338 4339 4340 4341 4342 4343 4344 4345 4346 4347 4348 4349 4350 4351 4352 4353 4354 4355 4356 4357 4358 4359 4360 4361 4362 4363 4364 4365 4366 4367 4368 4369 4370 4371 4372 4373 4374 4375 4376 4377 4378 4379 4380 4381 4382 4383 4384 4385 4386 4387 4388 4389 4390 4391 4392 4393 4394 4395 4396 4397 4398 4399 4400 4401 4402 4403 4404 4405 4406 4407 4408 4409 4410 4411 4412 4413 4414 4415 4416 4417 4418 4419 4420 4421 4422 4423 4424 4425 4426 4427 4428 4429 4430 4431 4432 4433 4434 4435 4436 4437 4438 4439 4440 4441 4442 4443 4444 4445 4446 4447 4448 4449 4450 4451 4452 4453 4454 4455 4456 4457 4458 4459 4460 4461 4462 4463 4464 4465 4466 4467 4468 4469 4470 4471 4472 4473 4474 4475 4476 4477 4478 4479 4480 4481 4482 4483 4484 4485 4486 4487 4488 4489 4490 4491 4492
|
/*-
* See the file LICENSE for redistribution information.
*
* Copyright (c) 2009, 2013 Oracle and/or its affiliates. All rights reserved.
*
*/
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Text;
using BerkeleyDB.Internal;
namespace BerkeleyDB {
/// <summary>
/// A class representing a Berkeley DB database environment - a collection
/// including support for some or all of caching, locking, logging and
/// transaction subsystems, as well as databases and log files.
/// </summary>
public class DatabaseEnvironment {
internal DB_ENV dbenv;
private IBackup backupObj;
private ErrorFeedbackDelegate errFeedbackHandler;
private EnvironmentFeedbackDelegate feedbackHandler;
private ThreadIsAliveDelegate isAliveHandler;
private EventNotifyDelegate notifyHandler;
private MessageDispatchDelegate messageDispatchHandler;
private ReplicationTransportDelegate transportHandler;
private SetThreadIDDelegate threadIDHandler;
private SetThreadNameDelegate threadNameHandler;
private string _pfx;
private DBTCopyDelegate CopyDelegate;
private BDB_BackupCloseDelegate doBackupCloseRef;
private BDB_BackupOpenDelegate doBackupOpenRef;
private BDB_BackupWriteDelegate doBackupWriteRef;
private BDB_ErrcallDelegate doErrFeedbackRef;
private BDB_EnvFeedbackDelegate doFeedbackRef;
private BDB_EventNotifyDelegate doNotifyRef;
private BDB_IsAliveDelegate doIsAliveRef;
private BDB_MessageDispatchDelegate doMessageDispatchRef;
private BDB_RepTransportDelegate doRepTransportRef;
private BDB_ThreadIDDelegate doThreadIDRef;
private BDB_ThreadNameDelegate doThreadNameRef;
private static long GIGABYTE = (long)(1 << 30);
#region Callbacks
private static int doBackupClose(IntPtr env, string dbname, IntPtr handle) {
DB_ENV dbenv = new DB_ENV(env, false);
return dbenv.api2_internal.backupObj.Close(dbname);
}
private static int doBackupOpen(IntPtr env, string dbname, string target, IntPtr handle) {
DB_ENV dbenv = new DB_ENV(env, false);
return dbenv.api2_internal.backupObj.Open(dbname, target);
}
private static int doBackupWrite(IntPtr env, uint off_gbytes, uint off_bytes, uint usize, IntPtr buf, IntPtr handle) {
int ret, size;
long offset = off_gbytes * GIGABYTE + off_bytes;
DB_ENV dbenv = new DB_ENV(env, false);
if (usize > Int32.MaxValue)
size = Int32.MaxValue;
else
size = (int)usize;
byte[] data = new byte[size];
Marshal.Copy(buf, data, 0, (int)size);
ret = dbenv.api2_internal.backupObj.Write(data, offset, (int)size);
if (ret == 0 && usize > Int32.MaxValue) {
size = (int)(usize - Int32.MaxValue);
/*
* There's no need to re-allocate data, it's already as large as
* we could possibly need it to be. Advance buf beyond what was
* just copied and write the remaining data.
*/
buf = new IntPtr(buf.ToInt64() + Int32.MaxValue);
Marshal.Copy(buf, data, 0, (int)size);
ret = dbenv.api2_internal.backupObj.Write(data, offset, (int)size);
}
return ret;
}
private static void doNotify(IntPtr env, uint eventcode, byte[] event_info) {
DB_ENV dbenv = new DB_ENV(env, false);
dbenv.api2_internal.notifyHandler(
(NotificationEvent)eventcode, event_info);
}
private static void doErrFeedback(IntPtr env, string pfx, string msg) {
DB_ENV dbenv = new DB_ENV(env, false);
dbenv.api2_internal.errFeedbackHandler(
dbenv.api2_internal._pfx, msg);
}
private static void doFeedback(IntPtr env, int opcode, int percent) {
DB_ENV dbenv = new DB_ENV(env, false);
dbenv.api2_internal.feedbackHandler(
(EnvironmentFeedbackEvent)opcode, percent);
}
private static int doIsAlive(IntPtr env, int pid, uint tid, uint flags) {
DB_ENV dbenv = new DB_ENV(env, false);
DbThreadID id = new DbThreadID(pid, tid);
bool procOnly = (flags == DbConstants.DB_MUTEX_PROCESS_ONLY);
return dbenv.api2_internal.isAliveHandler(id, procOnly) ? 1 : 0;
}
private static void doMessageDispatch(IntPtr env, IntPtr channel,
IntPtr requestp, uint nrequest, uint cb_flags) {
DB_ENV dbenv = new DB_ENV(env, false);
DbChannel dbchannel = new DbChannel(new DB_CHANNEL(channel, false));
bool need_response =
(cb_flags == DbConstants.DB_REPMGR_NEED_RESPONSE);
IntPtr[] reqp = new IntPtr[nrequest];
Marshal.Copy(requestp, reqp, 0, (int)nrequest);
DatabaseEntry[] requests = new DatabaseEntry[nrequest];
for (int i = 0; i < nrequest; i++) {
requests[i] = DatabaseEntry.fromDBT(new DBT(reqp[i], false));
}
dbenv.api2_internal.messageDispatchHandler(
dbchannel, ref requests, out nrequest, need_response);
}
private static int doRepTransport(IntPtr envp,
IntPtr controlp, IntPtr recp, IntPtr lsnp, int envid, uint flags) {
DB_ENV dbenv = new DB_ENV(envp, false);
DBT control = new DBT(controlp, false);
DBT rec = new DBT(recp, false);
DB_LSN tmplsn = new DB_LSN(lsnp, false);
LSN dblsn = new LSN(tmplsn.file, tmplsn.offset);
return dbenv.api2_internal.transportHandler(
DatabaseEntry.fromDBT(control),
DatabaseEntry.fromDBT(rec), dblsn, envid, flags);
}
private static void doThreadID(IntPtr env, IntPtr pid, IntPtr tid) {
DB_ENV dbenv = new DB_ENV(env, false);
DbThreadID id = dbenv.api2_internal.threadIDHandler();
/*
* Sometimes the library doesn't care about either pid or tid
* (usually tid) and will pass NULL instead of a valid pointer.
*/
if (pid != IntPtr.Zero)
Marshal.WriteInt32(pid, id.processID);
if (tid != IntPtr.Zero)
Marshal.WriteInt32(tid, (int)id.threadID);
}
private static string doThreadName(IntPtr env,
int pid, uint tid, ref string buf) {
DB_ENV dbenv = new DB_ENV(env, false);
DbThreadID id = new DbThreadID(pid, tid);
string ret =
dbenv.api2_internal.threadNameHandler(id);
try {
buf = ret;
} catch (NullReferenceException) {
/*
* The library may give us a NULL pointer in buf and there's no
* good way to test for that. Just ignore the exception if
* we're not able to set buf.
*/
}
return ret;
}
#endregion Callbacks
private DatabaseEnvironment(uint flags) {
dbenv = new DB_ENV(flags);
initialize();
}
/* Called by Databases with private environments. */
internal DatabaseEnvironment(DB_ENV dbenvp) {
dbenv = dbenvp;
initialize();
}
private void initialize() {
dbenv.api2_internal = this;
CopyDelegate = new DBTCopyDelegate(DatabaseEntry.dbt_usercopy);
dbenv.set_usercopy(CopyDelegate);
}
private void Config(DatabaseEnvironmentConfig cfg) {
//Alpha by dbenv function call
foreach (string dirname in cfg.DataDirs)
dbenv.add_data_dir(dirname);
if (cfg.CreationDir != null)
dbenv.set_create_dir(cfg.CreationDir);
if (cfg.encryptionIsSet)
dbenv.set_encrypt(
cfg.EncryptionPassword, (uint)cfg.EncryptAlgorithm);
if (cfg.MetadataDir != null)
dbenv.set_metadata_dir(cfg.MetadataDir);
if (cfg.ErrorFeedback != null)
ErrorFeedback = cfg.ErrorFeedback;
ErrorPrefix = cfg.ErrorPrefix;
if (cfg.EventNotify != null)
EventNotify = cfg.EventNotify;
if (cfg.Feedback != null)
Feedback = cfg.Feedback;
if (cfg.IntermediateDirMode != null)
IntermediateDirMode = cfg.IntermediateDirMode;
if (cfg.ThreadIsAlive != null)
ThreadIsAlive = cfg.ThreadIsAlive;
if (cfg.threadCntIsSet)
ThreadCount = cfg.ThreadCount;
if (cfg.SetThreadID != null)
SetThreadID = cfg.SetThreadID;
if (cfg.ThreadName != null)
threadNameHandler = cfg.ThreadName;
if (cfg.lckTimeoutIsSet)
LockTimeout = cfg.LockTimeout;
if (cfg.txnTimeoutIsSet)
TxnTimeout = cfg.TxnTimeout;
if (cfg.TempDir != null)
TempDir = cfg.TempDir;
if (cfg.maxTxnsIsSet)
MaxTransactions = cfg.MaxTransactions;
if (cfg.txnTimestampIsSet)
TxnTimestamp = cfg.TxnTimestamp;
if (cfg.Verbosity != null)
Verbosity = cfg.Verbosity;
if (cfg.flags != 0)
dbenv.set_flags(cfg.flags, 1);
if (cfg.initThreadCountIsSet)
InitThreadCount = cfg.InitThreadCount;
if (cfg.initTxnCountIsSet)
InitTxnCount = cfg.InitTxnCount;
if (cfg.LockSystemCfg != null) {
if (cfg.LockSystemCfg.Conflicts != null)
LockConflictMatrix = cfg.LockSystemCfg.Conflicts;
if (cfg.LockSystemCfg.DeadlockResolution != null)
DeadlockResolution = cfg.LockSystemCfg.DeadlockResolution;
if (cfg.LockSystemCfg.initLockerCountIsSet)
InitLockerCount = cfg.LockSystemCfg.InitLockerCount;
if (cfg.LockSystemCfg.initLockCountIsSet)
InitLockCount = cfg.LockSystemCfg.InitLockCount;
if (cfg.LockSystemCfg.initLockObjectCountIsSet)
InitLockObjectCount = cfg.LockSystemCfg.InitLockObjectCount;
if (cfg.LockSystemCfg.maxLockersIsSet)
MaxLockers = cfg.LockSystemCfg.MaxLockers;
if (cfg.LockSystemCfg.maxLocksIsSet)
MaxLocks = cfg.LockSystemCfg.MaxLocks;
if (cfg.LockSystemCfg.maxObjectsIsSet)
MaxObjects = cfg.LockSystemCfg.MaxObjects;
if (cfg.LockSystemCfg.partitionsIsSet)
LockPartitions = cfg.LockSystemCfg.Partitions;
if (cfg.LockSystemCfg.tablesizeIsSet)
LockTableSize = cfg.LockSystemCfg.TableSize;
}
if (cfg.LogSystemCfg != null) {
if (cfg.LogSystemCfg.bsizeIsSet)
LogBufferSize = cfg.LogSystemCfg.BufferSize;
if (cfg.LogSystemCfg.Dir != null)
LogDir = cfg.LogSystemCfg.Dir;
if (cfg.LogSystemCfg.initLogIdCountIsSet)
InitLogIdCount = cfg.LogSystemCfg.InitLogIdCount;
if (cfg.LogSystemCfg.modeIsSet)
LogFileMode = cfg.LogSystemCfg.FileMode;
if (cfg.LogSystemCfg.maxSizeIsSet)
MaxLogFileSize = cfg.LogSystemCfg.MaxFileSize;
if (cfg.LogSystemCfg.regionSizeIsSet)
LogRegionSize = cfg.LogSystemCfg.RegionSize;
if (cfg.LogSystemCfg.ConfigFlags != 0)
dbenv.log_set_config(cfg.LogSystemCfg.ConfigFlags, 1);
}
if (cfg.MPoolSystemCfg != null) {
if (cfg.MPoolSystemCfg.CacheSize != null)
CacheSize = cfg.MPoolSystemCfg.CacheSize;
if (cfg.MPoolSystemCfg.MaxCacheSize != null)
MaxCacheSize = cfg.MPoolSystemCfg.MaxCacheSize;
if (cfg.MPoolSystemCfg.maxOpenFDIsSet)
MaxOpenFiles = cfg.MPoolSystemCfg.MaxOpenFiles;
if (cfg.MPoolSystemCfg.maxSeqWriteIsSet)
SetMaxSequentialWrites(
cfg.MPoolSystemCfg.MaxSequentialWrites,
cfg.MPoolSystemCfg.SequentialWritePause);
if (cfg.MPoolSystemCfg.mmapSizeSet)
MMapSize = cfg.MPoolSystemCfg.MMapSize;
}
if (cfg.MutexSystemCfg != null) {
if (cfg.MutexSystemCfg.alignmentIsSet)
MutexAlignment = cfg.MutexSystemCfg.Alignment;
/*
* Setting max after increment ensures that the value of max
* will win if both max and increment are set. This is the
* behavior we document in MutexConfig.
*/
if (cfg.MutexSystemCfg.incrementIsSet)
MutexIncrement = cfg.MutexSystemCfg.Increment;
if (cfg.MutexSystemCfg.initMutexesIsSet)
InitMutexes = cfg.MutexSystemCfg.InitMutexes;
if (cfg.MutexSystemCfg.maxMutexesIsSet)
MaxMutexes = cfg.MutexSystemCfg.MaxMutexes;
if (cfg.MutexSystemCfg.numTASIsSet)
NumTestAndSetSpins = cfg.MutexSystemCfg.NumTestAndSetSpins;
}
if (cfg.RepSystemCfg != null) {
if (cfg.RepSystemCfg.ackTimeoutIsSet)
RepAckTimeout = cfg.RepSystemCfg.AckTimeout;
if (cfg.RepSystemCfg.BulkTransfer)
RepBulkTransfer = true;
if (cfg.RepSystemCfg.checkpointDelayIsSet)
RepCheckpointDelay = cfg.RepSystemCfg.CheckpointDelay;
if (cfg.RepSystemCfg.clockskewIsSet)
RepSetClockskew(cfg.RepSystemCfg.ClockskewFast,
cfg.RepSystemCfg.ClockskewSlow);
if (cfg.RepSystemCfg.connectionRetryIsSet)
RepConnectionRetry = cfg.RepSystemCfg.ConnectionRetry;
if (cfg.RepSystemCfg.DelayClientSync)
RepDelayClientSync = true;
if (cfg.RepSystemCfg.electionRetryIsSet)
RepElectionRetry = cfg.RepSystemCfg.ElectionRetry;
if (cfg.RepSystemCfg.electionTimeoutIsSet)
RepElectionTimeout = cfg.RepSystemCfg.ElectionTimeout;
if (cfg.RepSystemCfg.fullElectionTimeoutIsSet)
RepFullElectionTimeout =
cfg.RepSystemCfg.FullElectionTimeout;
if (cfg.RepSystemCfg.heartbeatMonitorIsSet)
RepHeartbeatMonitor = cfg.RepSystemCfg.HeartbeatMonitor;
if (cfg.RepSystemCfg.heartbeatSendIsSet)
RepHeartbeatSend = cfg.RepSystemCfg.HeartbeatSend;
if (cfg.RepSystemCfg.InMemory)
dbenv.rep_set_config(DbConstants.DB_REP_CONF_INMEM, 1);
if (cfg.RepSystemCfg.leaseTimeoutIsSet)
RepLeaseTimeout = cfg.RepSystemCfg.LeaseTimeout;
if (!cfg.RepSystemCfg.AutoInit)
RepAutoInit = false;
if (cfg.RepSystemCfg.NoBlocking)
RepNoBlocking = true;
if (cfg.RepSystemCfg.nsitesIsSet)
RepNSites = cfg.RepSystemCfg.NSites;
for (int i = 0; i < cfg.RepSystemCfg.RepmgrSitesConfig.Count; i++)
RepMgrSiteConfig(cfg.RepSystemCfg.RepmgrSitesConfig[i]);
if (cfg.RepSystemCfg.priorityIsSet)
RepPriority = cfg.RepSystemCfg.Priority;
if (cfg.RepSystemCfg.RepMgrAckPolicy != null)
RepMgrAckPolicy = cfg.RepSystemCfg.RepMgrAckPolicy;
if (cfg.RepSystemCfg.retransmissionRequestIsSet)
RepSetRetransmissionRequest(
cfg.RepSystemCfg.RetransmissionRequestMin,
cfg.RepSystemCfg.RetransmissionRequestMax);
if (cfg.RepSystemCfg.Strict2Site)
RepStrict2Site = true;
if (cfg.RepSystemCfg.transmitLimitIsSet)
RepSetTransmitLimit(
cfg.RepSystemCfg.TransmitLimitGBytes,
cfg.RepSystemCfg.TransmitLimitBytes);
if (cfg.RepSystemCfg.UseMasterLeases)
RepUseMasterLeases = true;
if (!cfg.RepSystemCfg.Elections)
RepMgrRunElections = false;
}
}
#region Properties
/// <summary>
/// If true, database operations for which no explicit transaction
/// handle was specified, and which modify databases in the database
/// environment, will be automatically enclosed within a transaction.
/// </summary>
public bool AutoCommit {
get {
uint flags = 0;
dbenv.get_flags(ref flags);
return (flags & DbConstants.DB_AUTO_COMMIT) != 0;
}
set {
dbenv.set_flags(DbConstants.DB_AUTO_COMMIT, value ? 1 : 0);
}
}
/// <summary>
/// The size of the buffer, in bytes, to read from the database during a
/// hot backup.
/// </summary>
public uint BackupBufferSize {
get {
uint ret = 0;
dbenv.get_backup_config(DbConstants.DB_BACKUP_SIZE, ref ret);
return ret;
}
set {
dbenv.set_backup_config(DbConstants.DB_BACKUP_SIZE, value);
}
}
/// <summary>
/// Sets the <see cref="IBackup"/> interface to be used when performing
/// hot backups.
/// <para>
/// This interface is used to override the default behavior used by the
/// <see cref="DatabaseEnvironment.Backup"/> and
/// <see cref="DatabaseEnvironment.BackupDatabase"/> methods.
/// </para>
/// </summary>
public IBackup BackupHandler {
get { return backupObj; }
set {
if (value == null) {
dbenv.set_backup_callbacks(null, null, null);
} else if (backupObj == null) {
if (doBackupCloseRef == null)
doBackupCloseRef =
new BDB_BackupCloseDelegate(doBackupClose);
if (doBackupOpenRef == null)
doBackupOpenRef =
new BDB_BackupOpenDelegate(doBackupOpen);
if (doBackupWriteRef == null)
doBackupWriteRef =
new BDB_BackupWriteDelegate(doBackupWrite);
dbenv.set_backup_callbacks(
doBackupOpenRef, doBackupWriteRef, doBackupCloseRef);
}
backupObj = value;
}
}
/// <summary>
/// The number of pages to read before pausing during the hot backup.
/// <para>
/// Increasing this value increases the amount of I/O the backup process
/// performs for any given time interval. If your application is already
/// heavily I/O bound, setting this value to a lower number may help to
/// improve your overall data throughput by reducing the I/O demands
/// placed on your system. By default, all pages are read without a
/// pause.
/// </para>
/// </summary>
public uint BackupReadCount {
get {
uint ret = 0;
dbenv.get_backup_config(DbConstants.DB_BACKUP_READ_COUNT, ref ret);
return ret;
}
set {
dbenv.set_backup_config(DbConstants.DB_BACKUP_READ_COUNT, value);
}
}
/// <summary>
/// The number of microseconds to sleep between batches of reads during
/// a hot backup.
/// <para>
/// Increasing this value decreases the amount of I/O the backup process
/// performs for any given time interval. If your application is already
/// heavily I/O bound, setting this value to a higher number may help to
/// improve your overall data throughput by reducing the I/O demands
/// placed on your system.
/// </para>
/// </summary>
public uint BackupReadSleepDuration {
get {
uint ret = 0;
dbenv.get_backup_config(DbConstants.DB_BACKUP_READ_SLEEP, ref ret);
return ret;
}
set {
dbenv.set_backup_config(DbConstants.DB_BACKUP_READ_SLEEP, value);
}
}
/// <summary>
/// If true, direct I/O is used when writing pages to the disk during a
/// hot backup.
/// <para>
/// For some environments, direct I/O can provide faster write
/// throughput, but usually it is slower because the OS buffer pool
/// offers asynchronous activity.
/// </para>
/// </summary>
public bool BackupWriteDirect {
get {
uint ret = 0;
dbenv.get_backup_config(DbConstants.DB_BACKUP_WRITE_DIRECT, ref ret);
return ret != 0;
}
set {
dbenv.set_backup_config(DbConstants.DB_BACKUP_WRITE_DIRECT, (uint)(value ? 1 : 0));
}
}
/// <summary>
/// The size of the shared memory buffer pool -- that is, the cache.
/// </summary>
/// <remarks>
/// <para>
/// The cache should be the size of the normal working data set of the
/// application, with some small amount of additional memory for unusual
/// situations. (Note: the working set is not the same as the number of
/// pages accessed simultaneously, and is usually much larger.)
/// </para>
/// <para>
/// The default cache size is 256KB, and may not be specified as less
/// than 20KB. Any cache size less than 500MB is automatically increased
/// by 25% to account for buffer pool overhead; cache sizes larger than
/// 500MB are used as specified. The maximum size of a single cache is
/// 4GB on 32-bit systems and 10TB on 64-bit systems. (All sizes are in
/// powers-of-two, that is, 256KB is 2^18 not 256,000.) For information
/// on tuning the Berkeley DB cache size, see Selecting a cache size in
/// the Programmer's Reference Guide.
/// </para>
/// </remarks>
public CacheInfo CacheSize {
get {
uint gb = 0;
uint b = 0;
int n = 0;
dbenv.get_cachesize(ref gb, ref b, ref n);
return new CacheInfo(gb, b, n);
}
set {
if (value != null)
dbenv.set_cachesize(
value.Gigabytes, value.Bytes, value.NCaches);
}
}
/// <summary>
/// If true, Berkeley DB Concurrent Data Store applications will perform
/// locking on an environment-wide basis rather than on a per-database
/// basis.
/// </summary>
public bool CDB_ALLDB {
get {
uint flags = 0;
dbenv.get_flags(ref flags);
return (flags & DbConstants.DB_CDB_ALLDB) != 0;
}
}
/// <summary>
/// If true, Berkeley DB subsystems will create any underlying files, as
/// necessary.
/// </summary>
public bool Create {
get {
uint flags = 0;
dbenv.get_open_flags(ref flags);
return (flags & DbConstants.DB_CREATE) != 0;
}
}
/// <summary>
/// The array of directories where database files are stored.
/// </summary>
public List<string> DataDirs { get { return dbenv.get_data_dirs(); } }
/// <summary>
/// The deadlock detector configuration, specifying what lock request(s)
/// should be rejected. As transactions acquire locks on behalf of a
/// single locker ID, rejecting a lock request associated with a
/// transaction normally requires the transaction be aborted.
/// </summary>
public DeadlockPolicy DeadlockResolution {
get {
uint mode = 0;
dbenv.get_lk_detect(ref mode);
return DeadlockPolicy.fromPolicy(mode);
}
set {
if (value != null)
dbenv.set_lk_detect(value.policy);
else
dbenv.set_lk_detect(DeadlockPolicy.DEFAULT.policy);
}
}
/// <summary>
/// The algorithm used by the Berkeley DB library to perform encryption
/// and decryption.
/// </summary>
public EncryptionAlgorithm EncryptAlgorithm {
get {
uint flags = 0;
dbenv.get_encrypt_flags(ref flags);
return (EncryptionAlgorithm)Enum.ToObject(
typeof(EncryptionAlgorithm), flags);
}
}
/// <summary>
/// The mechanism for reporting detailed error messages to the
/// application.
/// </summary>
/// <remarks>
/// <para>
/// When an error occurs in the Berkeley DB library, a
/// <see cref="DatabaseException"/>, or subclass of DatabaseException,
/// is thrown. In some cases, however, the exception may be insufficient
/// to completely describe the cause of the error, especially during
/// initial application debugging.
/// </para>
/// <para>
/// In some cases, when an error occurs, Berkeley DB will call the given
/// delegate with additional error information. It is up to the delegate
/// to display the error message in an appropriate manner.
/// </para>
/// <para>
/// Setting ErrorFeedback to NULL unconfigures the callback interface.
/// </para>
/// <para>
/// This error-logging enhancement does not slow performance or
/// significantly increase application size, and may be run during
/// normal operation as well as during application debugging.
/// </para>
/// </remarks>
public ErrorFeedbackDelegate ErrorFeedback {
get { return errFeedbackHandler; }
set {
if (value == null)
dbenv.set_errcall(null);
else if (errFeedbackHandler == null) {
if (doErrFeedbackRef == null)
doErrFeedbackRef = new BDB_ErrcallDelegate(doErrFeedback);
dbenv.set_errcall(doErrFeedbackRef);
}
errFeedbackHandler = value;
}
}
/// <summary>
/// The prefix string that appears before error messages issued by
/// Berkeley DB.
/// </summary>
/// <remarks>
/// <para>
/// For databases opened inside of a DatabaseEnvironment, setting
/// ErrorPrefix affects the entire environment and is equivalent to
/// setting <see cref="DatabaseEnvironment.ErrorPrefix"/>.
/// </para>
/// <para>
/// Setting ErrorPrefix configures operations performed using the
/// specified object, not all operations performed on the underlying
/// database.
/// </para>
/// </remarks>
public string ErrorPrefix {
get { return _pfx; }
set { _pfx = value; }
}
/// <summary>
/// A delegate which is called to notify the process of specific
/// Berkeley DB events.
/// </summary>
public EventNotifyDelegate EventNotify {
get { return notifyHandler; }
set {
if (value == null)
dbenv.set_event_notify(null);
else if (notifyHandler == null) {
if (doNotifyRef == null)
doNotifyRef = new BDB_EventNotifyDelegate(doNotify);
dbenv.set_event_notify(doNotifyRef);
}
notifyHandler = value;
}
}
/// <summary>
/// Monitor progress within long running operations.
/// </summary>
/// <remarks>
/// <para>
/// Some operations performed by the Berkeley DB library can take
/// non-trivial amounts of time. The Feedback delegate can be used by
/// applications to monitor progress within these operations. When an
/// operation is likely to take a long time, Berkeley DB will call the
/// specified delegate with progress information.
/// </para>
/// <para>
/// It is up to the delegate to display this information in an
/// appropriate manner.
/// </para>
/// </remarks>
public EnvironmentFeedbackDelegate Feedback {
get { return feedbackHandler; }
set {
if (value == null)
dbenv.set_feedback(null);
else if (feedbackHandler == null) {
if (doFeedbackRef == null)
doFeedbackRef = new BDB_EnvFeedbackDelegate(doFeedback);
dbenv.set_feedback(doFeedbackRef);
}
feedbackHandler = value;
}
}
/// <summary>
/// If true, flush database writes to the backing disk before returning
/// from the write system call, rather than flushing database writes
/// explicitly in a separate system call, as necessary.
/// </summary>
/// <remarks>
/// This flag may result in inaccurate file modification times and other
/// file-level information for Berkeley DB database files. This flag
/// will almost certainly result in a performance decrease on most
/// systems.
/// </remarks>
public bool ForceFlush {
get {
uint flags = 0;
dbenv.get_flags(ref flags);
return (flags & DbConstants.DB_DSYNC_DB) != 0;
}
set {
dbenv.set_flags(DbConstants.DB_DSYNC_DB, value ? 1 : 0);
}
}
/// <summary>
/// If true, the object is free-threaded; that is, concurrently usable
/// by multiple threads in the address space.
/// </summary>
public bool FreeThreaded {
get {
uint flags = 0;
dbenv.get_open_flags(ref flags);
return (flags & DbConstants.DB_THREAD) != 0;
}
}
/// <summary>
/// The database environment home directory.
/// </summary>
public string Home {
get {
string dir = "";
dbenv.get_home(out dir);
return dir;
}
}
/// <summary>
/// Whether there is any hot backup in progress.
/// </summary>
public bool HotbackupInProgress {
get {
uint flags = 0;
dbenv.get_flags(ref flags);
return (flags & DbConstants.DB_HOTBACKUP_IN_PROGRESS) != 0;
}
set {
dbenv.set_flags(
DbConstants.DB_HOTBACKUP_IN_PROGRESS, value ? 1 : 0);
}
}
/// <summary>
/// The number of locks allocated when the environment is created
/// </summary>
public uint InitLockCount {
get {
uint ret = 0;
dbenv.get_memory_init(DbConstants.DB_MEM_LOCK, ref ret);
return ret;
}
private set {
dbenv.set_memory_init(DbConstants.DB_MEM_LOCK, value);
}
}
/// <summary>
/// The number of lock objects allocated when the environment is created
/// </summary>
public uint InitLockObjectCount {
get {
uint ret = 0;
dbenv.get_memory_init(DbConstants.DB_MEM_LOCKOBJECT, ref ret);
return ret;
}
private set {
dbenv.set_memory_init(DbConstants.DB_MEM_LOCKOBJECT, value);
}
}
/// <summary>
/// The number of lockers allocated when the environment is created
/// </summary>
public uint InitLockerCount {
get {
uint ret = 0;
dbenv.get_memory_init(DbConstants.DB_MEM_LOCKER, ref ret);
return ret;
}
private set {
dbenv.set_memory_init(DbConstants.DB_MEM_LOCKER, value);
}
}
/// <summary>
/// The number of log identifier objects allocated when the
/// environment is created
/// </summary>
public uint InitLogIdCount {
get {
uint ret = 0;
dbenv.get_memory_init(DbConstants.DB_MEM_LOGID, ref ret);
return ret;
}
private set {
dbenv.set_memory_init(DbConstants.DB_MEM_LOGID, value);
}
}
/// <summary>
/// The number of thread objects allocated when the environment is
/// created
/// </summary>
public uint InitThreadCount {
get {
uint ret = 0;
dbenv.get_memory_init(DbConstants.DB_MEM_THREAD, ref ret);
return ret;
}
private set {
dbenv.set_memory_init(DbConstants.DB_MEM_THREAD, value);
}
}
/// <summary>
/// The number of transaction objects allocated when the environment is
/// created
/// </summary>
public uint InitTxnCount {
get {
uint ret = 0;
dbenv.get_memory_init(DbConstants.DB_MEM_TRANSACTION, ref ret);
return ret;
}
private set {
dbenv.set_memory_init(DbConstants.DB_MEM_TRANSACTION, value);
}
}
/// <summary>
/// The initial number of mutexes allocated
/// </summary>
public uint InitMutexes {
get {
uint ret = 0;
dbenv.mutex_get_init(ref ret);
return ret;
}
private set {
dbenv.mutex_set_init(value);
}
}
/// <summary>
/// If true, Berkeley DB will page-fault shared regions into memory when
/// initially creating or joining a Berkeley DB environment.
/// </summary>
/// <remarks>
/// <para>
/// In some applications, the expense of page-faulting the underlying
/// shared memory regions can affect performance. (For example, if the
/// page-fault occurs while holding a lock, other lock requests can
/// convoy, and overall throughput may decrease.)
/// </para>
/// <para>
/// In addition to page-faulting, Berkeley DB will write the shared
/// regions when creating an environment, forcing the underlying virtual
/// memory and filesystems to instantiate both the necessary memory and
/// the necessary disk space. This can also avoid out-of-disk space
/// failures later on.
/// </para>
/// </remarks>
public bool InitRegions {
get {
uint flags = 0;
dbenv.get_flags(ref flags);
return (flags & DbConstants.DB_REGION_INIT) != 0;
}
set {
dbenv.set_flags(DbConstants.DB_REGION_INIT, value ? 1 : 0);
}
}
/// <summary>
/// The intermediate directory permissions.
/// </summary>
public string IntermediateDirMode {
get {
string ret;
dbenv.get_intermediate_dir_mode(out ret);
return ret;
}
private set {
dbenv.set_intermediate_dir_mode(value);
}
}
/// <summary>
/// The current lock conflicts array.
/// </summary>
public byte[,] LockConflictMatrix {
get {
int sz = 0;
dbenv.get_lk_conflicts_nmodes(ref sz);
byte [,] ret = new byte[sz, sz];
dbenv.get_lk_conflicts(ret);
return ret;
}
private set {
// Matrix dimensions checked in LockingConfig.
dbenv.set_lk_conflicts(value, (int)Math.Sqrt(value.Length));
}
}
/// <summary>
/// If true, lock shared Berkeley DB environment files and memory-mapped
/// databases into memory.
/// </summary>
public bool Lockdown {
get {
uint flags = 0;
dbenv.get_open_flags(ref flags);
return (flags & DbConstants.DB_LOCKDOWN) != 0;
}
}
/// <summary>
/// The size of the lock table in the Berkeley DB environment.
/// </summary>
public uint LockTableSize {
get {
uint ret = 0;
dbenv.get_lk_tablesize(ref ret);
return ret;
}
private set {
dbenv.set_lk_tablesize(value);
}
}
/// <summary>
/// The number of lock table partitions used in the Berkeley DB
/// environment.
/// </summary>
public uint LockPartitions {
get {
uint ret = 0;
dbenv.get_lk_partitions(ref ret);
return ret;
}
private set {
dbenv.set_lk_partitions(value);
}
}
/// <summary>
/// A value, in microseconds, representing lock timeouts.
/// </summary>
/// <remarks>
/// <para>
/// All timeouts are checked whenever a thread of control blocks on a
/// lock or when deadlock detection is performed. As timeouts are only
/// checked when the lock request first blocks or when deadlock
/// detection is performed, the accuracy of the timeout depends on how
/// often deadlock detection is performed.
/// </para>
/// <para>
/// Timeout values specified for the database environment may be
/// overridden on a per-transaction basis, see
/// <see cref="Transaction.SetLockTimeout"/>.
/// </para>
/// </remarks>
public uint LockTimeout {
get {
uint timeout = 0;
dbenv.get_timeout(ref timeout, DbConstants.DB_SET_LOCK_TIMEOUT);
return timeout;
}
set {
dbenv.set_timeout(value, DbConstants.DB_SET_LOCK_TIMEOUT);
}
}
/// <summary>
/// The size of the in-memory log buffer, in bytes
/// </summary>
public uint LogBufferSize {
get {
uint ret = 0;
dbenv.get_lg_bsize(ref ret);
return ret;
}
private set {
dbenv.set_lg_bsize(value);
}
}
/// <summary>
/// The path of a directory to be used as the location of logging files.
/// Log files created by the Log Manager subsystem will be created in
/// this directory.
/// </summary>
public string LogDir {
get {
string ret;
dbenv.get_lg_dir(out ret);
return ret;
}
private set {
dbenv.set_lg_dir(value);
}
}
/// <summary>
/// The absolute file mode for created log files. This property is only
/// useful for the rare Berkeley DB application that does not control
/// its umask value.
/// </summary>
/// <remarks>
/// Normally, if Berkeley DB applications set their umask appropriately,
/// all processes in the application suite will have read permission on
/// the log files created by any process in the application suite.
/// However, if the Berkeley DB application is a library, a process
/// using the library might set its umask to a value preventing other
/// processes in the application suite from reading the log files it
/// creates. In this rare case, this property can be used to set the
/// mode of created log files to an absolute value.
/// </remarks>
public int LogFileMode {
get {
int ret = 0;
dbenv.get_lg_filemode(ref ret);
return ret;
}
set {
dbenv.set_lg_filemode(value);
}
}
/// <summary>
/// If true, system buffering is turned off for Berkeley DB log files to
/// avoid double caching.
/// </summary>
public bool LogNoBuffer {
get {
int onoff = 0;
dbenv.log_get_config(DbConstants.DB_LOG_DIRECT, ref onoff);
return (onoff != 0);
}
set {
dbenv.log_set_config(DbConstants.DB_LOG_DIRECT, value ? 1 : 0);
}
}
/// <summary>
/// If true, Berkeley DB will flush log writes to the backing disk
/// before returning from the write system call, rather than flushing
/// log writes explicitly in a separate system call, as necessary.
/// </summary>
public bool LogForceSync {
get{
int onoff = 0;
dbenv.log_get_config(DbConstants.DB_LOG_DSYNC, ref onoff);
return (onoff != 0);
}
set {
dbenv.log_set_config(DbConstants.DB_LOG_DSYNC, value ? 1 : 0);
}
}
/// <summary>
/// If true, Berkeley DB will automatically remove log files that are no
/// longer needed.
/// </summary>
public bool LogAutoRemove {
get {
int onoff = 0;
dbenv.log_get_config(DbConstants.DB_LOG_AUTO_REMOVE, ref onoff);
return (onoff != 0);
}
set {
dbenv.log_set_config(
DbConstants.DB_LOG_AUTO_REMOVE, value ? 1 : 0);
}
}
/// <summary>
/// If true, transaction logs are maintained in memory rather than on
/// disk. This means that transactions exhibit the ACI (atomicity,
/// consistency, and isolation) properties, but not D (durability).
/// </summary>
public bool LogInMemory {
get {
int onoff = 0;
dbenv.log_get_config(DbConstants.DB_LOG_IN_MEMORY, ref onoff);
return (onoff != 0);
}
}
/// <summary>
/// If true, all pages of a log file are zeroed when that log file is
/// created.
/// </summary>
public bool LogZeroOnCreate {
get {
int onoff = 0;
dbenv.log_get_config(DbConstants.DB_LOG_ZERO, ref onoff);
return (onoff != 0);
}
}
/// <summary>
/// The size of the underlying logging area of the Berkeley DB
/// environment, in bytes.
/// </summary>
public uint LogRegionSize {
get {
uint ret = 0;
dbenv.get_lg_regionmax(ref ret);
return ret;
}
private set {
dbenv.set_lg_regionmax(value);
}
}
/// <summary>
/// The maximum cache size
/// </summary>
public CacheInfo MaxCacheSize {
get {
uint gb = 0;
uint b = 0;
dbenv.get_cache_max(ref gb, ref b);
return new CacheInfo(gb, b, 0);
}
private set {
dbenv.set_cache_max(value.Gigabytes, value.Bytes);
}
}
/// <summary>
/// The maximum size of a single file in the log, in bytes. Because
/// <see cref="LSN.Offset">LSN Offsets</see> are unsigned four-byte
/// values, the size may not be larger than the maximum unsigned
/// four-byte value.
/// </summary>
/// <remarks>
/// <para>
/// When the logging subsystem is configured for on-disk logging, the
/// default size of a log file is 10MB.
/// </para>
/// <para>
/// When the logging subsystem is configured for in-memory logging, the
/// default size of a log file is 256KB. In addition, the configured log
/// buffer size must be larger than the log file size. (The logging
/// subsystem divides memory configured for in-memory log records into
/// "files", as database environments configured for in-memory log
/// records may exchange log records with other members of a replication
/// group, and those members may be configured to store log records
/// on-disk.) When choosing log buffer and file sizes for in-memory
/// logs, applications should ensure the in-memory log buffer size is
/// large enough that no transaction will ever span the entire buffer,
/// and avoid a state where the in-memory buffer is full and no space
/// can be freed because a transaction that started in the first log
/// "file" is still active.
/// </para>
/// <para>
/// See Log File Limits in the Programmer's Reference Guide for more
/// information.
/// </para>
/// <para>
/// If no size is specified by the application, the size last specified
/// for the database region will be used, or if no database region
/// previously existed, the default will be used.
/// </para>
/// </remarks>
public uint MaxLogFileSize {
get {
uint ret = 0;
dbenv.get_lg_max(ref ret);
return ret;
}
set {
dbenv.set_lg_max(value);
}
}
/// <summary>
/// The maximum number of locking entities supported by the Berkeley DB
/// environment.
/// </summary>
public uint MaxLockers {
get {
uint ret = 0;
dbenv.get_lk_max_lockers(ref ret);
return ret;
}
private set {
dbenv.set_lk_max_lockers(value);
}
}
/// <summary>
/// The maximum number of locks supported by the Berkeley DB
/// environment.
/// </summary>
public uint MaxLocks {
get {
uint ret = 0;
dbenv.get_lk_max_locks(ref ret);
return ret;
}
private set {
dbenv.set_lk_max_locks(value);
}
}
/// <summary>
/// The total number of mutexes allocated
/// </summary>
public uint MaxMutexes {
get {
uint ret = 0;
dbenv.mutex_get_max(ref ret);
return ret;
}
private set {
dbenv.mutex_set_max(value);
}
}
/// <summary>
/// The maximum number of locked objects
/// </summary>
public uint MaxObjects {
get {
uint ret = 0;
dbenv.get_lk_max_objects(ref ret);
return ret;
}
private set {
dbenv.set_lk_max_objects(value);
}
}
/// <summary>
/// The number of file descriptors the library will open concurrently
/// when flushing dirty pages from the cache.
/// </summary>
public int MaxOpenFiles {
get {
int ret = 0;
dbenv.get_mp_max_openfd(ref ret);
return ret;
}
set {
dbenv.set_mp_max_openfd(value);
}
}
/// <summary>
/// The number of sequential write operations scheduled by the library
/// when flushing dirty pages from the cache.
/// </summary>
public int MaxSequentialWrites {
get {
int ret = 0;
uint tmp = 0;
dbenv.get_mp_max_write(ref ret, ref tmp);
return ret;
}
}
/// <summary>
/// The number of active transactions supported by the environment. This
/// value bounds the size of the memory allocated for transactions.
/// Child transactions are counted as active until they either commit or
/// abort.
/// </summary>
/// <remarks>
/// <para>
/// Transactions that update multiversion databases are not freed until
/// the last page version that the transaction created is flushed from
/// cache. This means that applications using multi-version concurrency
/// control may need a transaction for each page in cache, in the
/// extreme case.
/// </para>
/// <para>
/// When all of the memory available in the database environment for
/// transactions is in use, calls to <see cref="BeginTransaction"/> will
/// fail (until some active transactions complete). If MaxTransactions
/// is never set, the database environment is configured to support at
/// least 100 active transactions.
/// </para>
/// </remarks>
public uint MaxTransactions {
get {
uint ret = 0;
dbenv.get_tx_max(ref ret);
return ret;
}
set {
dbenv.set_tx_max(value);
}
}
/// <summary>
/// The path of directory to store the persistent metadata.
/// </summary>
/// <remarks>
/// <para>
/// By default, metadata is stored in the environment home directory.
/// See Berkeley DB File Naming in the Programmer's Reference Guide for
/// more information.
/// </para>
/// <para>
/// When used in a replicated application, the metadata directory must
/// be the same location for all sites within a replication group.
/// </para>
/// </remarks>
public string MetadataDir {
get {
string mddir;
dbenv.get_metadata_dir(out mddir);
return mddir;
}
}
/// <summary>
/// The maximum file size, in bytes, for a file to be mapped into the
/// process address space. If no value is specified, it defaults to
/// 10MB.
/// </summary>
/// <remarks>
/// Files that are opened read-only in the cache (and that satisfy a few
/// other criteria) are, by default, mapped into the process address
/// space instead of being copied into the local cache. This can result
/// in better-than-usual performance because available virtual memory is
/// normally much larger than the local cache, and page faults are
/// faster than page copying on many systems. However, it can cause
/// resource starvation in the presence of limited virtual memory, and
/// it can result in immense process sizes in the presence of large
/// databases.
/// </remarks>
public uint MMapSize {
get {
uint ret = 0;
dbenv.get_mp_mmapsize(ref ret);
return ret;
}
set {
dbenv.set_mp_mmapsize(value);
}
}
/// <summary>
/// The mutex alignment, in bytes.
/// </summary>
public uint MutexAlignment {
get {
uint ret = 0;
dbenv.mutex_get_align(ref ret);
return ret;
}
private set {
dbenv.mutex_set_align(value);
}
}
/// <summary>
/// The number of additional mutexes allocated.
/// </summary>
public uint MutexIncrement {
get {
uint ret = 0;
dbenv.mutex_get_increment(ref ret);
return ret;
}
private set {
dbenv.mutex_set_increment(value);
}
}
/// <summary>
/// If true, turn off system buffering of Berkeley DB database files to
/// avoid double caching.
/// </summary>
public bool NoBuffer {
get {
uint flags = 0;
dbenv.get_flags(ref flags);
return (flags & DbConstants.DB_DIRECT_DB) != 0;
}
set {
dbenv.set_flags(DbConstants.DB_DIRECT_DB, value ? 1 : 0);
}
}
/// <summary>
/// If true, Berkeley DB will grant all requested mutual exclusion
/// mutexes and database locks without regard for their actual
/// availability. This functionality should never be used for purposes
/// other than debugging.
/// </summary>
public bool NoLocking {
get {
uint flags = 0;
dbenv.get_flags(ref flags);
return (flags & DbConstants.DB_NOLOCKING) != 0;
}
set {
dbenv.set_flags(DbConstants.DB_NOLOCKING, value ? 1 : 0);
}
}
/// <summary>
/// If true, Berkeley DB will copy read-only database files into the
/// local cache instead of potentially mapping them into process memory.
/// </summary>
/// <seealso cref="MMapSize"/>
public bool NoMMap {
get {
uint flags = 0;
dbenv.get_flags(ref flags);
return (flags & DbConstants.DB_NOMMAP) != 0;
}
set {
dbenv.set_flags(DbConstants.DB_NOMMAP, value ? 1 : 0);
}
}
/// <summary>
/// If true, Berkeley DB will ignore any panic state in the database
/// environment. (Database environments in a panic state normally refuse
/// all attempts to call Berkeley DB functions, throwing
/// <see cref="RunRecoveryException"/>.) This functionality should never
/// be used for purposes other than debugging.
/// </summary>
public bool NoPanic {
get {
uint flags = 0;
dbenv.get_flags(ref flags);
return (flags & DbConstants.DB_NOPANIC) != 0;
}
set {
dbenv.set_flags(DbConstants.DB_NOPANIC, value ? 1 : 0);
}
}
/// <summary>
/// The number of times that test-and-set mutexes should spin without
/// blocking. The value defaults to 1 on uniprocessor systems and to 50
/// times the number of processors on multiprocessor systems.
/// </summary>
public uint NumTestAndSetSpins {
get {
uint ret = 0;
dbenv.mutex_get_tas_spins(ref ret);
return ret;
}
set {
dbenv.mutex_set_tas_spins(value);
}
}
/// <summary>
/// If true, overwrite files stored in encrypted formats before deleting
/// them.
/// </summary>
/// <remarks>
/// Berkeley DB overwrites files using alternating 0xff, 0x00 and 0xff
/// byte patterns. For file overwriting to be effective, the underlying
/// file must be stored on a fixed-block filesystem. Systems with
/// journaling or logging filesystems will require operating system
/// support and probably modification of the Berkeley DB sources.
/// </remarks>
public bool Overwrite {
get {
uint flags = 0;
dbenv.get_flags(ref flags);
return (flags & DbConstants.DB_OVERWRITE) != 0;
}
set {
dbenv.set_flags(DbConstants.DB_OVERWRITE, value ? 1 : 0);
}
}
/// <summary>
/// If true, allocate region memory from the heap instead of from memory
/// backed by the filesystem or system shared memory.
/// </summary>
public bool Private {
get {
uint flags = 0;
dbenv.get_open_flags(ref flags);
return (flags & DbConstants.DB_PRIVATE) != 0;
}
}
/// <summary>
/// The gigabytes component of the byte-count limit on the amount of
/// memory to be used by shared structures in the main environment
/// region. These are the structures other than mutexes and the page
/// cache (memory pool).
/// </summary>
/// <returns>The maximum number of gigabytes used by the main region.
/// </returns>
public uint RegionMemoryLimitGBytes {
get {
uint gb = 0;
uint b = 0;
dbenv.get_memory_max(ref gb, ref b);
return gb;
}
}
/// <summary>
/// The bytes component of the byte-count limit on the amount of
/// memory to be used by shared structures in the main environment
/// region. These are the structures other than mutexes and the page
/// cache (memory pool).
/// </summary>
/// <returns>The maximum number of bytes used by the main region.
/// </returns>
public uint RegionMemoryLimitBytes {
get {
uint gb = 0;
uint b = 0;
dbenv.get_memory_max(ref gb, ref b);
return b;
}
}
/// <summary>
/// The amount of memory to be used by shared structures in the main
/// environment region. These are structures other than mutexes and
/// the page cache (memory pool).
/// </summary>
/// <param name="GBytes">
/// The number of gigabytes to allocate for the main memory region.
/// The gigabytes allocated will be added to the bytes input.
/// </param>
/// <param name="Bytes">
/// The number of gigabytes to allocate for the main memory region.
/// The bytes allocated will be added to the gigabytes input.
/// </param>
public void RegionSetMemoryLimit(uint GBytes, uint Bytes) {
dbenv.set_memory_max(GBytes, Bytes);
}
/// <summary>
/// If true, Berkeley DB will have checked to see if recovery needed to
/// be performed before opening the database environment.
/// </summary>
public bool Register {
get {
uint flags = 0;
dbenv.get_open_flags(ref flags);
return (flags & DbConstants.DB_REGISTER) != 0;
}
}
/// <summary>
/// The amount of time the replication manager's transport function
/// waits to collect enough acknowledgments from replication group
/// clients, before giving up and returning a failure indication. The
/// default wait time is 1 second.
/// </summary>
public uint RepAckTimeout {
get { return getRepTimeout(DbConstants.DB_REP_ACK_TIMEOUT); }
set {
dbenv.rep_set_timeout(
DbConstants.DB_REP_ACK_TIMEOUT, value);
}
}
/// <summary>
/// If true, the replication master sends groups of records to the
/// clients in a single network transfer
/// </summary>
public bool RepBulkTransfer {
get { return getRepConfig(DbConstants.DB_REP_CONF_BULK); }
set {
dbenv.rep_set_config(
DbConstants.DB_REP_CONF_BULK, value ? 1 : 0);
}
}
/// <summary>
/// The amount of time a master site will delay between completing a
/// checkpoint and writing a checkpoint record into the log.
/// </summary>
/// <remarks>
/// This delay allows clients to complete their own checkpoints before
/// the master requires completion of them. The default is 30 seconds.
/// If all databases in the environment, and the environment's
/// transaction log, are configured to reside in memory (never preserved
/// to disk), then, although checkpoints are still necessary, the delay
/// is not useful and should be set to 0.
/// </remarks>
public uint RepCheckpointDelay {
get { return getRepTimeout(DbConstants.DB_REP_CHECKPOINT_DELAY); }
set {
dbenv.rep_set_timeout(
DbConstants.DB_REP_CHECKPOINT_DELAY, value);
}
}
/// <summary>
/// The value, relative to <see cref="RepClockskewSlow"/>, of the
/// fastest clock in the group of sites.
/// </summary>
public uint RepClockskewFast {
get {
uint fast = 0;
uint slow = 0;
dbenv.rep_get_clockskew(ref fast, ref slow);
return fast;
}
}
/// <summary>
/// The value of the slowest clock in the group of sites.
/// </summary>
public uint RepClockskewSlow {
get {
uint fast = 0;
uint slow = 0;
dbenv.rep_get_clockskew(ref fast, ref slow);
return slow;
}
}
/// <summary>
/// Set the clock skew ratio among replication group members based on
/// the fastest and slowest measurements among the group for use with
/// master leases.
/// </summary>
/// <remarks>
/// <para>
/// Calling this method is optional, the default values for clock skew
/// assume no skew. The user must also configure leases via
/// <see cref="RepUseMasterLeases"/>. Additionally, the user must also
/// set the master lease timeout via <see cref="RepLeaseTimeout"/> and
/// the number of sites in the replication group via
/// <see cref="RepNSites"/>. These settings may be configured in any
/// order. For a description of the clock skew values, see Clock skew
/// in the Berkeley DB Programmer's Reference Guide. For a description
/// of master leases, see Master leases in the Berkeley DB Programmer's
/// Reference Guide.
/// </para>
/// <para>
/// These arguments can be used to express either raw measurements of a
/// clock timing experiment or a percentage across machines. For
/// instance a group of sites have a 2% variance, then
/// <paramref name="fast"/> should be set to 102, and
/// <paramref name="slow"/> should be set to 100. Or, for a 0.03%
/// difference, you can use 10003 and 10000 respectively.
/// </para>
/// </remarks>
/// <param name="fast">
/// The value, relative to <paramref name="slow"/>, of the fastest clock
/// in the group of sites.
/// </param>
/// <param name="slow">
/// The value of the slowest clock in the group of sites.
/// </param>
public void RepSetClockskew(uint fast, uint slow) {
dbenv.rep_set_clockskew(fast, slow);
}
/// <summary>
/// The amount of time the replication manager will wait before trying
/// to re-establish a connection to another site after a communication
/// failure. The default wait time is 30 seconds.
/// </summary>
public uint RepConnectionRetry {
get { return getRepTimeout(DbConstants.DB_REP_CONNECTION_RETRY); }
set {
dbenv.rep_set_timeout(
DbConstants.DB_REP_CONNECTION_RETRY, value);
}
}
/// <summary>
/// If true, the client should delay synchronizing to a newly declared
/// master (defaults to false). Clients configured in this way will remain
/// unsynchronized until the application calls <see cref="RepSync"/>.
/// </summary>
public bool RepDelayClientSync {
get { return getRepConfig(DbConstants.DB_REP_CONF_DELAYCLIENT); }
set {
dbenv.rep_set_config(
DbConstants.DB_REP_CONF_DELAYCLIENT, value ? 1 : 0);
}
}
/// <summary>
/// Configure the amount of time the replication manager will wait
/// before retrying a failed election. The default wait time is 10
/// seconds.
/// </summary>
public uint RepElectionRetry {
get { return getRepTimeout(DbConstants.DB_REP_ELECTION_RETRY); }
set {
dbenv.rep_set_timeout(DbConstants.DB_REP_ELECTION_RETRY, value);
}
}
/// <summary>
/// The timeout period for an election. The default timeout is 2
/// seconds.
/// </summary>
public uint RepElectionTimeout {
get { return getRepTimeout(DbConstants.DB_REP_ELECTION_TIMEOUT); }
set {
dbenv.rep_set_timeout(
DbConstants.DB_REP_ELECTION_TIMEOUT, value);
}
}
/// <summary>
/// An optional configuration timeout period to wait for full election
/// participation the first time the replication group finds a master.
/// By default this option is turned off and normal election timeouts
/// are used. (See the Elections section in the Berkeley DB Reference
/// Guide for more information.)
/// </summary>
public uint RepFullElectionTimeout {
get {
return getRepTimeout(
DbConstants.DB_REP_FULL_ELECTION_TIMEOUT);
}
set {
dbenv.rep_set_timeout(
DbConstants.DB_REP_FULL_ELECTION_TIMEOUT, value);
}
}
/// <summary>
/// The amount of time the replication manager, running at a client
/// site, waits for some message activity on the connection from the
/// master (heartbeats or other messages) before concluding that the
/// connection has been lost. When 0 (the default), no monitoring is
/// performed.
/// </summary>
public uint RepHeartbeatMonitor {
get { return getRepTimeout(DbConstants.DB_REP_HEARTBEAT_MONITOR); }
set {
dbenv.rep_set_timeout(
DbConstants.DB_REP_HEARTBEAT_MONITOR, value);
}
}
/// <summary>
/// The frequency at which the replication manager, running at a master
/// site, broadcasts a heartbeat message in an otherwise idle system.
/// When 0 (the default), no heartbeat messages will be sent.
/// </summary>
public uint RepHeartbeatSend {
get { return getRepTimeout(DbConstants.DB_REP_HEARTBEAT_SEND); }
set {
dbenv.rep_set_timeout(DbConstants.DB_REP_HEARTBEAT_SEND, value);
}
}
/// <summary>
/// If true, replication only stores the internal information in-memory
/// and cannot keep persistent state across a site crash or reboot. By
/// default, it is false and replication creates files in the
/// environment home directory to preserve the internal information.
/// </summary>
public bool RepInMemory {
get { return getRepConfig(DbConstants.DB_REP_CONF_INMEM); }
}
/// <summary>
/// The amount of time a client grants its master lease to a master.
/// When using master leases all sites in a replication group must use
/// the same lease timeout value. There is no default value. If leases
/// are desired, this method must be called prior to calling
/// <see cref="RepStartClient"/> or <see cref="RepStartMaster"/>.
/// </summary>
public uint RepLeaseTimeout {
get { return getRepTimeout(DbConstants.DB_REP_LEASE_TIMEOUT); }
set {
dbenv.rep_set_timeout(DbConstants.DB_REP_LEASE_TIMEOUT, value);
}
}
/// <summary>
/// Set the message dispatch function. It is responsible for receiving
/// messages sent from remote sites using either
/// <see cref="DbChannel.SendMessage"/> or <see cref="DbChannel.SendRequest"/>.
/// If the message received by this function was sent using
/// <see cref="DbChannel.SendMessage"/>, then no response is required.
/// If the message was sent using <see cref="DbChannel.SendRequest"/>,
/// then this function must send a response using
/// <see cref="DbChannel.SendMessage"/>.
/// </summary>
/// <remarks>
/// It should be called before the Replication Manager has been started.
/// </remarks>
public MessageDispatchDelegate RepMessageDispatch {
get { return messageDispatchHandler; }
set {
if (value == null)
dbenv.repmgr_msg_dispatch(null, 0);
else if (messageDispatchHandler == null) {
if (doMessageDispatchRef == null)
doMessageDispatchRef = new BDB_MessageDispatchDelegate(
doMessageDispatch);
dbenv.repmgr_msg_dispatch(doMessageDispatchRef, 0);
}
messageDispatchHandler = value;
}
}
/// <summary>
/// Specify how master and client sites will handle acknowledgment of
/// replication messages which are necessary for "permanent" records.
/// The current implementation requires all sites in a replication group
/// configure the same acknowledgement policy.
/// </summary>
/// <seealso cref="RepAckTimeout"/>
public AckPolicy RepMgrAckPolicy {
get {
int policy = 0;
dbenv.repmgr_get_ack_policy(ref policy);
return AckPolicy.fromInt(policy);
}
set { dbenv.repmgr_set_ack_policy(value.Policy); }
}
/// <summary>
/// Create DbChannel with given eid.
/// </summary>
/// <param name="eid">
/// Environment id. If the eid is <see cref="EnvironmentID.EID_MASTER"/>,
/// create channel sending to master site only.
/// </param>
public DbChannel RepMgrChannel(int eid) {
DB_CHANNEL dbChannel;
dbChannel = dbenv.repmgr_channel(eid, 0);
return new DbChannel(dbChannel);
}
/// <summary>
/// If true, Replication Manager automatically runs elections to
/// choose a new master when the old master appears to
/// have become disconnected (defaults to true).
/// </summary>
public bool RepMgrRunElections {
get { return getRepConfig(DbConstants.DB_REPMGR_CONF_ELECTIONS); }
set {
dbenv.rep_set_config(
DbConstants.DB_REPMGR_CONF_ELECTIONS, value ? 1 : 0);
}
}
/// <summary>
/// The local site of the replication manager. Returns null if the
/// local site has not been configured.
/// </summary>
public DbSite RepMgrLocalSite {
get {
DB_SITE site;
try {
site = dbenv.repmgr_local_site();
} catch (NotFoundException) {
// Local site wasn't set.
return null;
}
return new DbSite(site);
}
}
/// <summary>
/// The status of the sites currently known by the replication manager.
/// </summary>
public RepMgrSite[] RepMgrRemoteSites {
get { return dbenv.repmgr_site_list(); }
}
/// <summary>
/// If true, the replication master will automatically re-initialize
/// outdated clients (defaults to true).
/// </summary>
public bool RepAutoInit {
get { return getRepConfig(DbConstants.DB_REP_CONF_AUTOINIT); }
set {
dbenv.rep_set_config(
DbConstants.DB_REP_CONF_AUTOINIT, value ? 1 : 0);
}
}
/// <summary>
/// If true, Berkeley DB method calls that would normally block while
/// clients are in recovery will return errors immediately (defaults to
/// false).
/// </summary>
public bool RepNoBlocking {
get { return getRepConfig(DbConstants.DB_REP_CONF_NOWAIT); }
set {
dbenv.rep_set_config(
DbConstants.DB_REP_CONF_NOWAIT, value ? 1 : 0);
}
}
/// <summary>
/// The total number of sites in the replication group.
/// </summary>
/// <remarks>
/// <para>
/// This setting is typically used by applications which use the
/// Berkeley DB library "replication manager" support. (However, see
/// also <see cref="RepHoldElection"/>, the description of the nsites
/// parameter.)
/// </para>
/// </remarks>
public uint RepNSites {
get {
uint ret = 0;
dbenv.rep_get_nsites(ref ret);
return ret;
}
set { dbenv.rep_set_nsites(value); }
}
/// <summary>
/// The database environment's priority in replication group elections.
/// A special value of 0 indicates that this environment cannot be a
/// replication group master. If not configured, then a default value
/// of 100 is used.
/// </summary>
public uint RepPriority {
get {
uint ret = 0;
dbenv.rep_get_priority(ref ret);
return ret;
}
set { dbenv.rep_set_priority(value); }
}
/// <summary>
/// The minimum number of microseconds a client waits before requesting
/// retransmission.
/// </summary>
public uint RepRetransmissionRequestMin {
get {
uint min = 0;
uint max = 0;
dbenv.rep_get_request(ref min, ref max);
return min;
}
}
/// <summary>
/// The maximum number of microseconds a client waits before requesting
/// retransmission.
/// </summary>
public uint RepRetransmissionRequestMax {
get {
uint min = 0;
uint max = 0;
dbenv.rep_get_request(ref min, ref max);
return max;
}
}
/// <summary>
/// Set a threshold for the minimum and maximum time that a client waits
/// before requesting retransmission of a missing message.
/// </summary>
/// <remarks>
/// <para>
/// If the client detects a gap in the sequence of incoming log records
/// or database pages, Berkeley DB will wait for at least
/// <paramref name="min"/> microseconds before requesting retransmission
/// of the missing record. Berkeley DB will double that amount before
/// requesting the same missing record again, and so on, up to a
/// maximum threshold of <paramref name="max"/> microseconds.
/// </para>
/// <para>
/// These values are thresholds only. Since Berkeley DB has no thread
/// available in the library as a timer, the threshold is only checked
/// when a thread enters the Berkeley DB library to process an incoming
/// replication message. Any amount of time may have passed since the
/// last message arrived and Berkeley DB only checks whether the amount
/// of time since a request was made is beyond the threshold value or
/// not.
/// </para>
/// <para>
/// By default the minimum is 40000 and the maximum is 1280000 (1.28
/// seconds). These defaults are fairly arbitrary and the application
/// likely needs to adjust these. The values should be based on expected
/// load and performance characteristics of the master and client host
/// platforms and transport infrastructure as well as round-trip message
/// time.
/// </para></remarks>
/// <param name="min">
/// The minimum number of microseconds a client waits before requesting
/// retransmission.
/// </param>
/// <param name="max">
/// The maximum number of microseconds a client waits before requesting
/// retransmission.
/// </param>
public void RepSetRetransmissionRequest(uint min, uint max) {
dbenv.rep_set_request(min, max);
}
/// <summary>
/// Replication Manager observes the strict "majority" rule in managing
/// elections, even in a group with only 2 sites. This means the client
/// in a 2-site group will be unable to take over as master if the
/// original master fails or becomes disconnected. (See the Elections
/// section in the Berkeley DB Reference Guide for more information.)
/// Both sites in the replication group should have the same value for
/// this parameter.
/// </summary>
public bool RepStrict2Site {
get {
return getRepConfig(DbConstants.DB_REPMGR_CONF_2SITE_STRICT);
}
set {
dbenv.rep_set_config(
DbConstants.DB_REPMGR_CONF_2SITE_STRICT, value ? 1 : 0);
}
}
/// <summary>
/// The gigabytes component of the byte-count limit on the amount of
/// data that will be transmitted from a site in response to a single
/// message processed by <see cref="RepProcessMessage"/>.
/// </summary>
public uint RepTransmitLimitGBytes {
get {
uint gb = 0;
uint b = 0;
dbenv.rep_get_limit(ref gb, ref b);
return gb;
}
}
/// <summary>
/// The bytes component of the byte-count limit on the amount of data
/// that will be transmitted from a site in response to a single
/// message processed by <see cref="RepProcessMessage"/>.
/// </summary>
public uint RepTransmitLimitBytes {
get {
uint gb = 0;
uint b = 0;
dbenv.rep_get_limit(ref gb, ref b);
return b;
}
}
/// <summary>
/// Set a byte-count limit on the amount of data that will be
/// transmitted from a site in response to a single message processed by
/// <see cref="RepProcessMessage"/>. The limit is not a hard limit, and
/// the record that exceeds the limit is the last record to be sent.
/// </summary>
/// <remarks>
/// <para>
/// Record transmission throttling is turned on by default with a limit
/// of 10MB.
/// </para>
/// <para>
/// If both <paramref name="GBytes"/> and <paramref name="Bytes"/> are
/// zero, then the transmission limit is turned off.
/// </para>
/// </remarks>
/// <param name="GBytes">
/// The number of gigabytes which, when added to
/// <paramref name="Bytes"/>, specifies the maximum number of bytes that
/// will be sent in a single call to <see cref="RepProcessMessage"/>.
/// </param>
/// <param name="Bytes">
/// The number of bytes which, when added to
/// <paramref name="GBytes"/>, specifies the maximum number of bytes
/// that will be sent in a single call to
/// <see cref="RepProcessMessage"/>.
/// </param>
public void RepSetTransmitLimit(uint GBytes, uint Bytes) {
dbenv.rep_set_limit(GBytes, Bytes);
}
/// <summary>
/// The delegate used to transmit data using the replication
/// application's communication infrastructure.
/// </summary>
public ReplicationTransportDelegate RepTransport {
get { return transportHandler; }
}
/// <summary>
/// Initialize the communication infrastructure for a database
/// environment participating in a replicated application.
/// </summary>
/// <remarks>
/// RepSetTransport is not called by most replication applications. It
/// should only be called by applications implementing their own network
/// transport layer, explicitly holding replication group elections and
/// handling replication messages outside of the replication manager
/// framework.
/// </remarks>
/// <param name="envid">
/// The local environment's ID. It must be a non-negative integer and
/// uniquely identify this Berkeley DB database environment (see
/// Replication environment IDs in the Programmer's Reference Guide for
/// more information).
/// </param>
/// <param name="transport">
/// The delegate used to transmit data using the replication
/// application's communication infrastructure.
/// </param>
public void RepSetTransport(int envid,
ReplicationTransportDelegate transport) {
if (transport == null)
dbenv.rep_set_transport(envid, null);
else if (transportHandler == null) {
if (doRepTransportRef == null)
doRepTransportRef = new BDB_RepTransportDelegate(doRepTransport);
dbenv.rep_set_transport(envid, doRepTransportRef);
}
transportHandler = transport;
}
/// <summary>
/// If true, master leases will be used for this site (defaults to
/// false).
/// </summary>
/// <remarks>
/// Configuring this option may result in a
/// <see cref="LeaseExpiredException"/> when attempting to read entries
/// from a database after the site's master lease has expired.
/// </remarks>
public bool RepUseMasterLeases {
get { return getRepConfig(DbConstants.DB_REP_CONF_LEASE); }
set {
dbenv.rep_set_config(
DbConstants.DB_REP_CONF_LEASE, value ? 1 : 0);
}
}
/// <summary>
/// If true, catastrophic recovery was run on this environment before
/// opening it for normal use.
/// </summary>
public bool RunFatalRecovery {
get {
uint flags = 0;
dbenv.get_open_flags(ref flags);
return (flags & DbConstants.DB_RECOVER_FATAL) != 0;
}
}
/// <summary>
/// If true, normal recovery was run on this environment before opening
/// it for normal use.
/// </summary>
public bool RunRecovery {
get {
uint flags = 0;
dbenv.get_open_flags(ref flags);
return (flags & DbConstants.DB_RECOVER) != 0;
}
}
/// <summary>
/// The number of microseconds the thread of control will pause before
/// scheduling further write operations.
/// </summary>
public uint SequentialWritePause {
get {
int tmp = 0;
uint ret = 0;
dbenv.get_mp_max_write(ref tmp, ref ret);
return ret;
}
}
/// <summary>
/// A delegate that returns a unique identifier pair for the current
/// thread of control.
/// </summary>
/// <remarks>
/// This delegate supports <see cref="FailCheck"/>. For more
/// information, see Architecting Data Store and Concurrent Data Store
/// applications, and Architecting Transactional Data Store
/// applications, both in the Berkeley DB Programmer's Reference Guide.
/// </remarks>
public SetThreadIDDelegate SetThreadID {
get { return threadIDHandler; }
set {
if (value == null)
dbenv.set_thread_id(null);
else if (threadIDHandler == null) {
if (doThreadIDRef == null)
doThreadIDRef = new BDB_ThreadIDDelegate(doThreadID);
dbenv.set_thread_id(doThreadIDRef);
}
threadIDHandler = value;
}
}
/// <summary>
/// A delegate that formats a process ID and thread ID identifier pair.
/// </summary>
public SetThreadNameDelegate SetThreadName {
get { return threadNameHandler; }
set {
if (value == null)
dbenv.set_thread_id_string(null);
else if (threadNameHandler == null) {
if (doThreadNameRef == null)
doThreadNameRef =
new BDB_ThreadNameDelegate(doThreadName);
dbenv.set_thread_id_string(doThreadNameRef);
}
threadNameHandler = value;
}
}
/// <summary>
/// If true, allocate region memory from system shared memory instead of
/// from heap memory or memory backed by the filesystem.
/// </summary>
public bool SystemMemory {
get {
uint flags = 0;
dbenv.get_open_flags(ref flags);
return (flags & DbConstants.DB_SYSTEM_MEM) != 0;
}
}
/// <summary>
/// The path of a directory to be used as the location of temporary
/// files.
/// </summary>
/// <remarks>
/// <para>
/// The files created to back in-memory access method databases will be
/// created relative to this path. These temporary files can be quite
/// large, depending on the size of the database.
/// </para>
/// <para>
/// If no directories are specified, the following alternatives are
/// checked in the specified order. The first existing directory path is
/// used for all temporary files.
/// </para>
/// <list type="number">
/// <item>The value of the environment variable TMPDIR.</item>
/// <item>The value of the environment variable TEMP.</item>
/// <item>The value of the environment variable TMP.</item>
/// <item>The value of the environment variable TempFolder.</item>
/// <item>The value returned by the GetTempPath interface.</item>
/// <item>The directory /var/tmp.</item>
/// <item>The directory /usr/tmp.</item>
/// <item>The directory /temp.</item>
/// <item>The directory /tmp.</item>
/// <item>The directory C:/temp.</item>
/// <item>The directory C:/tmp.</item>
/// </list>
/// <para>
/// Environment variables are only checked if
/// <see cref="UseEnvironmentVars"/> is true.
/// </para>
/// </remarks>
public string TempDir {
get {
string ret;
dbenv.get_tmp_dir(out ret);
return ret;
}
set { dbenv.set_tmp_dir(value); }
}
/// <summary>
/// An approximate number of threads in the database environment.
/// </summary>
public uint ThreadCount {
get {
uint ret = 0;
dbenv.get_thread_count(ref ret);
return ret;
}
private set { dbenv.set_thread_count(value); }
}
/// <summary>
/// A delegate that returns if a thread of control (either a true thread
/// or a process) is still running.
/// </summary>
public ThreadIsAliveDelegate ThreadIsAlive {
get { return isAliveHandler; }
set {
if (value == null)
dbenv.set_isalive(null);
else if (isAliveHandler == null) {
if (doIsAliveRef == null)
doIsAliveRef = new BDB_IsAliveDelegate(doIsAlive);
dbenv.set_isalive(doIsAliveRef);
}
isAliveHandler = value;
}
}
/// <summary>
/// If true, database calls timing out based on lock or transaction
/// timeout values will throw <see cref="LockNotGrantedException"/>
/// instead of <see cref="DeadlockException"/>.
/// </summary>
/// <remarks>
/// If true, this allows applications to distinguish between operations
/// which have deadlocked and operations which have exceeded their time
/// limits.
/// </remarks>
public bool TimeNotGranted {
get {
uint flags = 0;
dbenv.get_flags(ref flags);
return (flags & DbConstants.DB_TIME_NOTGRANTED) != 0;
}
set {
dbenv.set_flags(DbConstants.DB_TIME_NOTGRANTED, value ? 1 : 0);
}
}
/// <summary>
/// If true, Berkeley DB will not write or synchronously flush the log
/// on transaction commit.
/// </summary>
/// <remarks>
/// This means that transactions exhibit the ACI (atomicity,
/// consistency, and isolation) properties, but not D (durability); that
/// is, database integrity will be maintained, but if the application or
/// system fails, it is possible some number of the most recently
/// committed transactions may be undone during recovery. The number of
/// transactions at risk is governed by how many log updates can fit
/// into the log buffer, how often the operating system flushes dirty
/// buffers to disk, and how often the log is checkpointed.
/// </remarks>
public bool TxnNoSync {
get {
uint flags = 0;
dbenv.get_flags(ref flags);
return (flags & DbConstants.DB_TXN_NOSYNC) != 0;
}
set { dbenv.set_flags(DbConstants.DB_TXN_NOSYNC, value ? 1 : 0); }
}
/// <summary>
/// If true and a lock is unavailable for any Berkeley DB operation
/// performed in the context of a transaction, cause the operation to
/// throw <see cref="DeadlockException"/> (or
/// <see cref="LockNotGrantedException"/> if configured with
/// <see cref="TimeNotGranted"/>).
/// </summary>
public bool TxnNoWait {
get {
uint flags = 0;
dbenv.get_flags(ref flags);
return (flags & DbConstants.DB_TXN_NOWAIT) != 0;
}
set { dbenv.set_flags(DbConstants.DB_TXN_NOWAIT, value ? 1 : 0); }
}
/// <summary>
/// If true, all transactions in the environment will be started as if
/// <see cref="TransactionConfig.Snapshot"/> was passed to
/// <see cref="BeginTransaction"/>, and all non-transactional cursors
/// will be opened as if <see cref="CursorConfig.SnapshotIsolation"/>
/// was passed to <see cref="BaseDatabase.Cursor"/>.
/// </summary>
public bool TxnSnapshot {
get {
uint flags = 0;
dbenv.get_flags(ref flags);
return (flags & DbConstants.DB_TXN_SNAPSHOT) != 0;
}
set { dbenv.set_flags(DbConstants.DB_TXN_SNAPSHOT, value ? 1 : 0); }
}
/// <summary>
/// A value, in microseconds, representing transaction timeouts.
/// </summary>
/// <remarks>
/// <para>
/// All timeouts are checked whenever a thread of control blocks on a
/// lock or when deadlock detection is performed. As timeouts are only
/// checked when the lock request first blocks or when deadlock
/// detection is performed, the accuracy of the timeout depends on how
/// often deadlock detection is performed.
/// </para>
/// <para>
/// Timeout values specified for the database environment may be
/// overridden on a per-transaction basis, see
/// <see cref="Transaction.SetTxnTimeout"/>.
/// </para>
/// </remarks>
public uint TxnTimeout {
get {
uint timeout = 0;
dbenv.get_timeout(ref timeout, DbConstants.DB_SET_TXN_TIMEOUT);
return timeout;
}
set {
dbenv.set_timeout(value, DbConstants.DB_SET_TXN_TIMEOUT);
}
}
/// <summary>
/// The recovery timestamp
/// </summary>
public DateTime TxnTimestamp {
get {
long secs = 0;
dbenv.get_tx_timestamp(ref secs);
DateTime epoch = new DateTime(1970, 1, 1);
DateTime ret = epoch.AddSeconds(secs);
return ret;
}
private set {
if (value != null) {
TimeSpan ts = value - new DateTime(1970, 1, 1);
long secs = (long)ts.TotalSeconds;
dbenv.set_tx_timestamp(ref secs);
}
}
}
/// <summary>
/// If true, Berkeley DB will write, but will not synchronously flush,
/// the log on transaction commit.
/// </summary>
/// <remarks>
/// This means that transactions exhibit the ACI (atomicity,
/// consistency, and isolation) properties, but not D (durability); that
/// is, database integrity will be maintained, but if the system fails,
/// it is possible some number of the most recently committed
/// transactions may be undone during recovery. The number of
/// transactions at risk is governed by how often the system flushes
/// dirty buffers to disk and how often the log is checkpointed.
/// </remarks>
public bool TxnWriteNoSync {
get {
uint flags = 0;
dbenv.get_flags(ref flags);
return (flags & DbConstants.DB_TXN_WRITE_NOSYNC) != 0;
}
set {
dbenv.set_flags(DbConstants.DB_TXN_WRITE_NOSYNC, value ? 1 : 0);
}
}
/// <summary>
/// If true, all databases in the environment will be opened as if
/// <see cref="DatabaseConfig.UseMVCC"/> was set.
/// </summary>
/// <remarks>
/// This flag will be ignored for queue databases for which MVCC is not
/// supported.
/// </remarks>
public bool UseMVCC {
get {
uint flags = 0;
dbenv.get_flags(ref flags);
return (flags & DbConstants.DB_MULTIVERSION) != 0;
}
set { dbenv.set_flags(DbConstants.DB_MULTIVERSION, value ? 1 : 0); }
}
/// <summary>
/// If true, locking for the Berkeley DB Concurrent Data Store product
/// was initialized.
/// </summary>
public bool UsingCDB {
get {
uint flags = 0;
dbenv.get_open_flags(ref flags);
return (flags & DbConstants.DB_INIT_CDB) != 0;
}
}
/// <summary>
/// If true, the locking subsystem was initialized.
/// </summary>
public bool UsingLocking {
get {
uint flags = 0;
dbenv.get_open_flags(ref flags);
return (flags & DbConstants.DB_INIT_LOCK) != 0;
}
}
/// <summary>
/// If true, the logging subsystem was initialized.
/// </summary>
public bool UsingLogging {
get {
uint flags = 0;
dbenv.get_open_flags(ref flags);
return (flags & DbConstants.DB_INIT_LOG) != 0;
}
}
/// <summary>
/// If true, the shared memory buffer pool subsystem was initialized.
/// </summary>
public bool UsingMPool {
get {
uint flags = 0;
dbenv.get_open_flags(ref flags);
return (flags & DbConstants.DB_INIT_MPOOL) != 0;
}
}
/// <summary>
/// If true, the replication subsystem was initialized.
/// </summary>
public bool UsingReplication {
get {
uint flags = 0;
dbenv.get_open_flags(ref flags);
return (flags & DbConstants.DB_INIT_REP) != 0;
}
}
/// <summary>
/// If true, the transaction subsystem was initialized.
/// </summary>
public bool UsingTxns {
get {
uint flags = 0;
dbenv.get_open_flags(ref flags);
return (flags & DbConstants.DB_INIT_TXN) != 0;
}
}
/// <summary>
/// Specific additional informational and debugging messages in the
/// Berkeley DB message output.
/// </summary>
public VerboseMessages Verbosity {
get {
uint flags = 0;
dbenv.get_verbose(ref flags);
return VerboseMessages.FromFlags(flags);
}
set {
if (value.MessagesOff != 0)
dbenv.set_verbose(value.MessagesOff, 0);
if (value.MessagesOn != 0)
dbenv.set_verbose(value.MessagesOn, 1);
}
}
/// <summary>
/// If true, Berkeley DB will yield the processor immediately after each
/// page or mutex acquisition.
/// </summary>
/// <remarks>
/// This functionality should never be used for purposes other than
/// stress testing.
/// </remarks>
public bool YieldCPU {
get {
uint flags = 0;
dbenv.get_flags(ref flags);
return (flags & DbConstants.DB_YIELDCPU) != 0;
}
set {
dbenv.set_flags(DbConstants.DB_YIELDCPU, value ? 1 : 0);
}
}
#endregion Properties
/// <summary>
/// Instantiate a new DatabaseEnvironment object and open the Berkeley
/// DB environment represented by <paramref name="home"/>.
/// </summary>
/// <param name="home">
/// The database environment's home directory. For more information on
/// home, and filename resolution in general, see Berkeley DB File
/// Naming in the Programmer's Reference Guide.
/// </param>
/// <param name="cfg">The environment's configuration</param>
/// <returns>A new, open DatabaseEnvironment object</returns>
public static DatabaseEnvironment Open(
String home, DatabaseEnvironmentConfig cfg) {
DatabaseEnvironment env = new DatabaseEnvironment(0);
env.Config(cfg);
env.dbenv.open(home, cfg.openFlags, 0);
return env;
}
/// <summary>
/// Destroy a Berkeley DB environment if it is not currently in use.
/// </summary>
/// <overloads>
/// <para>
/// The environment regions, including any backing files, are removed.
/// Any log or database files and the environment directory are not
/// removed.
/// </para>
/// <para>
/// If there are processes that have called <see cref="Open"/> without
/// calling <see cref="Close"/> (that is, there are processes currently
/// using the environment), Remove will fail without further action.
/// </para>
/// <para>
/// Calling Remove should not be necessary for most applications because
/// the Berkeley DB environment is cleaned up as part of normal database
/// recovery procedures. However, applications may want to call Remove
/// as part of application shut down to free up system resources. For
/// example, if <see cref="DatabaseEnvironmentConfig.SystemMemory"/> was
/// specified to <see cref="Open"/>, it may be useful to call Remove in
/// order to release system shared memory segments that have been
/// allocated. Or, on architectures in which mutexes require allocation
/// of underlying system resources, it may be useful to call Remove in
/// order to release those resources. Alternatively, if recovery is not
/// required because no database state is maintained across failures,
/// and no system resources need to be released, it is possible to clean
/// up an environment by simply removing all the Berkeley DB files in
/// the database environment's directories.
/// </para>
/// <para>
/// In multithreaded applications, only a single thread may call Remove.
/// </para>
/// </overloads>
/// <param name="db_home">
/// The database environment to be removed.
/// </param>
public static void Remove(string db_home) {
Remove(db_home, false, false, false);
}
/// <summary>
/// Destroy a Berkeley DB environment if it is not currently in use.
/// </summary>
/// <remarks>
/// <para>
/// Generally, <paramref name="force"/> is specified only when
/// applications were unable to shut down cleanly, and there is a risk
/// that an application may have died holding a Berkeley DB lock.)
/// </para>
/// <para>
/// The result of attempting to forcibly destroy the environment when it
/// is in use is unspecified. Processes using an environment often
/// maintain open file descriptors for shared regions within it. On UNIX
/// systems, the environment removal will usually succeed, and processes
/// that have already joined the region will continue to run in that
/// region without change. However, processes attempting to join the
/// environment will either fail or create new regions. On other systems
/// in which the unlink(2) system call will fail if any process has an
/// open file descriptor for the file (for example Windows/NT), the
/// region removal will fail.
/// </para>
/// </remarks>
/// <param name="db_home">
/// The database environment to be removed.
/// </param>
/// <param name="force">
/// If true, the environment is removed, regardless of any processes
/// that may still using it, and no locks are acquired during this
/// process.
/// </param>
public static void Remove(string db_home, bool force) {
Remove(db_home, force, false, false);
}
private static void Remove(string db_home,
bool force, bool USE_ENVIRON, bool USE_ENVIRON_ROOT) {
DatabaseEnvironment env = new DatabaseEnvironment(0);
uint flags = 0;
flags |= force ? DbConstants.DB_FORCE : 0;
flags |= USE_ENVIRON ? DbConstants.DB_USE_ENVIRON : 0;
flags |= USE_ENVIRON_ROOT ? DbConstants.DB_USE_ENVIRON_ROOT : 0;
env.dbenv.remove(db_home, flags);
}
/// <summary>
/// Perform a hot back up of the open environment.
/// <para>
/// All files used by the environment are backed up, so long as the
/// normal rules for file placement are followed. For information on how
/// files are normally placed relative to the environment directory, see
/// the "Berkeley DB File Naming" section in the Berkeley DB Reference
/// Guide.
/// </para>
/// <para>
/// By default, data directories and the log directory specified
/// relative to the home directory will be recreated relative to the
/// target directory. If absolute path names are used, then use the
/// <see cref="BackupOptions.SingleDir"/> method.
/// </para>
/// <para>
/// This method provides the same functionality as the db_hotbackup
/// utility. However, this method does not perform the housekeeping
/// actions performed by that utility. In particular, you may want to
/// run a checkpoint before calling this method. To run a checkpoint,
/// use the <see cref="DatabaseEnvironment.Checkpoint"/> method. For
/// more information on checkpoints, see the "Checkpoint" section in the
/// Berkeley DB Reference Guide.
/// </para>
/// <para>
/// To back up a single database file within the environment, use the
/// <see cref="DatabaseEnvironment.BackupDatabase"/> method.
/// </para>
/// <para>
/// In addition to the configuration options available using the
/// <see cref="BackupOptions"/> class, additional tuning modifications
/// can be made using the <see cref="DatabaseEnvironment.BackupReadCount"/>,
/// <see cref="DatabaseEnvironment.BackupReadSleepDuration"/>,
/// <see cref="DatabaseEnvironment.BackupBufferSize"/>, and
/// <see cref="DatabaseEnvironment.BackupWriteDirect"/> properties.
/// Alternatively, you can write your own custom hot back up facility
/// using the <see cref="IBackup"/> interface.
/// </para>
/// </summary>
/// <param name="target">Identifies the directory in which the back up
/// will be placed. Any subdirectories required to contain the back up
/// must be placed relative to this directory. Note that if an
/// <see cref="IBackup"/> is configured for the environment, then the
/// value specified to this parameter is passed on to the
/// <see cref="IBackup.Open"/> method. If this parameter is null, then
/// the target must be specified to the <see cref="IBackup.Open"/>
/// method.
/// <para>
/// This directory, and any required subdirectories, will be created for
/// you if you specify <see cref="CreatePolicy.IF_NEEDED"/> or
/// <see cref="CreatePolicy.ALWAYS"/> for the
/// <see cref="BackupOptions.Creation"/> property.
/// </para>
/// </param>
/// <param name="opt">The <see cref="BackupOptions"/> instance used to
/// configure the hot back up.</param>
public void Backup(string target, BackupOptions opt) {
dbenv.backup(target, opt.flags);
}
/// <summary>
/// Perform a hot back up of a single database file contained within the
/// environment.
/// <para>
/// To back up the entire environment, use the
/// <see cref="DatabaseEnvironment.Backup"/> method.
/// </para>
/// <para>
/// You can make some tuning modifications to the backup process using
/// the <see cref="DatabaseEnvironment.BackupReadCount"/>,
/// <see cref="DatabaseEnvironment.BackupReadSleepDuration"/>,
/// <see cref="DatabaseEnvironment.BackupBufferSize"/>, and
/// <see cref="DatabaseEnvironment.BackupWriteDirect"/> properties.
/// Alternatively, you can write your own custom hot back up facility
/// using the <see cref="IBackup"/> interface.
/// </para>
/// </summary>
/// <param name="target">Identifies the directory in which the back up
/// will be placed.</param>
/// <param name="database">The database file that you want to back up.
/// </param>
/// <param name="must_create">If true, then if the target file exists,
/// this method throws an exception.</param>
public void BackupDatabase(
string target, string database, bool must_create) {
dbenv.dbbackup(
database, target, must_create ? DbConstants.DB_EXCL : 0);
}
/// <summary>
/// Hold an election for the master of a replication group.
/// </summary>
public void RepHoldElection() {
RepHoldElection(0, 0);
}
/// <summary>
/// Hold an election for the master of a replication group.
/// </summary>
/// <param name="nsites">
/// The number of replication sites expected to participate in the
/// election. Once the current site has election information from that
/// many sites, it will short-circuit the election and immediately cast
/// its vote for a new master. If an application is using master leases,
/// then the value must be 0 and <see cref="RepNSites"/> must be used.
/// </param>
public void RepHoldElection(uint nsites) {
RepHoldElection(nsites, 0);
}
/// <summary>
/// Hold an election for the master of a replication group.
/// </summary>
/// <overloads>
/// <para>
/// RepHoldElection is not called by most replication applications. It
/// should only be called by applications implementing their own network
/// transport layer, explicitly holding replication group elections and
/// handling replication messages outside of the replication manager
/// framework.
/// </para>
/// <para>
/// If the election is successful, Berkeley DB will notify the
/// application of the results of the election by means of either the
/// <see cref="NotificationEvent.REP_ELECTED"/> or
/// <see cref="NotificationEvent.REP_NEWMASTER"/> events (see
/// <see cref="EventNotify"/>for more information). The application is
/// responsible for adjusting its relationship to the other database
/// environments in the replication group, including directing all
/// database updates to the newly selected master, in accordance with
/// the results of the election.
/// </para>
/// <para>
/// The thread of control that calls RepHoldElection must not be the
/// thread of control that processes incoming messages; processing the
/// incoming messages is necessary to successfully complete an election.
/// </para>
/// <para>
/// Before calling this method, the <see cref="RepTransport"/> delegate
/// must already have been configured to send replication messages.
/// </para>
/// </overloads>
/// <param name="nsites">
/// The number of replication sites expected to participate in the
/// election. Once the current site has election information from that
/// many sites, it will short-circuit the election and immediately cast
/// its vote for a new master. This parameter must be no less than
/// <paramref name="nvotes"/>, or 0 if the election should use
/// <see cref="RepNSites"/>. If an application is using master leases,
/// then the value must be 0 and <see cref="RepNSites"/> must be used.
/// </param>
/// <param name="nvotes">
/// The minimum number of replication sites from which the current site
/// must have election information, before the current site will cast a
/// vote for a new master. This parameter must be no greater than
/// <paramref name="nsites"/>, or 0 if the election should use the value
/// ((<paramref name="nsites"/> / 2) + 1).
/// </param>
public void RepHoldElection(uint nsites, uint nvotes) {
dbenv.rep_elect(nsites, nvotes, 0);
}
/// <summary>
/// Configure a site in the replication manager.
/// </summary>
/// <param name="siteConfig">The configuration of a site</param>
public void RepMgrSiteConfig(DbSiteConfig siteConfig) {
DB_SITE dbSite;
dbSite = dbenv.repmgr_site(siteConfig.Host, siteConfig.Port);
if (siteConfig.helperIsSet)
dbSite.set_config(DbConstants.DB_BOOTSTRAP_HELPER,
Convert.ToUInt32(siteConfig.Helper));
if (siteConfig.groupCreatorIsSet)
dbSite.set_config(DbConstants.DB_GROUP_CREATOR,
Convert.ToUInt32(siteConfig.GroupCreator));
if (siteConfig.legacyIsSet)
dbSite.set_config(DbConstants.DB_LEGACY,
Convert.ToUInt32(siteConfig.Legacy));
if (siteConfig.localSiteIsSet)
dbSite.set_config(DbConstants.DB_LOCAL_SITE,
Convert.ToUInt32(siteConfig.LocalSite));
if (siteConfig.peerIsSet)
dbSite.set_config(DbConstants.DB_REPMGR_PEER,
Convert.ToUInt32(siteConfig.Peer));
dbSite.close();
}
/// <summary>
/// Create DbSite with the given eid.
/// </summary>
/// <remarks>
/// It is only possible to use this method after env open, because EID
/// values are not established before that time.
/// </remarks>
/// <param name="eid">The environment id</param>
public DbSite RepMgrSite(int eid) {
DB_SITE dbSite;
dbSite = dbenv.repmgr_site_by_eid(eid);
return new DbSite(dbSite);
}
/// <summary>
/// Create DbSite with the given host and port.
/// </summary>
/// <param name="host">The host address</param>
/// <param name="port">The port</param>
public DbSite RepMgrSite(string host, uint port) {
DB_SITE dbSite;
dbSite = dbenv.repmgr_site(host, port);
return new DbSite(dbSite);
}
/// <summary>
/// Start the replication manager as a client site, and do not call for
/// an election.
/// </summary>
/// <overloads>
/// <para>
/// There are two ways to build Berkeley DB replication applications:
/// the most common approach is to use the Berkeley DB library
/// "replication manager" support, where the Berkeley DB library manages
/// the replication group, including network transport, all replication
/// message processing and acknowledgment, and group elections.
/// Applications using the replication manager support generally make
/// the following calls:
/// </para>
/// <list type="number">
/// <item>
/// Configure the local site in the replication group,
/// <see cref="RepMgrLocalSite"/>.
/// </item>
/// <item>
/// Call <see cref="RepMgrSiteConfig"/> to configure the remote
/// site(s) in the replication group.
/// </item>
/// <item>Configure the message acknowledgment policy
/// (<see cref="RepMgrAckPolicy"/>) which provides the replication group's
/// transactional needs.
/// </item>
/// <item>
/// Configure the local site's election priority,
/// <see cref="RepPriority"/>.
/// </item>
/// <item>
/// Call <see cref="RepMgrStartClient"/> or
/// <see cref="RepMgrStartMaster"/> to start the replication
/// application.
/// </item>
/// </list>
/// <para>
/// For more information on building replication manager applications,
/// please see the Replication Getting Started Guide included in the
/// Berkeley DB documentation.
/// </para>
/// <para>
/// Applications with special needs (for example, applications using
/// network protocols not supported by the Berkeley DB replication
/// manager), must perform additional configuration and call other
/// Berkeley DB replication methods. For more information on building
/// advanced replication applications, please see the Base Replication
/// API section in the Berkeley DB Programmer's Reference Guide for more
/// information.
/// </para>
/// <para>
/// Starting the replication manager consists of opening the TCP/IP
/// listening socket to accept incoming connections, and starting all
/// necessary background threads. When multiple processes share a
/// database environment, only one process can open the listening
/// socket; <see cref="RepMgrStartClient"/> (and
/// <see cref="RepMgrStartMaster"/>) automatically open the socket in
/// the first process to call it, and skips this step in the later calls
/// from other processes.
/// </para>
/// </overloads>
/// <param name="nthreads">
/// Specify the number of threads of control created and dedicated to
/// processing replication messages. In addition to these message
/// processing threads, the replication manager creates and manages a
/// few of its own threads of control.
/// </param>
public void RepMgrStartClient(int nthreads) {
RepMgrStartClient(nthreads, false);
}
/// <summary>
/// Start the replication manager as a client site, and optionally call
/// for an election.
/// </summary>
/// <param name="nthreads">
/// Specify the number of threads of control created and dedicated to
/// processing replication messages. In addition to these message
/// processing threads, the replication manager creates and manages a
/// few of its own threads of control.
/// </param>
/// <param name="holdElection">
/// If true, start as a client, and call for an election if no master is
/// found.
/// </param>
public void RepMgrStartClient(int nthreads, bool holdElection) {
dbenv.repmgr_start(nthreads,
holdElection ?
DbConstants.DB_REP_ELECTION : DbConstants.DB_REP_CLIENT);
}
/// <summary>
/// Start the replication manager as a master site, and do not call for
/// an election.
/// </summary>
/// <remarks>
/// <para>
/// There are two ways to build Berkeley DB replication applications:
/// the most common approach is to use the Berkeley DB library
/// "replication manager" support, where the Berkeley DB library manages
/// the replication group, including network transport, all replication
/// message processing and acknowledgment, and group elections.
/// Applications using the replication manager support generally make
/// the following calls:
/// </para>
/// <list type="number">
/// <item>
/// Configure the local site in the replication group,
/// <see cref="RepMgrLocalSite"/>.
/// </item>
/// <item>
/// Call <see cref="RepMgrSiteConfig"/> to configure the remote
/// site(s) in the replication group.
/// </item>
/// <item>Configure the message acknowledgment policy
/// (<see cref="RepMgrAckPolicy"/>) which provides the replication group's
/// transactional needs.
/// </item>
/// <item>
/// Configure the local site's election priority,
/// <see cref="RepPriority"/>.
/// </item>
/// <item>
/// Call <see cref="RepMgrStartClient"/> or
/// <see cref="RepMgrStartMaster"/> to start the replication
/// application.
/// </item>
/// </list>
/// <para>
/// For more information on building replication manager applications,
/// please see the Replication Getting Started Guide included in the
/// Berkeley DB documentation.
/// </para>
/// <para>
/// Applications with special needs (for example, applications using
/// network protocols not supported by the Berkeley DB replication
/// manager), must perform additional configuration and call other
/// Berkeley DB replication methods. For more information on building
/// advanced replication applications, please see the Base Replication
/// API section in the Berkeley DB Programmer's Reference Guide for more
/// information.
/// </para>
/// <para>
/// Starting the replication manager consists of opening the TCP/IP
/// listening socket to accept incoming connections, and starting all
/// necessary background threads. When multiple processes share a
/// database environment, only one process can open the listening
/// socket; <see cref="RepMgrStartMaster"/> (and
/// <see cref="RepMgrStartClient"/>) automatically open the socket in
/// the first process to call it, and skips this step in the later calls
/// from other processes.
/// </para>
/// </remarks>
/// <param name="nthreads">
/// Specify the number of threads of control created and dedicated to
/// processing replication messages. In addition to these message
/// processing threads, the replication manager creates and manages a
/// few of its own threads of control.
/// </param>
public void RepMgrStartMaster(int nthreads) {
dbenv.repmgr_start(nthreads, DbConstants.DB_REP_MASTER);
}
/// <summary>
/// Process an incoming replication message sent by a member of the
/// replication group to the local database environment.
/// </summary>
/// <remarks>
/// <para>
/// RepProcessMessage is not called by most replication applications. It
/// should only be called by applications implementing their own network
/// transport layer, explicitly holding replication group elections and
/// handling replication messages outside of the replication manager
/// framework.
/// </para>
/// <para>
/// For implementation reasons, all incoming replication messages must
/// be processed using the same <see cref="DatabaseEnvironment"/>
/// object. It is not required that a single thread of control process
/// all messages, only that all threads of control processing messages
/// use the same object.
/// </para>
/// <para>
/// Before calling this method, the <see cref="RepTransport"/> delegate
/// must already have been configured to send replication messages.
/// </para>
/// </remarks>
/// <param name="control">
/// A copy of the control parameter specified by Berkeley DB on the
/// sending environment.
/// </param>
/// <param name="rec">
/// A copy of the rec parameter specified by Berkeley DB on the sending
/// environment.
/// </param>
/// <param name="envid">
/// The local identifier that corresponds to the environment that sent
/// the message to be processed (see Replication environment IDs in the
/// Programmer's Reference Guide for more information)..
/// </param>
/// <returns>The result of processing a message</returns>
public RepProcMsgResult RepProcessMessage(
DatabaseEntry control, DatabaseEntry rec, int envid) {
DB_LSN dblsn = new DB_LSN();
int ret = dbenv.rep_process_message(control,
rec, envid, dblsn);
LSN lsnp = new LSN(dblsn.file, dblsn.offset);
RepProcMsgResult result = new RepProcMsgResult(ret, lsnp);
if (result.Result == RepProcMsgResult.ProcMsgResult.ERROR)
DatabaseException.ThrowException(ret);
return result;
}
/// <summary>
/// Configure the database environment as a client in a group of
/// replicated database environments.
/// </summary>
public void RepStartClient() {
RepStartClient(null);
}
/// <summary>
/// Configure the database environment as a client in a group of
/// replicated database environments.
/// </summary>
/// <overloads>
/// <para>
/// RepStartClient is not called by most replication applications. It
/// should only be called by applications implementing their own network
/// transport layer, explicitly holding replication group elections and
/// handling replication messages outside of the replication manager
/// framework.
/// </para>
/// <para>
/// Replication master environments are the only database environments
/// where replicated databases may be modified. Replication client
/// environments are read-only as long as they are clients. Replication
/// client environments may be upgraded to be replication master
/// environments in the case that the current master fails or there is
/// no master present. If master leases are in use, this method cannot
/// be used to appoint a master, and should only be used to configure a
/// database environment as a master as the result of an election.
/// </para>
/// <para>
/// Before calling this method, the <see cref="RepTransport"/> delegate
/// must already have been configured to send replication messages.
/// </para>
/// </overloads>
/// <param name="cdata">
/// An opaque data item that is sent over the communication
/// infrastructure when the client comes online (see Connecting to a new
/// site in the Programmer's Reference Guide for more information). If
/// no such information is useful, cdata should be null.
/// </param>
public void RepStartClient(DatabaseEntry cdata) {
dbenv.rep_start(
cdata, DbConstants.DB_REP_CLIENT);
}
/// <summary>
/// Configure the database environment as a master in a group of
/// replicated database environments.
/// </summary>
public void RepStartMaster() {
RepStartMaster(null);
}
/// <summary>
/// Configure the database environment as a master in a group of
/// replicated database environments.
/// </summary>
/// <overloads>
/// <para>
/// RepStartMaster is not called by most replication applications. It
/// should only be called by applications implementing their own network
/// transport layer, explicitly holding replication group elections and
/// handling replication messages outside of the replication manager
/// framework.
/// </para>
/// <para>
/// Replication master environments are the only database environments
/// where replicated databases may be modified. Replication client
/// environments are read-only as long as they are clients. Replication
/// client environments may be upgraded to be replication master
/// environments in the case that the current master fails or there is
/// no master present. If master leases are in use, this method cannot
/// be used to appoint a master, and should only be used to configure a
/// database environment as a master as the result of an election.
/// </para>
/// <para>
/// Before calling this method, the <see cref="RepTransport"/> delegate
/// must already have been configured to send replication messages.
/// </para>
/// </overloads>
/// <param name="cdata">
/// An opaque data item that is sent over the communication
/// infrastructure when the client comes online (see Connecting to a new
/// site in the Programmer's Reference Guide for more information). If
/// no such information is useful, cdata should be null.
/// </param>
public void RepStartMaster(DatabaseEntry cdata) {
dbenv.rep_start(
cdata, DbConstants.DB_REP_MASTER);
}
/// <summary>
/// Force master synchronization to begin for this client.
/// </summary>
/// <remarks>
/// <para>
/// This method is the other half of setting
/// <see cref="RepDelayClientSync"/>.
/// </para>
/// <para>
/// If an application has configured delayed master synchronization, the
/// application must synchronize explicitly (otherwise the client will
/// remain out-of-date and will ignore all database changes forwarded
/// from the replication group master). RepSync may be called any time
/// after the client application learns that the new master has been
/// established (by receiving
/// <see cref="NotificationEvent.REP_NEWMASTER"/>).
/// </para>
/// <para>
/// Before calling this method, the <see cref="RepTransport"/> delegate
/// must already have been configured to send replication messages.
/// </para>
/// </remarks>
public void RepSync() {
dbenv.rep_sync(0);
}
/// <summary>
/// The names of all of the log files that are no longer in use (for
/// example, that are no longer involved in active transactions), and
/// that may safely be archived for catastrophic recovery and then
/// removed from the system.
/// </summary>
/// <remarks>
/// <para>
/// The Berkeley DB interfaces to the database environment logging
/// subsystem (for example, <see cref="Transaction.Abort"/>) may
/// allocate log cursors and have open file descriptors for log files
/// as well. On operating systems where filesystem related system calls
/// (for example, rename and unlink on Windows/NT) can fail if a process
/// has an open file descriptor for the affected file, attempting to
/// move or remove the log files listed by ArchivableLogFiles may fail.
/// All Berkeley DB internal use of log cursors operates on active log
/// files only and furthermore, is short-lived in nature. So, an
/// application seeing such a failure should be restructured to retry
/// the operation until it succeeds. (Although this is not likely to be
/// necessary; it is hard to imagine a reason to move or rename a log
/// file in which transactions are being logged or aborted.)
/// </para>
/// <para>
/// When Replication Manager is in use, log archiving will be performed
/// in a replication group-aware manner such that the log file status of
/// other sites in the group will be considered to determine if a log
/// file could be in use.
/// </para>
/// <para>
/// See the db_archive utility for more information on database archival
/// procedures.
/// </para>
/// </remarks>
/// <param name="AbsolutePaths">
/// If true, all pathnames are returned as absolute pathnames, instead
/// of relative to the database home directory.
/// </param>
/// <returns>
/// The names of all of the log files that are no longer in use
/// </returns>
public List<string> ArchivableLogFiles(bool AbsolutePaths) {
uint flags = 0;
flags |= AbsolutePaths ? DbConstants.DB_ARCH_ABS : 0;
return dbenv.log_archive(flags);
}
/// <summary>
/// The database files that need to be archived in order to recover the
/// database from catastrophic failure. If any of the database files
/// have not been accessed during the lifetime of the current log files,
/// they will not included in this list. It is also possible that some
/// of the files referred to by the log have since been deleted from the
/// system.
/// </summary>
/// <remarks>
/// <para>
/// When Replication Manager is in use, log archiving will be performed
/// in a replication group-aware manner such that the log file status of
/// other sites in the group will be considered to determine if a log
/// file could be in use.
/// </para>
/// <para>
/// See the db_archive utility for more information on database archival
/// procedures.
/// </para>
/// </remarks>
/// <param name="AbsolutePaths">
/// If true, all pathnames are returned as absolute pathnames, instead
/// of relative to the database home directory.
/// </param>
/// <returns>
/// The database files that need to be archived in order to recover the
/// database from catastrophic failure.
/// </returns>
public List<string> ArchivableDatabaseFiles(bool AbsolutePaths) {
uint flags = DbConstants.DB_ARCH_DATA;
flags |= AbsolutePaths ? DbConstants.DB_ARCH_ABS : 0;
return dbenv.log_archive(flags);
}
/// <summary>
/// The names of all of the log files
/// </summary>
/// <remarks>
/// <para>
/// The Berkeley DB interfaces to the database environment logging
/// subsystem (for example, <see cref="Transaction.Abort"/>) may
/// allocate log cursors and have open file descriptors for log files
/// as well. On operating systems where filesystem related system calls
/// (for example, rename and unlink on Windows/NT) can fail if a process
/// has an open file descriptor for the affected file, attempting to
/// move or remove the log files listed by LogFiles may fail. All
/// Berkeley DB internal use of log cursors operates on active log files
/// only and furthermore, is short-lived in nature. So, an application
/// seeing such a failure should be restructured to retry the operation
/// until it succeeds. (Although this is not likely to be necessary; it
/// is hard to imagine a reason to move or rename a log file in which
/// transactions are being logged or aborted.)
/// </para>
/// <para>
/// See the db_archive utility for more information on database archival
/// procedures.
/// </para>
/// </remarks>
/// <param name="AbsolutePaths">
/// If true, all pathnames are returned as absolute pathnames, instead
/// of relative to the database home directory.
/// </param>
/// <returns>
/// All the log filenames, regardless of whether or not they are in use.
/// </returns>
public List<string> LogFiles(bool AbsolutePaths) {
uint flags = DbConstants.DB_ARCH_LOG;
flags |= AbsolutePaths ? DbConstants.DB_ARCH_ABS : 0;
return dbenv.log_archive(flags);
}
/// <summary>
/// Remove log files that are no longer needed. Automatic log file
/// removal is likely to make catastrophic recovery impossible.
/// </summary>
/// <remarks>
/// <para>
/// When Replication Manager is in use, log archiving will be performed
/// in a replication group-aware manner such that the log file status of
/// other sites in the group will be considered to determine if a log
/// file could be in use.
/// </para>
/// </remarks>
public void RemoveUnusedLogFiles() {
dbenv.log_archive(DbConstants.DB_ARCH_REMOVE);
}
/// <summary>
/// Allocate a locker ID in an environment configured for Berkeley DB
/// Concurrent Data Store applications.
/// </summary>
/// <remarks>
/// <para>
/// Calling <see cref="Transaction.Commit"/> will discard the allocated
/// locker ID.
/// </para>
/// <para>
/// See Berkeley DB Concurrent Data Store applications in the
/// Programmer's Reference Guide for more information about when this is
/// required.
/// </para>
/// </remarks>
/// <returns>
/// A Transaction object that uniquely identifies the locker ID
/// </returns>
public Transaction BeginCDSGroup() {
return new Transaction(dbenv.cdsgroup_begin());
}
/// <summary>
/// Create a new transaction in the environment, with the default
/// configuration.
/// </summary>
/// <returns>A new transaction object</returns>
public Transaction BeginTransaction() {
return BeginTransaction(new TransactionConfig(), null);
}
/// <summary>
/// Create a new transaction in the environment.
/// </summary>
/// <param name="cfg">
/// The configuration properties for the transaction
/// </param>
/// <returns>A new transaction object</returns>
public Transaction BeginTransaction(TransactionConfig cfg) {
return BeginTransaction(cfg, null);
}
/// <summary>
/// Create a new transaction in the environment.
/// </summary>
/// <remarks>
/// In the presence of distributed transactions and two-phase commit,
/// only the parental transaction, that is a transaction without a
/// parent specified, should be passed as an parameter to
/// <see cref="Transaction.Prepare"/>.
/// </remarks>
/// <param name="cfg">
/// The configuration properties for the transaction
/// </param>
/// <param name="parent">
/// If the non-null, the new transaction will be a nested transaction,
/// with <paramref name="parent"/> as the new transaction's parent.
/// Transactions may be nested to any level.
/// </param>
/// <returns>A new transaction object</returns>
public Transaction BeginTransaction(
TransactionConfig cfg, Transaction parent) {
DB_TXN dbtxn = dbenv.txn_begin(
Transaction.getDB_TXN(parent), cfg.flags);
Transaction txn = new Transaction(dbtxn);
if (cfg.lockTimeoutIsSet)
txn.SetLockTimeout(cfg.LockTimeout);
if (cfg.nameIsSet)
txn.Name = cfg.Name;
if (cfg.txnTimeoutIsSet)
txn.SetTxnTimeout(cfg.TxnTimeout);
return txn;
}
/// <summary>
/// Flush the underlying memory pool, write a checkpoint record to the
/// log, and then flush the log, even if there has been no activity
/// since the last checkpoint.
/// </summary>
public void Checkpoint() {
dbenv.txn_checkpoint(0, 0, DbConstants.DB_FORCE);
}
/// <summary>
/// If there has been any logging activity in the database environment
/// since the last checkpoint, flush the underlying memory pool, write a
/// checkpoint record to the log, and then flush the log.
/// </summary>
/// <param name="kbytesWritten">
/// A checkpoint will be done if more than kbytesWritten kilobytes of
/// log data have been written since the last checkpoint.
/// </param>
/// <param name="minutesElapsed">
/// A checkpoint will be done if more than minutesElapsed minutes have
/// passed since the last checkpoint.
/// </param>
public void Checkpoint(uint kbytesWritten, uint minutesElapsed) {
dbenv.txn_checkpoint(kbytesWritten, minutesElapsed, 0);
}
/// <summary>
/// By closing the Berkeley DB environment you can free allocated resources
/// and close any open databases along with the underlying subsystems.
/// </summary>
/// <remarks>
/// <para>
/// The object should not be closed while any other handle that refers
/// to it is not yet closed; for example, database environment handles
/// must not be closed while transactions in the environment have
/// not yet been committed or aborted.
/// When you close each database handle, by default, the database is not synchronized.
/// To synchronize all open databases ensure that the last environment object is closed by the CloseForceSync() method.
/// When the close operation fails, the method returns a non-zero error value for the first instance of such error,
/// and continues to close the rest of the environment objects.
/// </para>
/// <para>
/// Where the environment was configured with
/// <see cref="DatabaseEnvironmentConfig.UseTxns"/>, calling CloseForceSync
/// aborts any unresolved transactions. Applications should not depend
/// on this behavior for transactions involving Berkeley DB databases;
/// all such transactions should be explicitly resolved. The problem
/// with depending on this semantic is that aborting an unresolved
/// transaction involving database operations requires a database
/// handle. Because the database handles should have been closed before
/// calling CloseForceSync, it will not be possible to abort the
/// transaction, and recovery will have to be run on the Berkeley DB
/// environment before further operations are done.
/// </para>
/// <para>
/// In multithreaded applications, only a single thread may call
/// CloseForceSync.
/// </para>
/// </remarks>
public void Close() {
dbenv.close(0);
}
/// <summary>
/// Close the Berkeley DB environment, freeing any allocated resources,
/// closing any open databases as well as underlying subsystems.
/// </summary>
/// <remarks>
/// <para>
/// The object should not be closed while any other handle that refers
/// to it is not yet closed; for example, database environment handles
/// must not be closed while transactions in the environment have
/// not yet been committed or aborted. If there are open database
/// handles, they are all closed, and each of them will be synced on
/// close. The first error in the close operations, if any, is
/// returned at last, and the environment close procedures will
/// carry on anyway.
/// </para>
/// <para>
/// Where the environment was configured with
/// <see cref="DatabaseEnvironmentConfig.UseTxns"/>, calling CloseForceSync
/// aborts any unresolved transactions. Applications should not depend
/// on this behavior for transactions involving Berkeley DB databases;
/// all such transactions should be explicitly resolved. The problem
/// with depending on this semantic is that aborting an unresolved
/// transaction involving database operations requires a database
/// handle. Because the database handles should have been closed before
/// calling CloseForceSync, it will not be possible to abort the
/// transaction, and recovery will have to be run on the Berkeley DB
/// environment before further operations are done.
/// </para>
/// <para>
/// In multithreaded applications, only a single thread may call
/// CloseForceSync.
/// </para>
/// </remarks>
public void CloseForceSync() {
dbenv.close(DbConstants.DB_FORCESYNC);
}
/// <summary>
/// Run one iteration of the deadlock detector. The deadlock detector
/// traverses the lock table and marks one of the participating lock
/// requesters for rejection in each deadlock it finds.
/// </summary>
/// <param name="atype">Specify which lock request(s) to reject</param>
/// <returns>The number of lock requests that were rejected.</returns>
public uint DetectDeadlocks(DeadlockPolicy atype) {
uint rejectCount = 0;
if (atype == null)
atype = DeadlockPolicy.DEFAULT;
dbenv.lock_detect(0, atype.policy, ref rejectCount);
return rejectCount;
}
/// <summary>
/// Check for threads of control (either a true thread or a process)
/// that have exited while manipulating Berkeley DB library data
/// structures, while holding a logical database lock, or with an
/// unresolved transaction (that is, a transaction that was never
/// aborted or committed).
/// </summary>
/// <remarks>
/// <para>
/// For more information, see Architecting Data Store and Concurrent
/// Data Store applications, and Architecting Transactional Data Store
/// applications, both in the Berkeley DB Programmer's Reference Guide.
/// </para>
/// <para>
/// FailCheck is based on the <see cref="SetThreadID"/> and
/// <see cref="ThreadIsAlive"/> delegates. Applications calling
/// FailCheck must have already set <see cref="ThreadIsAlive"/>, and
/// must have configured <see cref="ThreadCount"/>.
/// </para>
/// <para>
/// If FailCheck determines a thread of control exited while holding
/// database read locks, it will release those locks. If FailCheck
/// determines a thread of control exited with an unresolved
/// transaction, the transaction will be aborted. In either of these
/// cases, FailCheck will return successfully and the application may
/// continue to use the database environment.
/// </para>
/// <para>
/// In either of these cases, FailCheck will also report the process and
/// thread IDs associated with any released locks or aborted
/// transactions. The information is printed to a specified output
/// channel (see <see cref="Verbosity"/> for more information), or
/// passed to an application delegate (see <see cref="Feedback"/> for
/// more information).
/// </para>
/// <para>
/// If FailCheck determines a thread of control has exited such that
/// database environment recovery is required, it will throw
/// <see cref="RunRecoveryException"/>. In this case, the application
/// should not continue to use the database environment. For a further
/// description as to the actions the application should take when this
/// failure occurs, see Handling failure in Data Store and Concurrent
/// Data Store applications, and Handling failure in Transactional Data
/// Store applications, both in the Berkeley DB Programmer's Reference
/// Guide.
/// </para>
/// </remarks>
public void FailCheck() {
dbenv.failchk(0);
}
/// <summary>
/// This method checks to see if a specified transaction has been replicated from
/// the master of a replication group. It may be called by applications using either
/// the Base API or the Replication Manager.
/// </summary>
/// <param name="token">
/// The commit token from a transaction previously written at a master
/// site in the replication group. Commit tokens are retrieved using
/// the <see cref="Transaction.CommitToken"/> method.
/// </param>
/// <param name="timeout">
/// The maximum time to wait for the transaction to arrive by replication, expressed in
/// microseconds. To check the status of the transaction without waiting, the timeout
/// may be specified as 0.
/// </param>
/// <returns>
/// This method returns TransactionAppliedStatus.APPLIED to indicate that the specified
/// transaction has indeed been applied at the local site. TransactionAppliedStatus.TIMEOUT
/// will be returned if the specified transaction has not yet arrived at the calling site,
/// but can be expected to arrive soon. TransactionAppliedStatus.NOTFOUND will be returned
/// if the transaction has not been applied at the local site, and it can be determined that
/// the transaction has been rolled back due to a master takeover, and is therefore never
/// expected to arrive. TransactionAppliedStatus.EMPTY_TRANSACTION will be return if the specified
/// token was generated by a transaction that did not modify the database environment
/// (e.g., a read-only transaction).
/// </returns>
public TransactionAppliedStatus IsTransactionApplied(byte[] token, uint timeout)
{
if (token == null)
throw new ArgumentNullException("The token cannot be null.");
if (token.Length != DbConstants.DB_TXN_TOKEN_SIZE)
{
throw new ArgumentOutOfRangeException("The token size must be "
+ DbConstants.DB_TXN_TOKEN_SIZE);
}
DB_TXN_TOKEN txn_token = new DB_TXN_TOKEN(token);
int ret = dbenv.is_transaction_applied(txn_token, timeout, 0);
switch (ret)
{
case 0:
return TransactionAppliedStatus.APPLIED;
case DbConstants.DB_TIMEOUT:
return TransactionAppliedStatus.TIMEOUT;
case DbConstants.DB_NOTFOUND:
return TransactionAppliedStatus.NOTFOUND;
case DbConstants.DB_KEYEMPTY:
return TransactionAppliedStatus.EMPTY_TRANSACTION;
default:
throw new DatabaseException(ret);
}
}
/// <summary>
/// Map an LSN object to a log filename
/// </summary>
/// <param name="logSeqNum">
/// The DB_LSN structure for which a filename is wanted.
/// </param>
/// <returns>
/// The name of the file containing the record named by
/// <paramref name="logSeqNum"/>.
/// </returns>
public string LogFile(LSN logSeqNum) {
return dbenv.log_file(LSN.getDB_LSN(logSeqNum));
}
/// <summary>
/// Write all log records to disk.
/// </summary>
public void LogFlush() {
LogFlush(null);
}
/// <summary>
/// Write log records to disk.
/// </summary>
/// <param name="logSeqNum">
/// All log records with LSN values less than or equal to
/// <paramref name="logSeqNum"/> are written to disk. If null, all
/// records in the log are flushed.
/// </param>
public void LogFlush(LSN logSeqNum) {
dbenv.log_flush(LSN.getDB_LSN(logSeqNum));
}
/// <summary>
/// Verify log records of this environment.
/// </summary>
/// <param name="config">
/// Log verification configuration object.
/// </param>
public int LogVerify(LogVerifyConfig config) {
String dbfile, dbname, home;
int etime, stime;
uint cachesize;
uint efile, eoffset, sfile, soffset;
int caf, ret, verbose;
caf = ret = verbose = 0;
etime = stime = 0;
home = config.EnvHome;
dbfile = config.DbFile;
dbname = config.DbName;
try {
etime = (int)config.EndTime.ToFileTimeUtc();
stime = (int)config.StartTime.ToFileTimeUtc();
} catch (Exception){}
efile = config.EndLsn.LogFileNumber;
eoffset = config.EndLsn.Offset;
sfile = config.StartLsn.LogFileNumber;
soffset = config.StartLsn.Offset;
cachesize = config.CacheSize;
if (config.Verbose)
verbose = 1;
if (config.ContinueAfterFail)
caf = 1;
try {
ret = dbenv.log_verify(home, cachesize, dbfile, dbname,
stime, etime, sfile, soffset, efile, eoffset, caf, verbose);
} catch (Exception){}
return (ret);
}
/// <summary>
/// Append a record to the log
/// </summary>
/// <param name="dbt">The record to write to the log.</param>
/// <param name="flush">
/// If true, the log is forced to disk after this record is written,
/// guaranteeing that all records with LSN values less than or equal to
/// the one being "put" are on disk before LogWrite returns.
/// </param>
/// <returns>The LSN of the written record</returns>
public LSN LogWrite(DatabaseEntry dbt, bool flush) {
DB_LSN lsn = new DB_LSN();
dbenv.log_put(lsn,
dbt, flush ? DbConstants.DB_FLUSH : 0);
return new LSN(lsn.file, lsn.offset);
}
/// <summary>
/// Set the panic state for the database environment. (Database
/// environments in a panic state normally refuse all attempts to call
/// Berkeley DB functions, throwing <see cref="RunRecoveryException"/>.)
/// </summary>
public void Panic() {
dbenv.set_flags(DbConstants.DB_PANIC_ENVIRONMENT, 1);
}
/// <summary>
/// Restore transactions that were prepared, but not yet resolved at the
/// time of the system shut down or crash, to their state prior to the
/// shut down or crash, including any locks previously held.
/// </summary>
/// <remarks>
/// Calls to Recover from different threads of control should not be
/// intermixed in the same environment.
/// </remarks>
/// <param name="count">
/// The maximum number of <see cref="PreparedTransaction"/> objects
/// to return.
/// </param>
/// <param name="resume">
/// If true, continue returning a list of prepared, but not yet resolved
/// transactions, starting where the last call to Recover left off. If
/// false, begins a new pass over all prepared, but not yet completed
/// transactions, regardless of whether they have already been returned
/// in previous calls to Recover.
/// </param>
/// <returns>A list of the prepared transactions</returns>
public PreparedTransaction[] Recover(int count, bool resume) {
uint flags = 0;
flags |= resume ? DbConstants.DB_NEXT : DbConstants.DB_FIRST;
return dbenv.txn_recover(count, flags);
}
/// <summary>
/// Remove the underlying file represented by <paramref name="file"/>,
/// incidentally removing all of the databases it contained.
/// </summary>
/// <param name="file">The physical file to be removed.</param>
/// <param name="autoCommit">
/// If true, enclose RemoveDB within a transaction. If the call
/// succeeds, changes made by the operation will be recoverable. If the
/// call fails, the operation will have made no changes.
/// </param>
public void RemoveDB(string file, bool autoCommit) {
RemoveDB(file, null, autoCommit, null);
}
/// <summary>
/// Remove the database specified by <paramref name="file"/> and
/// <paramref name="database"/>. If no database is specified, the
/// underlying file represented by <paramref name="file"/> is removed,
/// incidentally removing all of the databases it contained.
/// </summary>
/// <param name="file">
/// The physical file which contains the database(s) to be removed.
/// </param>
/// <param name="database">The database to be removed.</param>
/// <param name="autoCommit">
/// If true, enclose RemoveDB within a transaction. If the call
/// succeeds, changes made by the operation will be recoverable. If the
/// call fails, the operation will have made no changes.
/// </param>
public void RemoveDB(string file, string database, bool autoCommit) {
RemoveDB(file, database, autoCommit, null);
}
/// <summary>
/// Remove the underlying file represented by <paramref name="file"/>,
/// incidentally removing all of the databases it contained.
/// </summary>
/// <param name="file">The physical file to be removed.</param>
/// <param name="autoCommit">
/// If true, enclose RemoveDB within a transaction. If the call
/// succeeds, changes made by the operation will be recoverable. If the
/// call fails, the operation will have made no changes.
/// </param>
/// <param name="txn">
/// If the operation is part of an application-specified transaction,
/// <paramref name="txn"/> is a Transaction object returned from
/// <see cref="DatabaseEnvironment.BeginTransaction"/>; if
/// the operation is part of a Berkeley DB Concurrent Data Store group,
/// <paramref name="txn"/> is a handle returned from
/// <see cref="DatabaseEnvironment.BeginCDSGroup"/>; otherwise null. If
/// null, but <paramref name="autoCommit"/> or <see cref="AutoCommit"/>
/// is true, the operation will be implicitly transaction protected.
/// </param>
public void RemoveDB(string file, bool autoCommit, Transaction txn) {
RemoveDB(file, null, autoCommit, txn);
}
/// <summary>
/// Remove the database specified by <paramref name="file"/> and
/// <paramref name="database"/>. If no database is specified, the
/// underlying file represented by <paramref name="file"/> is removed,
/// incidentally removing all of the databases it contained.
/// </summary>
/// <param name="file">
/// The physical file which contains the database(s) to be removed.
/// </param>
/// <param name="database">The database to be removed.</param>
/// <param name="autoCommit">
/// If true, enclose RemoveDB within a transaction. If the call
/// succeeds, changes made by the operation will be recoverable. If the
/// call fails, the operation will have made no changes.
/// </param>
/// <param name="txn">
/// If the operation is part of an application-specified transaction,
/// <paramref name="txn"/> is a Transaction object returned from
/// <see cref="DatabaseEnvironment.BeginTransaction"/>; if
/// the operation is part of a Berkeley DB Concurrent Data Store group,
/// <paramref name="txn"/> is a handle returned from
/// <see cref="DatabaseEnvironment.BeginCDSGroup"/>; otherwise null. If
/// null, but <paramref name="autoCommit"/> or <see cref="AutoCommit"/>
/// is true, the operation will be implicitly transaction protected.
/// </param>
public void RemoveDB(
string file, string database, bool autoCommit, Transaction txn) {
dbenv.dbremove(Transaction.getDB_TXN(txn),
file, database, autoCommit ? DbConstants.DB_AUTO_COMMIT : 0);
}
/// <summary>
/// Rename the underlying file represented by <paramref name="file"/>
/// using the value supplied to <paramref name="newname"/>, incidentally
/// renaming all of the databases it contained.
/// </summary>
/// <param name="file">The physical file to be renamed.</param>
/// <param name="newname">The new name of the database or file.</param>
/// <param name="autoCommit">
/// If true, enclose RenameDB within a transaction. If the call
/// succeeds, changes made by the operation will be recoverable. If the
/// call fails, the operation will have made no changes.
/// </param>
public void RenameDB(string file, string newname, bool autoCommit) {
RenameDB(file, null, newname, autoCommit, null);
}
/// <summary>
/// Rename the database specified by <paramref name="file"/> and
/// <paramref name="database"/> to <paramref name="newname"/>. If no
/// database is specified, the underlying file represented by
/// <paramref name="file"/> is renamed using the value supplied to
/// <paramref name="newname"/>, incidentally renaming all of the
/// databases it contained.
/// </summary>
/// <param name="file">
/// The physical file which contains the database(s) to be renamed.
/// </param>
/// <param name="database">The database to be renamed.</param>
/// <param name="newname">The new name of the database or file.</param>
/// <param name="autoCommit">
/// If true, enclose RenameDB within a transaction. If the call
/// succeeds, changes made by the operation will be recoverable. If the
/// call fails, the operation will have made no changes.
/// </param>
public void RenameDB(
string file, string database, string newname, bool autoCommit) {
RenameDB(file, database, newname, autoCommit, null);
}
/// <summary>
/// Rename the underlying file represented by <paramref name="file"/>
/// using the value supplied to <paramref name="newname"/>, incidentally
/// renaming all of the databases it contained.
/// </summary>
/// <param name="file">The physical file to be renamed.</param>
/// <param name="newname">The new name of the database or file.</param>
/// <param name="autoCommit">
/// If true, enclose RenameDB within a transaction. If the call
/// succeeds, changes made by the operation will be recoverable. If the
/// call fails, the operation will have made no changes.
/// </param>
/// <param name="txn">
/// If the operation is part of an application-specified transaction,
/// <paramref name="txn"/> is a Transaction object returned from
/// <see cref="DatabaseEnvironment.BeginTransaction"/>; if
/// the operation is part of a Berkeley DB Concurrent Data Store group,
/// <paramref name="txn"/> is a handle returned from
/// <see cref="DatabaseEnvironment.BeginCDSGroup"/>; otherwise null. If
/// null, but <paramref name="autoCommit"/> or <see cref="AutoCommit"/>
/// is true, the operation will be implicitly transaction protected.
/// </param>
public void RenameDB(string file,
string newname, bool autoCommit, Transaction txn) {
RenameDB(file, null, newname, autoCommit, txn);
}
/// <summary>
/// Rename the database specified by <paramref name="file"/> and
/// <paramref name="database"/> to <paramref name="newname"/>. If no
/// database is specified, the underlying file represented by
/// <paramref name="file"/> is renamed using the value supplied to
/// <paramref name="newname"/>, incidentally renaming all of the
/// databases it contained.
/// </summary>
/// <param name="file">
/// The physical file which contains the database(s) to be renamed.
/// </param>
/// <param name="database">The database to be renamed.</param>
/// <param name="newname">The new name of the database or file.</param>
/// <param name="autoCommit">
/// If true, enclose RenameDB within a transaction. If the call
/// succeeds, changes made by the operation will be recoverable. If the
/// call fails, the operation will have made no changes.
/// </param>
/// <param name="txn">
/// If the operation is part of an application-specified transaction,
/// <paramref name="txn"/> is a Transaction object returned from
/// <see cref="DatabaseEnvironment.BeginTransaction"/>; if
/// the operation is part of a Berkeley DB Concurrent Data Store group,
/// <paramref name="txn"/> is a handle returned from
/// <see cref="DatabaseEnvironment.BeginCDSGroup"/>; otherwise null. If
/// null, but <paramref name="autoCommit"/> or <see cref="AutoCommit"/>
/// is true, the operation will be implicitly transaction protected.
/// </param>
public void RenameDB(string file,
string database, string newname, bool autoCommit, Transaction txn) {
dbenv.dbrename(Transaction.getDB_TXN(txn), file,
database, newname, autoCommit ? DbConstants.DB_AUTO_COMMIT : 0);
}
/// <summary>
/// Allow database files to be copied, and then the copy used in the
/// same database environment as the original.
/// </summary>
/// <remarks>
/// <para>
/// All databases contain an ID string used to identify the database in
/// the database environment cache. If a physical database file is
/// copied, and used in the same environment as another file with the
/// same ID strings, corruption can occur. ResetFileID creates new ID
/// strings for all of the databases in the physical file.
/// </para>
/// <para>
/// ResetFileID modifies the physical file, in-place. Applications
/// should not reset IDs in files that are currently in use.
/// </para>
/// </remarks>
/// <param name="file">
/// The name of the physical file in which new file IDs are to be created.
/// </param>
/// <param name="encrypted">
/// If true, he file contains encrypted databases.
/// </param>
public void ResetFileID(string file, bool encrypted) {
dbenv.fileid_reset(file, encrypted ? DbConstants.DB_ENCRYPT : 0);
}
/// <summary>
/// Allow database files to be moved from one transactional database
/// environment to another.
/// </summary>
/// <remarks>
/// <para>
/// Database pages in transactional database environments contain
/// references to the environment's log files (that is, log sequence
/// numbers, or <see cref="LSN"/>s). Copying or moving a database file
/// from one database environment to another, and then modifying it, can
/// result in data corruption if the LSNs are not first cleared.
/// </para>
/// <para>
/// Note that LSNs should be reset before moving or copying the database
/// file into a new database environment, rather than moving or copying
/// the database file and then resetting the LSNs. Berkeley DB has
/// consistency checks that may be triggered if an application calls
/// ResetLSN on a database in a new environment when the database LSNs
/// still reflect the old environment.
/// </para>
/// <para>
/// The ResetLSN method modifies the physical file, in-place.
/// Applications should not reset LSNs in files that are currently in
/// use.
/// </para>
/// </remarks>
/// <param name="file"></param>
/// <param name="encrypted"></param>
public void ResetLSN(string file, bool encrypted) {
dbenv.lsn_reset(file, encrypted ? DbConstants.DB_ENCRYPT : 0);
}
/// <summary>
/// Limit the number of sequential write operations scheduled by the
/// library when flushing dirty pages from the cache.
/// </summary>
/// <param name="maxWrites">
/// The maximum number of sequential write operations scheduled by the
/// library when flushing dirty pages from the cache, or 0 if there is
/// no limitation on the number of sequential write operations.
/// </param>
/// <param name="pause">
/// The number of microseconds the thread of control should pause before
/// scheduling further write operations. It must be specified as an
/// unsigned 32-bit number of microseconds, limiting the maximum pause
/// to roughly 71 minutes.
/// </param>
public void SetMaxSequentialWrites(int maxWrites, uint pause) {
dbenv.set_mp_max_write(maxWrites, pause);
}
/// <summary>
/// Flush all modified pages in the cache to their backing files.
/// </summary>
/// <remarks>
/// Pages in the cache that cannot be immediately written back to disk
/// (for example, pages that are currently in use by another thread of
/// control) are waited for and written to disk as soon as it is
/// possible to do so.
/// </remarks>
public void SyncMemPool() {
SyncMemPool(null);
}
/// <summary>
/// Flush modified pages in the cache with log sequence numbers less
/// than <paramref name="minLSN"/> to their backing files.
/// </summary>
/// <remarks>
/// Pages in the cache that cannot be immediately written back to disk
/// (for example, pages that are currently in use by another thread of
/// control) are waited for and written to disk as soon as it is
/// possible to do so.
/// </remarks>
/// <param name="minLSN">
/// All modified pages with a log sequence number less than the minLSN
/// parameter are written to disk. If null, all modified pages in the
/// cache are written to disk.
/// </param>
public void SyncMemPool(LSN minLSN) {
dbenv.memp_sync(LSN.getDB_LSN(minLSN));
}
/// <summary>
/// Ensure that a specified percent of the pages in the cache are clean,
/// by writing dirty pages to their backing files.
/// </summary>
/// <param name="pctClean">
/// The percent of the pages in the cache that should be clean.
/// </param>
/// <returns>
/// The number of pages written to reach the specified percentage is
/// copied.
/// </returns>
public int TrickleCleanMemPool(int pctClean) {
int ret = 0;
dbenv.memp_trickle(pctClean, ref ret);
return ret;
}
/// <summary>
/// Append an informational message to the Berkeley DB database
/// environment log files.
/// </summary>
/// <overloads>
/// WriteToLog allows applications to include information in the
/// database environment log files, for later review using the
/// db_printlog utility. This method is intended for debugging and
/// performance tuning.
/// </overloads>
/// <param name="str">The message to append to the log files</param>
public void WriteToLog(string str) {
dbenv.log_printf(null, str);
}
/// <summary>
/// Append an informational message to the Berkeley DB database
/// environment log files.
/// </summary>
/// <overloads>
/// WriteToLog allows applications to include information in the
/// database environment log files, for later review using the
/// db_printlog utility. This method is intended for debugging and
/// performance tuning.
/// </overloads>
/// <param name="str">The message to append to the log files</param>
/// <param name="txn">
/// If the operation is part of an application-specified transaction,
/// <paramref name="txn"/> is a Transaction object returned from
/// <see cref="DatabaseEnvironment.BeginTransaction"/>;
/// otherwise null.
/// </param>
public void WriteToLog(string str, Transaction txn) {
dbenv.log_printf(Transaction.getDB_TXN(txn), str);
}
#region Stats
/// <summary>
/// The locking subsystem statistics
/// </summary>
/// <returns>The locking subsystem statistics</returns>
public LockStats LockingSystemStats() {
return LockingSystemStats(false);
}
/// <summary>
/// The locking subsystem statistics
/// </summary>
/// <param name="clearStats">
/// If true, reset statistics after returning their values.
/// </param>
/// <returns>The locking subsystem statistics</returns>
public LockStats LockingSystemStats(bool clearStats) {
uint flags = 0;
flags |= clearStats ? DbConstants.DB_STAT_CLEAR : 0;
LockStatStruct st = dbenv.lock_stat(flags);
return new LockStats(st);
}
/// <summary>
/// The logging subsystem statistics
/// </summary>
/// <returns>The logging subsystem statistics</returns>
public LogStats LoggingSystemStats() {
return LoggingSystemStats(false);
}
/// <summary>
/// The logging subsystem statistics
/// </summary>
/// <param name="clearStats">
/// If true, reset statistics after returning their values.
/// </param>
/// <returns>The logging subsystem statistics</returns>
public LogStats LoggingSystemStats(bool clearStats) {
uint flags = 0;
flags |= clearStats ? DbConstants.DB_STAT_CLEAR : 0;
LogStatStruct st = dbenv.log_stat(flags);
return new LogStats(st);
}
/// <summary>
/// The memory pool (that is, the buffer cache) subsystem statistics
/// </summary>
/// <returns>The memory pool subsystem statistics</returns>
public MPoolStats MPoolSystemStats() {
return MPoolSystemStats(false);
}
/// <summary>
/// The memory pool (that is, the buffer cache) subsystem statistics
/// </summary>
/// <param name="clearStats">
/// If true, reset statistics after returning their values.
/// </param>
/// <returns>The memory pool subsystem statistics</returns>
public MPoolStats MPoolSystemStats(bool clearStats) {
uint flags = 0;
flags |= clearStats ? DbConstants.DB_STAT_CLEAR : 0;
MempStatStruct st = dbenv.memp_stat(flags);
return new MPoolStats(st);
}
/// <summary>
/// The mutex subsystem statistics
/// </summary>
/// <returns>The mutex subsystem statistics</returns>
public MutexStats MutexSystemStats() {
return MutexSystemStats(false);
}
/// <summary>
/// The mutex subsystem statistics
/// </summary>
/// <param name="clearStats">
/// If true, reset statistics after returning their values.
/// </param>
/// <returns>The mutex subsystem statistics</returns>
public MutexStats MutexSystemStats(bool clearStats) {
uint flags = 0;
flags |= clearStats ? DbConstants.DB_STAT_CLEAR : 0;
MutexStatStruct st = dbenv.mutex_stat(flags);
return new MutexStats(st);
}
/// <summary>
/// The replication manager statistics
/// </summary>
/// <returns>The replication manager statistics</returns>
public RepMgrStats RepMgrSystemStats() {
return RepMgrSystemStats(false);
}
/// <summary>
/// The replication manager statistics
/// </summary>
/// <param name="clearStats">
/// If true, reset statistics after returning their values.
/// </param>
/// <returns>The replication manager statistics</returns>
public RepMgrStats RepMgrSystemStats(bool clearStats) {
uint flags = 0;
flags |= clearStats ? DbConstants.DB_STAT_CLEAR : 0;
RepMgrStatStruct st = dbenv.repmgr_stat(flags);
return new RepMgrStats(st);
}
/// <summary>
/// The replication subsystem statistics
/// </summary>
/// <returns>The replication subsystem statistics</returns>
public ReplicationStats ReplicationSystemStats() {
return ReplicationSystemStats(false);
}
/// <summary>
/// The replication subsystem statistics
/// </summary>
/// <param name="clearStats">
/// If true, reset statistics after returning their values.
/// </param>
/// <returns>The replication subsystem statistics</returns>
public ReplicationStats ReplicationSystemStats(bool clearStats) {
uint flags = 0;
flags |= clearStats ? DbConstants.DB_STAT_CLEAR : 0;
ReplicationStatStruct st = dbenv.rep_stat(flags);
return new ReplicationStats(st);
}
/// <summary>
/// The transaction subsystem statistics
/// </summary>
/// <returns>The transaction subsystem statistics</returns>
public TransactionStats TransactionSystemStats() {
return TransactionSystemStats(false);
}
/// <summary>
/// The transaction subsystem statistics
/// </summary>
/// <param name="clearStats">
/// If true, reset statistics after returning their values.
/// </param>
/// <returns>The transaction subsystem statistics</returns>
public TransactionStats TransactionSystemStats(bool clearStats) {
uint flags = 0;
flags |= clearStats ? DbConstants.DB_STAT_CLEAR : 0;
TxnStatStruct st = dbenv.txn_stat(flags);
return new TransactionStats(st);
}
#endregion Stats
#region Print Stats
/// <summary>
/// Display the locking subsystem statistical information, as described
/// by <see cref="LockStats"/>.
/// </summary>
public void PrintLockingSystemStats() {
PrintLockingSystemStats(false, false, false, false, false, false);
}
/// <summary>
/// Display the locking subsystem statistical information, as described
/// by <see cref="LockStats"/>.
/// </summary>
/// <param name="PrintAll">
/// If true, display all available information.
/// </param>
/// <param name="ClearStats">
/// If true, reset statistics after displaying their values.
/// </param>
public void PrintLockingSystemStats(bool PrintAll, bool ClearStats) {
PrintLockingSystemStats(
PrintAll, ClearStats, false, false, false, false);
}
/// <summary>
/// Display the locking subsystem statistical information, as described
/// by <see cref="LockStats"/>.
/// </summary>
/// <param name="PrintAll">
/// If true, display all available information.
/// </param>
/// <param name="ClearStats">
/// If true, reset statistics after displaying their values.
/// </param>
/// <param name="ConflictMatrix">
/// If true, display the lock conflict matrix.
/// </param>
/// <param name="Lockers">
/// If true, Display the lockers within hash chains.
/// </param>
/// <param name="Objects">
/// If true, display the lock objects within hash chains.
/// </param>
/// <param name="Parameters">
/// If true, display the locking subsystem parameters.
/// </param>
public void PrintLockingSystemStats(bool PrintAll, bool ClearStats,
bool ConflictMatrix, bool Lockers, bool Objects, bool Parameters) {
uint flags = 0;
flags |= PrintAll ? DbConstants.DB_STAT_ALL : 0;
flags |= ClearStats ? DbConstants.DB_STAT_CLEAR : 0;
flags |= ConflictMatrix ? DbConstants.DB_STAT_LOCK_CONF : 0;
flags |= Lockers ? DbConstants.DB_STAT_LOCK_LOCKERS : 0;
flags |= Objects ? DbConstants.DB_STAT_LOCK_OBJECTS : 0;
flags |= Parameters ? DbConstants.DB_STAT_LOCK_PARAMS : 0;
dbenv.lock_stat_print(flags);
}
/// <summary>
/// Display the logging subsystem statistical information, as described
/// by <see cref="LogStats"/>.
/// </summary>
public void PrintLoggingSystemStats() {
PrintLoggingSystemStats(false, false);
}
/// <summary>
/// Display the logging subsystem statistical information, as described
/// by <see cref="LogStats"/>.
/// </summary>
/// <param name="PrintAll">
/// If true, display all available information.
/// </param>
/// <param name="ClearStats">
/// If true, reset statistics after displaying their values.
/// </param>
public void PrintLoggingSystemStats(bool PrintAll, bool ClearStats) {
uint flags = 0;
flags |= PrintAll ? DbConstants.DB_STAT_ALL : 0;
flags |= ClearStats ? DbConstants.DB_STAT_CLEAR : 0;
dbenv.log_stat_print(flags);
}
/// <summary>
/// Display the memory pool (that is, buffer cache) subsystem
/// statistical information, as described by <see cref="MPoolStats"/>.
/// </summary>
public void PrintMPoolSystemStats() {
PrintMPoolSystemStats(false, false, false);
}
/// <summary>
/// Display the memory pool (that is, buffer cache) subsystem
/// statistical information, as described by <see cref="MPoolStats"/>.
/// </summary>
/// <param name="PrintAll">
/// If true, display all available information.
/// </param>
/// <param name="ClearStats">
/// If true, reset statistics after displaying their values.
/// </param>
public void PrintMPoolSystemStats(bool PrintAll, bool ClearStats) {
PrintMPoolSystemStats(PrintAll, ClearStats, false);
}
/// <summary>
/// Display the memory pool (that is, buffer cache) subsystem
/// statistical information, as described by <see cref="MPoolStats"/>.
/// </summary>
/// <param name="PrintAll">
/// If true, display all available information.
/// </param>
/// <param name="ClearStats">
/// If true, reset statistics after displaying their values.
/// </param>
/// <param name="HashChains">
/// If true, display the buffers with hash chains.
/// </param>
public void PrintMPoolSystemStats(
bool PrintAll, bool ClearStats, bool HashChains) {
uint flags = 0;
flags |= PrintAll ? DbConstants.DB_STAT_ALL : 0;
flags |= ClearStats ? DbConstants.DB_STAT_CLEAR : 0;
flags |= HashChains ? DbConstants.DB_STAT_MEMP_HASH : 0;
dbenv.memp_stat_print(flags);
}
/// <summary>
/// Display the mutex subsystem statistical information, as described
/// by <see cref="MutexStats"/>.
/// </summary>
public void PrintMutexSystemStats() {
PrintMutexSystemStats(false, false);
}
/// <summary>
/// Display the mutex subsystem statistical information, as described
/// by <see cref="MutexStats"/>.
/// </summary>
/// <param name="PrintAll">
/// If true, display all available information.
/// </param>
/// <param name="ClearStats">
/// If true, reset statistics after displaying their values.
/// </param>
public void PrintMutexSystemStats(bool PrintAll, bool ClearStats) {
uint flags = 0;
flags |= PrintAll ? DbConstants.DB_STAT_ALL : 0;
flags |= ClearStats ? DbConstants.DB_STAT_CLEAR : 0;
dbenv.mutex_stat_print(flags);
}
/// <summary>
/// Display the replication manager statistical information, as
/// described by <see cref="RepMgrStats"/>.
/// </summary>
public void PrintRepMgrSystemStats() {
PrintRepMgrSystemStats(false, false);
}
/// <summary>
/// Display the replication manager statistical information, as
/// described by <see cref="RepMgrStats"/>.
/// </summary>
/// <param name="PrintAll">
/// If true, display all available information.
/// </param>
/// <param name="ClearStats">
/// If true, reset statistics after displaying their values.
/// </param>
public void PrintRepMgrSystemStats(bool PrintAll, bool ClearStats) {
uint flags = 0;
flags |= PrintAll ? DbConstants.DB_STAT_ALL : 0;
flags |= ClearStats ? DbConstants.DB_STAT_CLEAR : 0;
dbenv.repmgr_stat_print(flags);
}
/// <summary>
/// Display the replication subsystem statistical information, as
/// described by <see cref="ReplicationStats"/>.
/// </summary>
public void PrintReplicationSystemStats() {
PrintReplicationSystemStats(false, false);
}
/// <summary>
/// Display the replication subsystem statistical information, as
/// described by <see cref="ReplicationStats"/>.
/// </summary>
/// <param name="PrintAll">
/// If true, display all available information.
/// </param>
/// <param name="ClearStats">
/// If true, reset statistics after displaying their values.
/// </param>
public void
PrintReplicationSystemStats(bool PrintAll, bool ClearStats) {
uint flags = 0;
flags |= PrintAll ? DbConstants.DB_STAT_ALL : 0;
flags |= ClearStats ? DbConstants.DB_STAT_CLEAR : 0;
dbenv.rep_stat_print(flags);
}
/// <summary>
/// Display the locking subsystem statistical information, as described
/// by <see cref="LockStats"/>.
/// </summary>
public void PrintStats() {
PrintStats(false, false, false);
}
/// <summary>
/// Display the locking subsystem statistical information, as described
/// by <see cref="LockStats"/>.
/// </summary>
/// <param name="PrintAll">
/// If true, display all available information.
/// </param>
/// <param name="ClearStats">
/// If true, reset statistics after displaying their values.
/// </param>
public void PrintStats(bool PrintAll, bool ClearStats) {
PrintStats(PrintAll, ClearStats, false);
}
/// <summary>
/// Display the locking subsystem statistical information, as described
/// by <see cref="LockStats"/>.
/// </summary>
public void PrintSubsystemStats() {
PrintStats(false, false, true);
}
/// <summary>
/// Display the locking subsystem statistical information, as described
/// by <see cref="LockStats"/>.
/// </summary>
/// <param name="PrintAll">
/// If true, display all available information.
/// </param>
/// <param name="ClearStats">
/// If true, reset statistics after displaying their values.
/// </param>
public void PrintSubsystemStats(bool PrintAll, bool ClearStats) {
PrintStats(PrintAll, ClearStats, true);
}
/// <summary>
/// Display the locking subsystem statistical information, as described
/// by <see cref="LockStats"/>.
/// </summary>
private void PrintStats(bool all, bool clear, bool subs) {
uint flags = 0;
flags |= all ? DbConstants.DB_STAT_ALL : 0;
flags |= clear ? DbConstants.DB_STAT_CLEAR : 0;
flags |= subs ? DbConstants.DB_STAT_SUBSYSTEM : 0;
dbenv.stat_print(flags);
}
/// <summary>
/// Display the transaction subsystem statistical information, as
/// described by <see cref="TransactionStats"/>.
/// </summary>
public void PrintTransactionSystemStats() {
PrintTransactionSystemStats(false, false);
}
/// <summary>
/// Display the transaction subsystem statistical information, as
/// described by <see cref="TransactionStats"/>.
/// </summary>
/// <param name="PrintAll">
/// If true, display all available information.
/// </param>
/// <param name="ClearStats">
/// If true, reset statistics after displaying their values.
/// </param>
public void
PrintTransactionSystemStats(bool PrintAll, bool ClearStats) {
uint flags = 0;
flags |= PrintAll ? DbConstants.DB_STAT_ALL : 0;
flags |= ClearStats ? DbConstants.DB_STAT_CLEAR : 0;
dbenv.txn_stat_print(flags);
}
#endregion Print Stats
private uint getRepTimeout(int which) {
uint ret = 0;
dbenv.rep_get_timeout(which, ref ret);
return ret;
}
private bool getRepConfig(uint which) {
int onoff = 0;
dbenv.rep_get_config(which, ref onoff);
return (onoff != 0);
}
#region Unsupported Subsystem Methods
/// <summary>
/// The Berkeley DB process' environment may be permitted to specify
/// information to be used when naming files; see Berkeley DB File
/// Naming in the Programmer's Reference Guide for more information.
/// </summary>
public bool UseEnvironmentVars {
get {
uint flags = 0;
dbenv.get_open_flags(ref flags);
return (flags & DbConstants.DB_USE_ENVIRON) != 0;
}
}
private bool USE_ENVIRON_ROOT {
get {
uint flags = 0;
dbenv.get_open_flags(ref flags);
return (flags & DbConstants.DB_USE_ENVIRON_ROOT) != 0;
}
}
private uint CreateLockerID() {
uint ret = 0;
dbenv.lock_id(ref ret);
return ret;
}
private void FreeLockerID(uint locker) {
dbenv.lock_id_free(locker);
}
private Lock GetLock(
uint locker, bool wait, DatabaseEntry obj, LockMode mode) {
return new Lock(dbenv.lock_get(locker,
wait ? 0 : DbConstants.DB_LOCK_NOWAIT,
obj, LockMode.GetMode(mode)));
}
private Mutex GetMutex(bool SelfBlock, bool SingleProcess) {
uint m = 0;
uint flags = 0;
flags |= SelfBlock ? DbConstants.DB_MUTEX_SELF_BLOCK : 0;
flags |= SingleProcess ? DbConstants.DB_MUTEX_PROCESS_ONLY : 0;
dbenv.mutex_alloc(flags, ref m);
return new Mutex(this, m);
}
private void LockMany(uint locker, bool wait, LockRequest[] vec) {
LockMany(locker, wait, vec, null);
}
private void LockMany(
uint locker, bool wait, LockRequest[] vec, LockRequest failedReq) {
IntPtr[] reqList = new IntPtr[vec.Length];
DB_LOCKREQ[] lst = new DB_LOCKREQ[vec.Length];
for (int i = 0; i < vec.Length; i++) {
reqList[i] = DB_LOCKREQ.getCPtr(
LockRequest.get_DB_LOCKREQ(vec[i])).Handle;
lst[i] = LockRequest.get_DB_LOCKREQ(vec[i]);
}
dbenv.lock_vec(locker, wait ? 0 : DbConstants.DB_TXN_NOWAIT,
reqList, vec.Length, LockRequest.get_DB_LOCKREQ(failedReq));
}
private void PutLock(Lock lck) {
dbenv.lock_put(Lock.GetDB_LOCK(lck));
}
#endregion
}
}
|