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
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<!-- This document was generated using DocBuilder 3.3.3 -->
<HTML>
<HEAD>
<TITLE>mnesia</TITLE>
<SCRIPT type="text/javascript" src="../../../../doc/erlresolvelinks.js">
</SCRIPT>
<STYLE TYPE="text/css">
<!--
.REFBODY { margin-left: 13mm }
.REFTYPES { margin-left: 8mm }
-->
</STYLE>
</HEAD>
<BODY BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000FF" VLINK="#FF00FF"
ALINK="#FF0000">
<!-- refpage -->
<CENTER>
<A HREF="http://www.erlang.se">
<IMG BORDER=0 ALT="[Ericsson AB]" SRC="min_head.gif">
</A>
<H1>mnesia</H1>
</CENTER>
<H3>MODULE</H3>
<DIV CLASS=REFBODY>
mnesia
</DIV>
<H3>MODULE SUMMARY</H3>
<DIV CLASS=REFBODY>
A Distributed Telecommunications DBMS
</DIV>
<H3>DESCRIPTION</H3>
<DIV CLASS=REFBODY>
<P><CODE>Mnesia</CODE> is a distributed DataBase Management System (DBMS),
appropriate for telecommunications applications and other Erlang
applications which require continuous operation and exhibit soft
real-time properties.
<P>Listed below are some of the most important and attractive capabilities, Mnesia provides:
<P>
<UL>
<LI>
A relational/object hybrid data model which is
suitable for telecommunications applications.
<BR>
</LI>
<LI>
A specifically designed DBMS query language, QLC (as an add-on library).
<BR>
</LI>
<LI>
Persistence. Tables may be coherently kept on disc as
well as in main memory.
<BR>
</LI>
<LI>
Replication. Tables may be replicated at several nodes.
<BR>
</LI>
<LI>
Atomic transactions. A series of table manipulation
operations can be grouped into a single atomic
transaction.
<BR>
</LI>
<LI>
Location transparency. Programs can be written without
knowledge of the actual location of data.
<BR>
</LI>
<LI>
Extremely fast real time data searches.
<BR>
</LI>
<LI>
Schema manipulation routines. It is possible to
reconfigure the DBMS at runtime without stopping the
system.
<BR>
</LI>
</UL>
<P>This Reference Manual describes the Mnesia API. This includes
functions used to define and manipulate Mnesia tables.
<P> All functions documented in these pages can be used in any
combination with queries using the list comprehension notation. The
query notation is described in the QLC's man page.
<P> Data in Mnesia is organized as a set of tables. Each table
has a name which must be an atom. Each table is made up of
Erlang records. The user is responsible for the record
definitions. Each table also has a set of properties. Below
are some of the properties that are associated with each
table:
<P>
<UL>
<LI>
<CODE>type</CODE>. Each table can either have 'set',
'ordered_set' or 'bag' semantics. Note: currently 'ordered_set'
is not supported for 'disc_only_copies'. If a table is of type
'set' it means that each key leads to either one or zero
records. <BR>
If a new item is inserted with the same key as
an existing record, the old record is overwritten. On the
other hand, if a table is of type 'bag', each key can map to
several records. However, all records in type bag tables are
unique, only the keys may be duplicated.
<BR>
</LI>
<LI>
<CODE>record_name</CODE>. All records stored in a table must
have the same name. You may say that the records must be
instances of the same record type.
<BR>
</LI>
<LI>
<CODE>ram_copies</CODE> A table can be replicated on a number
of Erlang nodes. The <CODE>ram_copies</CODE> property specifies a
list of Erlang nodes where RAM copies are kept. These
copies can be dumped to disc at regular intervals. However,
updates to these copies are not written to disc on a
transaction basis.
<BR>
</LI>
<LI>
<CODE>disc_copies</CODE> The <CODE>disc_copies</CODE> property
specifies a list of Erlang nodes where the table is kept in
RAM as well as on disc. All updates of the table are
performed on the actual table and are also logged to disc.
If a table is of type <CODE>disc_copies</CODE> at a certain node,
it means that the entire table is resident in RAM memory as
well as on disc. Each transaction performed on the table is
appended to a LOG file as well as written into the RAM
table.
<BR>
</LI>
<LI>
<CODE>disc_only_copies</CODE> Some, or all, table replicas
can be kept on disc only. These replicas are considerably
slower than the RAM based replicas.
<BR>
</LI>
<LI>
<CODE>index</CODE> This is a list of attribute names, or
integers, which specify the tuple positions on which
Mnesia shall build and maintain an extra index table.
<BR>
</LI>
<LI>
<CODE>local_content</CODE> When an application requires
tables whose contents is local to each node,
<CODE>local_content</CODE> tables may be used. The name of the
table is known to all Mnesia nodes, but its contents is
unique on each node. This means that access to such a table
must be done locally. Set the <CODE>local_content</CODE> field to
<CODE>true</CODE> if you want to enable the <CODE>local_content</CODE>
behavior. The default is <CODE>false</CODE>.
<BR>
</LI>
<LI>
<CODE>snmp</CODE> Each (set based) Mnesia table can be
automatically turned into an SNMP ordered table as well.
This property specifies the types of the SNMP keys.
<BR>
</LI>
<LI>
<CODE>attributes</CODE>. The names of the attributes for the
records that are inserted in the table.
<BR>
</LI>
</UL>
<P>See <CODE>mnesia:create_table/2</CODE> about the complete set of
table properties and their details.
<P>This document uses a table of persons to illustrate various
examples. The following record definition is assumed:
<PRE>
-record(person, {name,
age = 0,
address = unknown,
salary = 0,
children = []}),
</PRE>
<P>The first attribute of the record is the primary key, or key
for short.
<P>The function descriptions are sorted in alphabetic order. <STRONG>Hint:</STRONG>
start to read about <CODE>mnesia:create_table/2</CODE>,
<CODE>mnesia:lock/2</CODE> and <CODE>mnesia:activity/4</CODE> before you continue on
and learn about the rest.
</DIV>
<H3>EXPORTS</H3>
<P><A NAME="abort/1"><STRONG><CODE>abort(Reason) -> transaction abort </CODE></STRONG></A><BR>
<DIV CLASS=REFBODY>
<P>Makes the transaction silently
return the tuple <CODE>{aborted, Reason}</CODE>.
The abortion of a Mnesia transaction means that
an exception will be thrown to an enclosing <CODE>catch</CODE>.
Thus, the expression <CODE>catch mnesia:abort(x)</CODE> does
not abort the transaction.
</DIV>
<P><A NAME="activate_checkpoint/1"><STRONG><CODE>activate_checkpoint(Args) -> {ok,Name,Nodes} | {error,Reason}</CODE></STRONG></A><BR>
<DIV CLASS=REFBODY>
<P>A checkpoint is a consistent view of the system.
A checkpoint can be activated on a set of tables.
This checkpoint can then be traversed and will
present a view of the system as it existed at the time when
the checkpoint was activated, even if the tables are being or have been
manipulated.
<P><CODE>Args</CODE> is a list of the following tuples:
<P>
<UL>
<LI>
<CODE>{name,Name}</CODE>. <CODE>Name</CODE> of checkpoint. Each
checkpoint must have a name which is unique to the
associated nodes. The name can be reused only once the
checkpoint has been deactivated. By default, a name
which is probably unique is generated.
<BR>
</LI>
<LI>
<CODE>{max,MaxTabs}</CODE> <CODE>MaxTabs</CODE> is a list of
tables that should be included in the checkpoint. The
default is []. For these tables, the redundancy will be
maximized and checkpoint information will be retained together
with all replicas. The checkpoint becomes more fault
tolerant if the tables have several replicas. When a new
replica is added by means of the schema manipulation
function <CODE>mnesia:add_table_copy/3</CODE>, a retainer will
also be attached automatically.
<BR>
</LI>
<LI>
<CODE>{min,MinTabs}</CODE>. <CODE>MinTabs</CODE> is a list of
tables that should be included in the checkpoint. The
default is []. For these tables, the redundancy will be
minimized and the checkpoint information will only be retained
with one replica, preferably on the local node.
<BR>
</LI>
<LI>
<CODE>{allow_remote,Bool}</CODE>. <CODE>false</CODE> means that
all retainers must be local. The checkpoint cannot be
activated if a table does not reside locally.
<CODE>true</CODE> allows retainers to be allocated on any
node. Default is set to <CODE>true</CODE>.
<BR>
</LI>
<LI>
<CODE>{ram_overrides_dump,Bool} </CODE> Only applicable
for <CODE>ram_copies</CODE>. <CODE>Bool</CODE> allows you to choose
to backup the table state as it is in RAM, or as it is on
disc. <CODE>true</CODE> means that the latest committed
records in RAM should be included in the checkpoint.
These are the records that the application accesses.
<CODE>false</CODE> means that the records dumped to DAT files
should be included in the checkpoint. These are the
records that will be loaded at startup. Default is
<CODE>false</CODE>.
<BR>
</LI>
</UL>
<P>Returns <CODE>{ok,Name,Nodes}</CODE> or <CODE>{error,Reason}</CODE>.
<CODE>Name</CODE> is the (possibly generated) name of the
checkpoint. <CODE>Nodes</CODE> are the nodes that
are involved in the checkpoint. Only nodes that keep a
checkpoint retainer know about the checkpoint.
</DIV>
<P><A NAME="activity/3"><STRONG><CODE>activity(AccessContext, Fun [, Args]) ->
ResultOfFun | exit(Reason)
</CODE></STRONG></A><BR>
<DIV CLASS=REFBODY>
<P>Invokes <CODE>mnesia:activity(AccessContext, Fun, Args,
AccessMod)</CODE> where <CODE>AccessMod</CODE> is the default
access callback module obtained by
<CODE>mnesia:system_info(access_module)</CODE>. <CODE>Args</CODE>
defaults to the empty list <CODE>[]</CODE>.
</DIV>
<P><A NAME="activity/4"><STRONG><CODE>activity(AccessContext, Fun, Args, AccessMod) ->
ResultOfFun | exit(Reason)
</CODE></STRONG></A><BR>
<DIV CLASS=REFBODY>
<P> This function executes the functional object <CODE>Fun</CODE>
with the arguments <CODE>Args</CODE>.
<P> The code which executes inside the activity can
consist of a series of table manipulation functions, which is
performed in a <CODE>AccessContext</CODE>. Currently, the following
access contexts are supported:
<P>
<DL>
<DT>
<CODE>transaction</CODE>
</DT>
<DD>
Short for <CODE>{transaction, infinity}</CODE>
<BR>
</DD>
<DT>
<CODE>{transaction, Retries}</CODE>
</DT>
<DD>
Invokes <CODE>mnesia:transaction(Fun, Args,
Retries)</CODE>. Note that the result from the <CODE>Fun</CODE> is
returned if the transaction was successful (atomic),
otherwise the function exits with an abort reason.
<BR>
</DD>
<DT>
<CODE>sync_transaction</CODE>
</DT>
<DD>
Short for <CODE>{sync_transaction, infinity}</CODE>
<BR>
</DD>
<DT>
<CODE>{sync_transaction, Retries}</CODE>
</DT>
<DD>
Invokes <CODE>mnesia:sync_transaction(Fun, Args,
Retries)</CODE>. Note that the result from the <CODE>Fun</CODE> is
returned if the transaction was successful (atomic),
otherwise the function exits with an abort reason.
<BR>
</DD>
<DT>
<CODE>async_dirty</CODE>
</DT>
<DD>
Invokes <CODE>mnesia:async_dirty(Fun, Args)</CODE>.
<BR>
</DD>
<DT>
<CODE>sync_dirty</CODE>
</DT>
<DD>
Invokes <CODE>mnesia:sync_dirty(Fun, Args)</CODE>.
<BR>
</DD>
<DT>
<CODE>ets</CODE>
</DT>
<DD>
Invokes <CODE>mnesia:ets(Fun, Args)</CODE>.
<BR>
</DD>
</DL>
<P>This function (<CODE>mnesia:activity/4</CODE>) differs in an
important aspect from the <CODE>mnesia:transaction</CODE>,
<CODE>mnesia:sync_transaction</CODE>,
<CODE>mnesia:async_dirty</CODE>, <CODE>mnesia:sync_dirty</CODE> and
<CODE>mnesia:ets</CODE> functions. The <CODE>AccessMod</CODE> argument
is the name of a callback module which implements the
<CODE>mnesia_access</CODE> behavior.
<P>Mnesia will forward calls to the following functions:
<P>
<UL>
<LI>
mnesia:write/3 (write/1, s_write/1)
<BR>
</LI>
<LI>
mnesia:delete/3 (delete/1, s_delete/1)
<BR>
</LI>
<LI>
mnesia:delete_object/3 (delete_object/1, s_delete_object/1)
<BR>
</LI>
<LI>
mnesia:read/3 (read/1, wread/1)
<BR>
</LI>
<LI>
mnesia:match_object/3 (match_object/1)
<BR>
</LI>
<LI>
mnesia:all_keys/1
<BR>
</LI>
<LI>
mnesia:index_match_object/4 (index_match_object/2)
<BR>
</LI>
<LI>
mnesia:index_read/3
<BR>
</LI>
<LI>
mnesia:lock/2 (read_lock_table/1, write_lock_table/1)
<BR>
</LI>
<LI>
mnesia:table_info/2
<BR>
</LI>
</UL>
<P>to the corresponding:
<P>
<UL>
<LI>
AccessMod:lock(ActivityId, Opaque, LockItem, LockKind)
<BR>
</LI>
<LI>
AccessMod:write(ActivityId, Opaque, Tab, Rec, LockKind)
<BR>
</LI>
<LI>
AccessMod:delete(ActivityId, Opaque, Tab, Key, LockKind)
<BR>
</LI>
<LI>
AccessMod:delete_object(ActivityId, Opaque, Tab, RecXS, LockKind)
<BR>
</LI>
<LI>
AccessMod:read(ActivityId, Opaque, Tab, Key, LockKind)
<BR>
</LI>
<LI>
AccessMod:match_object(ActivityId, Opaque, Tab, Pattern, LockKind)
<BR>
</LI>
<LI>
AccessMod:all_keys(ActivityId, Opaque, Tab, LockKind)
<BR>
</LI>
<LI>
AccessMod:index_match_object(ActivityId, Opaque, Tab, Pattern, Attr, LockKind)
<BR>
</LI>
<LI>
AccessMod:index_read(ActivityId, Opaque, Tab, SecondaryKey, Attr, LockKind)
<BR>
</LI>
<LI>
AccessMod:table_info(ActivityId, Opaque, Tab, InfoItem)
<BR>
</LI>
</UL>
<P>where <CODE>ActivityId</CODE> is a record which represents the
identity of the enclosing Mnesia activity. The first field
(obtained with <CODE>element(1, ActivityId)</CODE> contains an
atom which may be interpreted as the type of the activity:
<CODE>'ets'</CODE>, <CODE>'async_dirty'</CODE>, <CODE>'sync_dirty'</CODE> or
<CODE>'tid'</CODE>. <CODE>'tid'</CODE> means that the activity is a
transaction. The structure of the rest of the identity
record is internal to Mnesia.
<P><CODE>Opaque</CODE> is an opaque data structure which is internal
to Mnesia.
</DIV>
<P><A NAME="add_table_copy/3"><STRONG><CODE>add_table_copy(Tab, Node, Type) -> {aborted, R} | {atomic, ok}
</CODE></STRONG></A><BR>
<DIV CLASS=REFBODY>
<P> This function makes another copy of a table at the
node <CODE>Node</CODE>. The <CODE>Type</CODE> argument must be
either of the atoms <CODE>ram_copies</CODE>, <CODE>disc_copies</CODE>,
or
<CODE>disc_only_copies</CODE>. For example, the following call
ensures that a disc replica of the <CODE>person</CODE> table also
exists at node <CODE>Node</CODE>.
<PRE>
mnesia:add_table_copy(person, Node, disc_copies)
</PRE>
<P>This function can also be used to add a replica of the
table named <CODE>schema</CODE>.
</DIV>
<P><A NAME="add_table_index/2"><STRONG><CODE>add_table_index(Tab, AttrName) -> {aborted, R} | {atomic, ok}
</CODE></STRONG></A><BR>
<DIV CLASS=REFBODY>
<P>Table indices can and should be used whenever the user
wants to frequently use some other field than the key field
to look up records. If this other field has an index
associated with it, these lookups can occur in constant time
and space. For example, if our application wishes to use
the age field of persons to efficiently find all person with
a specific age, it might be a good idea to have an index on
the age field. This can be accomplished with the following
call:
<PRE>
mnesia:add_table_index(person, age)
</PRE>
<P> Indices do not come free, they occupy space which is
proportional to the size of the table. They also cause insertions
into the table to execute slightly slower.
</DIV>
<P><A NAME="all_keys/1"><STRONG><CODE>all_keys(Tab) -> KeyList | transaction abort
</CODE></STRONG></A><BR>
<DIV CLASS=REFBODY>
<P>This function returns a list of all keys in the table
named <CODE>Tab</CODE>. The semantics of this function is context
sensitive. See <CODE>mnesia:activity/4</CODE> for more information. In
transaction context it acquires a read lock on the entire
table.
</DIV>
<P><A NAME="async_dirty/3"><STRONG><CODE>async_dirty(Fun, [, Args]) -> ResultOfFun | exit(Reason)</CODE></STRONG></A><BR>
<DIV CLASS=REFBODY>
<P>Call the <CODE>Fun</CODE> in a context which is not protected
by a transaction. The Mnesia function calls performed in the
<CODE>Fun</CODE> are mapped to the corresponding dirty
functions. This still involves logging, replication and
subscriptions, but there is no locking, local transaction
storage, or commit protocols involved. Checkpoint retainers
and indices are updated, but they will be updated dirty. As
for normal mnesia:dirty_* operations, the operations are
performed semi-asynchronously. See
<CODE>mnesia:activity/4</CODE> and the Mnesia User's Guide for
more details.
<P>It is possible to manipulate the Mnesia tables without
using transactions. This has some serious disadvantages, but
is considerably faster since the transaction manager is not
involved and no locks are set. A dirty operation does,
however, guarantee a certain level of consistency and it is
not possible for the dirty operations to return garbled
records. All dirty operations provide location transparency
to the programmer and a program does not have to be aware of
the whereabouts of a certain table in order to function.
<P> <STRONG> Note:</STRONG>It is more than 10 times more efficient to read records dirty
than within a transaction.
<P>Depending on the application, it may be a good idea to use
the dirty functions for certain operations. Almost all
Mnesia functions which can be called within transactions
have a dirty equivalent which is much more
efficient. However, it must be noted that it is possible for
the database to be left in an inconsistent state if dirty
operations are used to update it. Dirty operations should
only be used for performance reasons when it is absolutely
necessary.
<P> <STRONG> Note:</STRONG> Calling (nesting) a <CODE>mnesia:[a]sync_dirty</CODE>
inside a transaction context will inherit the transaction semantics.
</DIV>
<P><A NAME="backup/2"><STRONG><CODE>backup(Opaque [, BackupMod]) -> ok | {error,Reason}</CODE></STRONG></A><BR>
<DIV CLASS=REFBODY>
<P>Activates a new checkpoint covering all Mnesia tables,
including the schema, with maximum degree of redundancy and
performs a backup using <CODE>backup_checkpoint/2/3</CODE>. The
default value of the backup callback module <CODE>BackupMod</CODE>
is obtained by <CODE>mnesia:system_info(backup_module)</CODE>.
</DIV>
<P><A NAME="backup_checkpoint/3"><STRONG><CODE>backup_checkpoint(Name, Opaque [, BackupMod]) ->
ok | {error,Reason}</CODE></STRONG></A><BR>
<DIV CLASS=REFBODY>
<P>The tables are backed up to external media using the backup
module <CODE>BackupMod</CODE>. Tables with the local contents
property is being backed up as they exist on the current
node. <CODE>BackupMod</CODE> is the default backup callback
module obtained by
<CODE>mnesia:system_info(backup_module)</CODE>. See the User's
Guide about the exact callback interface (the
<CODE>mnesia_backup behavior</CODE>).
</DIV>
<P><A NAME="change_config/2"><STRONG><CODE>change_config(Config, Value) -> {error, Reason}
| {ok, ReturnValue}
</CODE></STRONG></A><BR>
<DIV CLASS=REFBODY>
<P> The <CODE>Config</CODE> should be an atom of the following
configuration parameters:
<P>
<DL>
<DT>
<CODE>extra_db_nodes</CODE>
</DT>
<DD>
<CODE>Value</CODE> is a list of nodes which Mnesia should try to connect to.
The <CODE>ReturnValue</CODE> will be those nodes in
<CODE>Value</CODE> which Mnesia was able to connect to.
<BR>
Note: This function shall only be used to connect to newly started ram nodes
(N.D.R.S.N.) with an empty schema. If for example it is used after the network
have been partitioned it may lead to inconsistent tables.
<BR>
Note: Mnesia may be connected to other nodes than those
returned in <CODE>ReturnValue</CODE>.
<BR>
</DD>
</DL>
</DIV>
<P><A NAME="change_table_access_mode/2"><STRONG><CODE>change_table_access_mode(Tab, AccessMode) -> {aborted, R}
| {atomic, ok}
</CODE></STRONG></A><BR>
<DIV CLASS=REFBODY>
<P>The <CODE>AcccessMode</CODE> is by default the atom
<CODE>read_write</CODE> but it may also be set to the atom
<CODE>read_only</CODE>. If the <CODE>AccessMode</CODE> is set to
<CODE>read_only</CODE>, it means that it is not possible to perform
updates to the table. At startup Mnesia always loads
<CODE>read_only</CODE> tables locally regardless of when and if
Mnesia was terminated on other nodes.
</DIV>
<P><A NAME="change_table_copy_type/3"><STRONG><CODE>change_table_copy_type(Tab, Node, To) ->
{aborted, R} | {atomic, ok}
</CODE></STRONG></A><BR>
<DIV CLASS=REFBODY>
<P>For example:
<PRE>
mnesia:change_table_copy_type(person, node(), disc_copies)
</PRE>
<P>Transforms our <CODE>person</CODE> table from a RAM table into
a disc based table at <CODE>Node</CODE>.
<P>This function can also be used to change the storage type of
the table named <CODE>schema</CODE>. The schema table can only
have <CODE>ram_copies</CODE> or <CODE>disc_copies</CODE> as the storage type. If the
storage type of the schema is <CODE>ram_copies</CODE>, no other table
can be disc resident on that node.
</DIV>
<P><A NAME="change_table_load_order/2"><STRONG><CODE>change_table_load_order(Tab, LoadOrder) ->
{aborted, R} | {atomic, ok}
</CODE></STRONG></A><BR>
<DIV CLASS=REFBODY>
<P>The <CODE>LoadOrder</CODE> priority is by default <CODE>0</CODE> (zero)
but may be set to any integer. The tables with the highest
<CODE>LoadOrder</CODE> priority will be loaded first at startup.
</DIV>
<P><A NAME="clear_table/1"><STRONG><CODE>clear_table(Tab) ->
{aborted, R} | {atomic, ok}
</CODE></STRONG></A><BR>
<DIV CLASS=REFBODY>
<P> Deletes all entries in the table <CODE>Tab</CODE>.
</DIV>
<P><A NAME="create_schema/1"><STRONG><CODE>create_schema(DiscNodes) -> ok | {error,Reason}
</CODE></STRONG></A><BR>
<DIV CLASS=REFBODY>
<P>Creates a new database on disc. Various files are
created in the local Mnesia directory of each node. Note
that the directory must be unique for each node. Two nodes
may never share the same directory. If possible, use a local
disc device in order to improve performance.
<P><CODE>mnesia:create_schema/1</CODE> fails if any of the
Erlang nodes given as <CODE>DiscNodes</CODE> are not alive, if
Mnesia is running on anyone of the nodes, or if anyone of
the nodes already has a schema. Use
<CODE>mnesia:delete_schema/1</CODE> to get rid of old faulty
schemas.
<P><STRONG>Note:</STRONG> Only nodes with disc should be
included in <CODE>DiscNodes</CODE>. Disc-less nodes, that is nodes
where all tables including the schema only resides in RAM,
may not be included.
</DIV>
<P><A NAME="create_table/2"><STRONG><CODE>create_table(Name, TabDef) -> {atomic, ok} | {aborted, Reason}
</CODE></STRONG></A><BR>
<DIV CLASS=REFBODY>
<P> This function creates a Mnesia table called <CODE>Name</CODE>
according to the
argument <CODE>TabDef</CODE>. This list must be a list of
<CODE>{Item, Value}</CODE> tuples, where the following values are
allowed:
<P>
<UL>
<LI>
<CODE>{access_mode, Atom}</CODE>. The access mode is by
default the atom <CODE>read_write</CODE> but it may also be
set to the atom <CODE>read_only</CODE>. If the
<CODE>AccessMode</CODE> is set to <CODE>read_only</CODE>, it means
that it is not possible to perform updates to the table.
<BR>
At startup Mnesia always loads <CODE>read_only</CODE> tables
locally regardless of when and if Mnesia was terminated
on other nodes. This argument returns the access mode of
the table. The access mode may either be read_only or
read_write.
<BR>
</LI>
<LI>
<CODE>{attributes, AtomList}</CODE> a list of the
attribute names for the records that are supposed to
populate the table. The default value is <CODE>[key,
val]</CODE>. The table must have at least one extra
attribute in addition to the key.
<BR>
When accessing single attributes in a record, it is not
necessary, or even recommended, to hard code any
attribute names as atoms. Use the construct
<CODE>record_info(fields, RecordName)</CODE> instead. It can be
used for records of type <CODE>RecordName</CODE>
<BR>
</LI>
<LI>
<CODE>{disc_copies, Nodelist}</CODE>, where
<CODE>Nodelist</CODE> is a list of the nodes where this table
is supposed to have disc copies. If a table replica is
of type <CODE>disc_copies</CODE>, all write operations on this
particular replica of the table are written to disc as
well as to the RAM copy of the table.
<BR>
It is possible
to have a replicated table of type <CODE>disc_copies</CODE>
on one node, and another type on another node. The
default value is <CODE>[]</CODE>
<BR>
</LI>
<LI>
<CODE>{disc_only_copies, Nodelist}</CODE>, where
<CODE>Nodelist</CODE> is a list of the nodes where this table
is supposed to have <CODE>disc_only_copies</CODE>. A disc only
table replica is kept on disc only and unlike the other
replica types, the contents of the replica will not
reside in RAM. These replicas are considerably slower
than replicas held in RAM.
<BR>
</LI>
<LI>
<CODE>{index, Intlist}</CODE>, where
<CODE>Intlist</CODE> is a list of attribute names (atoms) or
record fields for which Mnesia shall build and maintain
an extra index table. The <CODE>qlc</CODE> query compiler may
or may not utilize any additional indices while
processing queries on a table.
<BR>
</LI>
<LI>
<CODE>{load_order, Integer}</CODE>. The load order
priority is by default <CODE>0</CODE> (zero) but may be set to
any integer. The tables with the highest load order
priority will be loaded first at startup.
<BR>
</LI>
<LI>
<CODE>{ram_copies, Nodelist}</CODE>, where
<CODE>Nodelist</CODE> is a list of the nodes where this table
is supposed to have RAM copies. A table replica of type
<CODE>ram_copies</CODE> is obviously not written to disc on a
per transaction basis. It is possible to dump
<CODE>ram_copies</CODE> replicas to disc with the function
<CODE>mnesia:dump_tables(Tabs)</CODE>. The default value for
this attribute is <CODE>[node()]</CODE>.
<BR>
</LI>
<LI>
<CODE>{record_name, Name}</CODE>, where <CODE>Name</CODE> must
be an atom. All records, stored in the table, must have
this name as the first element. It defaults to the same
name as the name of the table.
<BR>
</LI>
<LI>
<CODE>{snmp, SnmpStruct}</CODE>. See
<CODE>mnesia:snmp_open_table/2</CODE> for a description of
<CODE>SnmpStruct</CODE>. If this attribute is present in the
<CODE>ArgList</CODE> to <CODE>mnesia:create_table/2</CODE>, the
table is immediately accessible by means of the Simple
Network Management Protocol (SNMP). This means that
applications which use SNMP to manipulate and control
the system can be designed easily, since Mnesia provides
a direct mapping between the logical tables that make up
an SNMP control application and the physical data which
makes up a Mnesia table.
<BR>
</LI>
<LI>
<CODE>{type, Type}</CODE>, where <CODE>Type</CODE> must be
either of the atoms <CODE>set</CODE>, <CODE>ordered_set</CODE> or
<CODE>bag</CODE>. The default value is <CODE>set</CODE>. In a
<CODE>set</CODE> all records have unique keys and in a
<CODE>bag</CODE> several records may have the same key, but
the record content is unique. If a non-unique record is
stored the old, conflicting record(s) will simply be
overwritten. Note: currently 'ordered_set'
is not supported for 'disc_only_copies'.
<BR>
</LI>
<LI>
<CODE>{local_content, Bool}</CODE>, where <CODE>Bool</CODE> must be
either <CODE>true</CODE> or <CODE>false</CODE>. The default value is <CODE>false</CODE>.
<BR>
</LI>
</UL>
<P>For example, the following call creates the <CODE>person</CODE> table
previously defined and replicates it on 2 nodes:
<PRE>
mnesia:create_table(person,
[{ram_copies, [N1, N2]},
{attributes, record_info(fields,person)}]).
</PRE>
<P> If it was required that Mnesia build and maintain an extra index
table on the <CODE>address</CODE> attribute of all the <CODE>person</CODE>
records that are inserted in the table, the following code would be issued:
<PRE>
mnesia:create_table(person,
[{ram_copies, [N1, N2]},
{index, [address]},
{attributes, record_info(fields,person)}]).
</PRE>
<P> The specification of <CODE>index</CODE> and <CODE>attributes</CODE> may be
hard coded as <CODE>{index, [2]}</CODE> and
<CODE>{attributes, [name, age, address, salary, children]}</CODE>
respectively.
<P> <CODE>mnesia:create_table/2</CODE> writes records into the
<CODE>schema</CODE> table. This function, as well as all other
schema manipulation functions, are implemented with the
normal transaction management system. This guarantees that
schema updates are performed on all nodes in an atomic
manner.
</DIV>
<P><A NAME="deactivate_checkpoint/1"><STRONG><CODE>deactivate_checkpoint(Name) -> ok | {error, Reason}</CODE></STRONG></A><BR>
<DIV CLASS=REFBODY>
<P>The checkpoint is automatically deactivated when some of
the tables involved have no retainer attached to them. This may
happen when nodes go down or when a replica is deleted.
Checkpoints will also be deactivated with this function.
<CODE>Name</CODE> is the name of an active checkpoint.
</DIV>
<P><A NAME="del_table_copy/2"><STRONG><CODE>del_table_copy(Tab, Node) -> {aborted, R} | {atomic, ok}
</CODE></STRONG></A><BR>
<DIV CLASS=REFBODY>
<P> Deletes the replica of table <CODE>Tab</CODE> at node <CODE>Node</CODE>.
When the last replica is deleted with this
function, the table disappears entirely.
<P>This function may also be used to delete a replica of
the table named <CODE>schema</CODE>. Then the mnesia node will be removed.
Note: Mnesia must be stopped on the node first.
</DIV>
<P><A NAME="del_table_index/2"><STRONG><CODE>del_table_index(Tab, AttrName) -> {aborted, R} | {atomic, ok}
</CODE></STRONG></A><BR>
<DIV CLASS=REFBODY>
<P>This function deletes the index on attribute with name
<CODE>AttrName</CODE> in a table.
</DIV>
<P><A NAME="delete/2"><STRONG><CODE>delete({Tab, Key}) -> transaction abort | ok </CODE></STRONG></A><BR>
<DIV CLASS=REFBODY>
<P>Invokes <CODE>mnesia:delete(Tab, Key, write)</CODE>
</DIV>
<P><A NAME="delete/3"><STRONG><CODE>delete(Tab, Key, LockKind) -> transaction abort | ok </CODE></STRONG></A><BR>
<DIV CLASS=REFBODY>
<P>Deletes all records in table <CODE>Tab</CODE> with the key
<CODE>Key</CODE>.
<P>The semantics of this function is context sensitive. See
<CODE>mnesia:activity/4</CODE> for more information. In transaction
context it acquires a lock of type <CODE>LockKind</CODE> in the
record. Currently the lock types <CODE>write</CODE> and
<CODE>sticky_write</CODE> are supported.
</DIV>
<P><A NAME="delete_object/1"><STRONG><CODE>delete_object(Record) -> transaction abort | ok </CODE></STRONG></A><BR>
<DIV CLASS=REFBODY>
<P>Invokes <CODE>mnesia:delete_object(Tab, Record, write)</CODE> where
<CODE>Tab</CODE> is <CODE>element(1, Record)</CODE>.
</DIV>
<P><A NAME="delete_object/3"><STRONG><CODE>delete_object(Tab, Record, LockKind) -> transaction abort | ok </CODE></STRONG></A><BR>
<DIV CLASS=REFBODY>
<P> If a table is of type <CODE>bag</CODE>, we may sometimes
want to delete only some of the records with a certain
key. This can be done with the <CODE>delete_object/3</CODE>
function. A complete record must be supplied to this
function.
<P>The semantics of this function is context sensitive. See
<CODE>mnesia:activity/4</CODE> for more information. In transaction
context it acquires a lock of type <CODE>LockKind</CODE> on the
record. Currently the lock types <CODE>write</CODE> and
<CODE>sticky_write</CODE> are supported.
</DIV>
<P><A NAME="delete_schema/1"><STRONG><CODE>delete_schema(DiscNodes) -> ok | {error,Reason}
</CODE></STRONG></A><BR>
<DIV CLASS=REFBODY>
<P>Deletes a database created with
<CODE>mnesia:create_schema/1</CODE>.
<CODE>mnesia:delete_schema/1</CODE> fails if any of the Erlang
nodes given as <CODE>DiscNodes</CODE> is not alive, or if Mnesia
is running on any of the nodes.
<P>After the database has been deleted, it may still be
possible to start Mnesia as a disc-less node. This depends on
how the configuration parameter <CODE>schema_location</CODE> is set.
<P>
<TABLE CELLPADDING=4>
<TR>
<TD VALIGN=TOP><IMG ALT="Warning!" SRC="warning.gif"></TD>
<TD>
<P> This function must be used with extreme
caution since it makes existing persistent data
obsolete. Think twice before using it. </TD>
</TR>
</TABLE>
</DIV>
<P><A NAME="delete_table/1"><STRONG><CODE>delete_table(Tab) -> {aborted, Reason} | {atomic, ok}
</CODE></STRONG></A><BR>
<DIV CLASS=REFBODY>
<P>Permanently deletes all replicas of table <CODE>Tab</CODE>.
</DIV>
<P><A NAME="dirty_all_keys/1"><STRONG><CODE>dirty_all_keys(Tab) -> KeyList | exit({aborted, Reason}).
</CODE></STRONG></A><BR>
<DIV CLASS=REFBODY>
<P>This is the dirty equivalent of the
<CODE>mnesia:all_keys/1</CODE> function.
</DIV>
<P><A NAME="dirty_delete/2"><STRONG><CODE>dirty_delete({Tab, Key}) -> ok | exit({aborted, Reason}) </CODE></STRONG></A><BR>
<DIV CLASS=REFBODY>
<P>Invokes <CODE>mnesia:dirty_delete(Tab, Key)</CODE>.
</DIV>
<P><A NAME="dirty_delete/2"><STRONG><CODE>dirty_delete(Tab, Key) -> ok | exit({aborted, Reason}) </CODE></STRONG></A><BR>
<DIV CLASS=REFBODY>
<P>This is the dirty equivalent of the
<CODE>mnesia:delete/3</CODE> function.
</DIV>
<P><A NAME="dirty_delete_object/1"><STRONG><CODE>dirty_delete_object(Record) </CODE></STRONG></A><BR>
<DIV CLASS=REFBODY>
<P>Invokes <CODE>mnesia:dirty_delete_object(Tab, Record)</CODE>
where <CODE>Tab</CODE> is <CODE>element(1, Record)</CODE>.
</DIV>
<P><A NAME="dirty_delete_object/2"><STRONG><CODE>dirty_delete_object(Tab, Record) </CODE></STRONG></A><BR>
<DIV CLASS=REFBODY>
<P>This is the dirty equivalent of the
<CODE>mnesia:delete_object/3</CODE> function.
</DIV>
<P><A NAME="dirty_first/1"><STRONG><CODE>dirty_first(Tab) -> Key | exit({aborted, Reason}) </CODE></STRONG></A><BR>
<DIV CLASS=REFBODY>
<P> Records in <CODE>set</CODE> or <CODE>bag</CODE> tables are not ordered.
However, there
is an ordering of the records which is not known
to the user. Accordingly, it is possible to traverse a table by means
of this function in conjunction with the <CODE>mnesia:dirty_next/2</CODE>
function.
<P> If there are no records at all in the table, this function
returns the atom <CODE>'$end_of_table'</CODE>. For this reason, it
is highly undesirable, but not disallowed, to use this atom
as the key for any user records.
</DIV>
<P><A NAME="dirty_index_match_object/2"><STRONG><CODE>dirty_index_match_object(Pattern, Pos)</CODE></STRONG></A><BR>
<DIV CLASS=REFBODY>
<P>Invokes <CODE>mnesia:dirty_index_match_object(Tab, Pattern,
Pos)</CODE> where <CODE>Tab</CODE> is <CODE>element(1, Pattern)</CODE>.
</DIV>
<P><A NAME="dirty_index_match_object/3"><STRONG><CODE>dirty_index_match_object(Tab, Pattern, Pos)</CODE></STRONG></A><BR>
<DIV CLASS=REFBODY>
<P>This is the dirty equivalent of the
<CODE>mnesia:index_match_object/4</CODE> function.
</DIV>
<P><A NAME="dirty_index_read/3"><STRONG><CODE>dirty_index_read(Tab, SecondaryKey, Pos)</CODE></STRONG></A><BR>
<DIV CLASS=REFBODY>
<P>This is the dirty equivalent of the
<CODE>mnesia:index_read/3</CODE> function.
</DIV>
<P><A NAME="dirty_last/1"><STRONG><CODE>dirty_last(Tab) -> Key | exit({aborted, Reason}) </CODE></STRONG></A><BR>
<DIV CLASS=REFBODY>
<P> This function works exactly
<CODE>mnesia:dirty_first/1</CODE> but returns the last object in
Erlang term order for the <CODE>ordered_set</CODE> table type. For
all other table types, <CODE>mnesia:dirty_first/1</CODE> and
<CODE>mnesia:dirty_last/1</CODE> are synonyms.
</DIV>
<P><A NAME="dirty_match_object/1"><STRONG><CODE>dirty_match_object(Pattern) -> RecordList | exit({aborted, Reason}).
</CODE></STRONG></A><BR>
<DIV CLASS=REFBODY>
<P>Invokes <CODE>mnesia:dirty_match_object(Tab, Pattern)</CODE>
where <CODE>Tab</CODE> is <CODE>element(1, Pattern)</CODE>.
</DIV>
<P><A NAME="dirty_match_object/2"><STRONG><CODE>dirty_match_object(Tab, Pattern) -> RecordList | exit({aborted, Reason}).
</CODE></STRONG></A><BR>
<DIV CLASS=REFBODY>
<P>This is the dirty equivalent of the
<CODE>mnesia:match_object/3</CODE> function.
</DIV>
<P><A NAME="dirty_next/2"><STRONG><CODE>dirty_next(Tab, Key) -> Key | exit({aborted, Reason}) </CODE></STRONG></A><BR>
<DIV CLASS=REFBODY>
<P>This function makes it possible to traverse a table
and perform operations on all records in the table. When
the end of the table is reached, the special key
<CODE>'$end_of_table'</CODE> is returned. Otherwise, the function
returns a key which can be used to read the actual record.The
behavior is undefined if another Erlang process performs write
operations on the table while it is being traversed with the
<CODE>mnesia:dirty_next/2</CODE> function.
</DIV>
<P><A NAME="dirty_prev/2"><STRONG><CODE>dirty_prev(Tab, Key) -> Key | exit({aborted, Reason}) </CODE></STRONG></A><BR>
<DIV CLASS=REFBODY>
<P> This function works exactly
<CODE>mnesia:dirty_next/2</CODE> but returns the previous object in
Erlang term order for the ordered_set table type. For
all other table types, <CODE>mnesia:dirty_next/2</CODE> and
<CODE>mnesia:dirty_prev/2</CODE> are synonyms.
</DIV>
<P><A NAME="dirty_read/2"><STRONG><CODE>dirty_read({Tab, Key}) -> ValueList | exit({aborted, Reason}</CODE></STRONG></A><BR>
<DIV CLASS=REFBODY>
<P>Invokes <CODE>mnesia:dirty_read(Tab, Key)</CODE>.
</DIV>
<P><A NAME="dirty_read/2"><STRONG><CODE>dirty_read(Tab, Key) -> ValueList | exit({aborted, Reason}</CODE></STRONG></A><BR>
<DIV CLASS=REFBODY>
<P>This is the dirty equivalent of the
<CODE>mnesia:read/3</CODE> function.
</DIV>
<P><A NAME="dirty_select/2"><STRONG><CODE>dirty_select(Tab, MatchSpec) -> ValueList | exit({aborted, Reason}</CODE></STRONG></A><BR>
<DIV CLASS=REFBODY>
<P>This is the dirty equivalent of the
<CODE>mnesia:select/2</CODE> function.
</DIV>
<P><A NAME="dirty_slot/2"><STRONG><CODE>dirty_slot(Tab, Slot) -> RecordList | exit({aborted, Reason})
</CODE></STRONG></A><BR>
<DIV CLASS=REFBODY>
<P>This function can be used to traverse a table in a
manner similar to the <CODE>mnesia:dirty_next/2</CODE> function.
A table has a number of slots which range from 0 (zero) to some
unknown upper bound. The function
<CODE>mnesia:dirty_slot/2</CODE> returns the special atom
<CODE>'$end_of_table'</CODE> when the end of the table is reached.
The behavior of this function is undefined if a write
operation is performed on the table while it is being
traversed.
</DIV>
<P><A NAME="dirty_update_counter/3"><STRONG><CODE>dirty_update_counter({Tab, Key}, Incr) -> NewVal | exit({aborted, Reason})
</CODE></STRONG></A><BR>
<DIV CLASS=REFBODY>
<P>Invokes <CODE>mnesia:dirty_update_counter(Tab, Key, Incr)</CODE>.
</DIV>
<P><A NAME="dirty_update_counter/3"><STRONG><CODE>dirty_update_counter(Tab, Key, Incr) -> NewVal | exit({aborted, Reason})
</CODE></STRONG></A><BR>
<DIV CLASS=REFBODY>
<P>There are no special counter records in Mnesia. However,
records of the form <CODE>{Tab, Key, Integer}</CODE> can be used
as (possibly disc resident) counters, when <CODE>Tab</CODE> is a
<CODE>set</CODE>. This function updates a counter with a
positive or negative number. However, counters can never become less
than zero. There are two significant differences between
this function and the action of first reading the record,
performing the arithmetics, and then writing the record:
<P>
<UL>
<LI>
It is much more efficient
</LI>
<LI>
<CODE>mnesia:dirty_update_counter/3</CODE> is
performed as an atomic operation despite the fact that it is not
protected by a transaction.
</LI>
</UL>
<P> If two processes perform <CODE>mnesia:dirty_update_counter/3</CODE>
simultaneously, both updates will take effect without the
risk of loosing one of the updates. The new value
<CODE>NewVal</CODE> of the counter is returned.
<P> If <CODE>Key</CODE> don't exits, a new record is created with the value
<CODE>Incr</CODE> if it is larger than 0, otherwise it is set to 0.
</DIV>
<P><A NAME="dirty_write/1"><STRONG><CODE>dirty_write(Record) -> ok | exit({aborted, Reason})</CODE></STRONG></A><BR>
<DIV CLASS=REFBODY>
<P>Invokes <CODE>mnesia:dirty_write(Tab, Record)</CODE>
where <CODE>Tab</CODE> is <CODE>element(1, Record)</CODE>.
</DIV>
<P><A NAME="dirty_write/2"><STRONG><CODE>dirty_write(Tab, Record) -> ok | exit({aborted, Reason})</CODE></STRONG></A><BR>
<DIV CLASS=REFBODY>
<P>This is the dirty equivalent of <CODE>mnesia:write/3</CODE>.
</DIV>
<P><A NAME="dump_log/0"><STRONG><CODE>dump_log() -> dumped</CODE></STRONG></A><BR>
<DIV CLASS=REFBODY>
<P>Performs a user initiated dump of the local log file.
This is usually not necessary since Mnesia, by default,
manages this automatically.
</DIV>
<P><A NAME="dump_tables/1"><STRONG><CODE>dump_tables(TabList) -> {atomic, ok} | {aborted, Reason}</CODE></STRONG></A><BR>
<DIV CLASS=REFBODY>
<P>This function dumps a set of <CODE>ram_copies</CODE> tables
to disc. The next time the system is started, these tables
are initiated with the data found in the files that are the
result of this dump. None of the tables may have disc
resident replicas.
</DIV>
<P><A NAME="dump_to_textfile/1"><STRONG><CODE>dump_to_textfile(Filename) </CODE></STRONG></A><BR>
<DIV CLASS=REFBODY>
<P> Dumps all local tables of a mnesia system into a text file
which can then be edited (by means of a normal text editor)
and then later be reloaded with
<CODE>mnesia:load_textfile/1</CODE>. Only use this function for
educational purposes. Use other functions to deal with real
backups.
</DIV>
<P><A NAME="error_description/1"><STRONG><CODE>error_description(Error) -> String </CODE></STRONG></A><BR>
<DIV CLASS=REFBODY>
<P>All Mnesia transactions, including all the schema
update functions, either return the value <CODE>{atomic,
Val}</CODE> or the tuple <CODE>{aborted, Reason}</CODE>. The
<CODE>Reason</CODE> can be either of the following atoms. The
<CODE>error_description/1</CODE> function returns a descriptive
string which describes the error.
<P>
<UL>
<LI>
<CODE>nested_transaction</CODE>. Nested transactions are
not allowed in this context.
<BR>
</LI>
<LI>
<CODE>badarg</CODE>. Bad or invalid argument, possibly
bad type.
<BR>
</LI>
<LI>
<CODE>no_transaction</CODE>. Operation not allowed
outside transactions.
<BR>
</LI>
<LI>
<CODE>combine_error</CODE>. Table options were illegally
combined.
<BR>
</LI>
<LI>
<CODE>bad_index</CODE>. Index already exists or was out
of bounds.
<BR>
</LI>
<LI>
<CODE>already_exists</CODE>. Schema option is already set.
<BR>
</LI>
<LI>
<CODE>index_exists</CODE>. Some operations cannot be performed on
tabs with index.
<BR>
</LI>
<LI>
<CODE>no_exists</CODE>. Tried to perform operation on
non-existing, or not alive, item.
<BR>
</LI>
<LI>
<CODE>system_limit</CODE>. Some system_limit was exhausted.
<BR>
</LI>
<LI>
<CODE>mnesia_down</CODE>. A transaction involving
records at some remote node which died while
transaction was executing. Record(s) are no longer
available elsewhere in the network.
<BR>
</LI>
<LI>
<CODE>not_a_db_node</CODE>. A node which does not exist
in the schema was mentioned.
<BR>
</LI>
<LI>
<CODE>bad_type</CODE>. Bad type on some arguments.
<BR>
</LI>
<LI>
<CODE>node_not_running</CODE>. Node not running.
<BR>
</LI>
<LI>
<CODE>truncated_binary_file</CODE>. Truncated binary in file.
<BR>
</LI>
<LI>
<CODE>active</CODE>. Some delete operations require that
all active records are removed.
<BR>
</LI>
<LI>
<CODE>illegal</CODE>. Operation not supported on record.
<BR>
</LI>
</UL>
<P>The <CODE>Error</CODE> may be <CODE>Reason</CODE>,
<CODE>{error, Reason}</CODE>, or <CODE>{aborted, Reason}</CODE>. The
<CODE>Reason</CODE> may be an atom or a tuple with <CODE>Reason</CODE>
as an atom in the first field.
</DIV>
<P><A NAME="ets/3"><STRONG><CODE>ets(Fun, [, Args]) -> ResultOfFun | exit(Reason)</CODE></STRONG></A><BR>
<DIV CLASS=REFBODY>
<P>Call the <CODE>Fun</CODE> in a raw context which is not protected by
a transaction. The Mnesia function call is performed in the
<CODE>Fun</CODE> are performed directly on the local <CODE>ets</CODE> tables on
the assumption that the local storage type is
<CODE>ram_copies</CODE> and the tables are not replicated to other
nodes. Subscriptions are not triggered and checkpoints are
not updated, but it is extremely fast. This function can
also be applied to <CODE>disc_copies</CODE> tables if all
operations are read only. See <CODE>mnesia:activity/4</CODE>
and the Mnesia User's Guide for more details.
<P> <STRONG> Note:</STRONG> Calling (nesting) a <CODE>mnesia:ets</CODE>
inside a transaction context will inherit the transaction semantics.
</DIV>
<P><A NAME="first/1"><STRONG><CODE>first(Tab) -> Key | transaction abort </CODE></STRONG></A><BR>
<DIV CLASS=REFBODY>
<P> Records in <CODE>set</CODE> or <CODE>bag</CODE> tables are not ordered.
However, there
is an ordering of the records which is not known
to the user. Accordingly, it is possible to traverse a table by means
of this function in conjunction with the <CODE>mnesia:next/2</CODE>
function.
<P> If there are no records at all in the table, this function
returns the atom <CODE>'$end_of_table'</CODE>. For this reason, it
is highly undesirable, but not disallowed, to use this atom
as the key for any user records.
</DIV>
<P><A NAME="foldl/3"><STRONG><CODE>foldl(Function, Acc, Table) -> NewAcc | transaction abort </CODE></STRONG></A><BR>
<DIV CLASS=REFBODY>
<P>Iterates over the table <CODE>Table</CODE> and calls
<CODE>Function(Record, NewAcc)</CODE> for each <CODE>Record</CODE> in the table.
The term returned from <CODE>Function</CODE> will be used as the second
argument in the next call to the <CODE>Function</CODE>.
<P><CODE>foldl</CODE> returns the same term as the last call to
<CODE>Function</CODE> returned.
</DIV>
<P><A NAME="foldr/3"><STRONG><CODE>foldr(Function, Acc, Table) -> NewAcc | transaction abort </CODE></STRONG></A><BR>
<DIV CLASS=REFBODY>
<P> This function works exactly as
<CODE>foldl/3</CODE> but iterates the table in the opposite order
for the <CODE>ordered_set</CODE> table type. For
all other table types, <CODE>foldr/3</CODE> and
<CODE>foldl/3</CODE> are synonyms.
</DIV>
<P><A NAME="force_load_table/1"><STRONG><CODE>force_load_table(Tab) -> yes | ErrorDescription </CODE></STRONG></A><BR>
<DIV CLASS=REFBODY>
<P> The Mnesia algorithm for table load might lead to a
situation where a table cannot be loaded. This situation
occurs when a node is started and Mnesia concludes, or
suspects, that another copy of the table was active after
this local copy became inactive due to a system crash.
<P> If this situation is not acceptable, this function can be
used to override the strategy of the Mnesia table load
algorithm. This could lead to a situation where some
transaction effects are lost with a inconsistent database as
result, but for some applications high availability is more
important than consistent data.
</DIV>
<P><A NAME="index_match_object/2"><STRONG><CODE>index_match_object(Pattern, Pos) -> transaction abort | ObjList</CODE></STRONG></A><BR>
<DIV CLASS=REFBODY>
<P>Invokes <CODE>mnesia:index_match_object(Tab, Pattern, Pos,
read)</CODE> where <CODE>Tab</CODE> is <CODE>element(1,
Pattern)</CODE>.
</DIV>
<P><A NAME="index_match_object/4"><STRONG><CODE>index_match_object(Tab, Pattern, Pos, LockKind) -> transaction abort | ObjList</CODE></STRONG></A><BR>
<DIV CLASS=REFBODY>
<P> In a manner similar to the <CODE>mnesia:index_read/3</CODE>
function, we can also utilize any index information when we
try to match records. This function takes a pattern which
obeys the same rules as the <CODE>mnesia:match_object/3</CODE>
function with the exception that this function requires the
following conditions:
<P>
<UL>
<LI>
The table <CODE>Tab</CODE> must have an index on
position <CODE>Pos</CODE>.
<BR>
</LI>
<LI>
The element in position <CODE>Pos</CODE> in
<CODE>Pattern</CODE> must be bound. <CODE>Pos</CODE> may either be
an integer (#record.Field), or an attribute name.
<BR>
</LI>
</UL>
<P>The two index search functions described here are
automatically invoked when searching tables with <CODE>qlc</CODE>
list comprehensions and also when using the low level
<CODE>mnesia:[dirty_]match_object</CODE> functions.
<P>
<P>The semantics of this function is context sensitive. See
<CODE>mnesia:activity/4</CODE> for more information. In transaction
context it acquires a lock of type <CODE>LockKind</CODE> on the
entire table or on a single record. Currently, the lock type
<CODE>read</CODE> is supported.
</DIV>
<P><A NAME="index_read/3"><STRONG><CODE>index_read(Tab, SecondaryKey, Pos) -> transaction abort | RecordList
</CODE></STRONG></A><BR>
<DIV CLASS=REFBODY>
<P> Assume there is an index on position <CODE>Pos</CODE> for a
certain record type. This function can be used to read the
records without knowing the actual key for the record. For
example, with an index in position 1 of the <CODE>person</CODE>
table, the call <CODE>mnesia:index_read(person, 36,
#person.age)</CODE> returns a list of all persons with age
equal to 36. <CODE>Pos</CODE> may also be an attribute name
(atom), but if the notation <CODE>mnesia:index_read(person, 36,
age)</CODE> is used, the field position will be searched for in
runtime, for each call.
<P>The semantics of this function is context sensitive. See
<CODE>mnesia:activity/4</CODE> for more information. In transaction
context it acquires a read lock on the entire table.
</DIV>
<P><A NAME="info/0"><STRONG><CODE>info() -> ok </CODE></STRONG></A><BR>
<DIV CLASS=REFBODY>
<P>Prints some information about the system on the tty.
This function may be used even if Mnesia is not started.
However, more information will be displayed if Mnesia is
started.
</DIV>
<P><A NAME="install_fallback/1"><STRONG><CODE>install_fallback(Opaque) -> ok | {error,Reason}</CODE></STRONG></A><BR>
<DIV CLASS=REFBODY>
<P>Invokes <CODE>mnesia:install_fallback(Opaque, Args)</CODE> where
<CODE>Args</CODE> is <CODE>[{scope, global}]</CODE>.
</DIV>
<P><A NAME="install_fallback/2"><STRONG><CODE>install_fallback(Opaque), BackupMod) -> ok | {error,Reason}</CODE></STRONG></A><BR>
<DIV CLASS=REFBODY>
<P>Invokes <CODE>mnesia:install_fallback(Opaque, Args)</CODE> where
<CODE>Args</CODE> is <CODE>[{scope, global}, {module, BackupMod}]</CODE>.
</DIV>
<P><A NAME="install_fallback/2"><STRONG><CODE>install_fallback(Opaque, Args) -> ok | {error,Reason}</CODE></STRONG></A><BR>
<DIV CLASS=REFBODY>
<P>This function is used to install a backup as fallback. The
fallback will be used to restore the database at the next
start-up. Installation of fallbacks requires Erlang to be up
and running on all the involved nodes, but it does not
matter if Mnesia is running or not. The installation of the
fallback will fail if the local node is not one of the disc
resident nodes in the backup.
<P> <CODE>Args</CODE> is a list of the following tuples:
<P>
<UL>
<LI>
<CODE>{module, BackupMod}</CODE>.
All accesses of the backup media is performed via a
callback module named <CODE>BackupMod</CODE>. The
<CODE>Opaque</CODE> argument is forwarded to the callback
module which may interpret it as it wish. The default
callback module is called <CODE>mnesia_backup</CODE> and it
interprets the <CODE>Opaque</CODE> argument as a local
filename. The default for this module is also
configurable via the <CODE>-mnesia mnesia_backup</CODE>
configuration parameter. <BR>
</LI>
<LI>
<CODE>{scope, Scope}</CODE>
The <CODE>Scope</CODE> of a fallback may either be
<CODE>global</CODE> for the entire database or <CODE>local</CODE>
for one node. By default, the installation of a fallback
is a global operation which either is performed all
nodes with disc resident schema or none. Which nodes
that are disc resident or not, is determined from the
schema info in the backup.<BR>
If the <CODE>Scope</CODE> of the operation is <CODE>local</CODE>
the fallback will only be installed on the local node.
<BR>
</LI>
<LI>
<CODE>{mnesia_dir, AlternateDir}</CODE>
This argument is only valid if the scope of the
installation is <CODE>local</CODE>. Normally the installation
of a fallback is targeted towards the Mnesia directory
as configured with the <CODE>-mnesia dir</CODE> configuration
parameter. But by explicitly supplying an
<CODE>AlternateDir</CODE> the fallback will be installed there
regardless of the Mnesia directory configuration
parameter setting. After installation of a fallback on
an alternate Mnesia directory that directory is fully
prepared for usage as an active Mnesia directory.
<BR>
This is a somewhat dangerous feature which must be
used with care. By unintentional mixing of directories
you may easily end up with a inconsistent database, if
the same backup is installed on more than one directory.
<BR>
</LI>
</UL>
</DIV>
<P><A NAME="last/1"><STRONG><CODE>last(Tab) -> Key | transaction abort </CODE></STRONG></A><BR>
<DIV CLASS=REFBODY>
<P> This function works exactly
<CODE>mnesia:first/1</CODE> but returns the last object in
Erlang term order for the <CODE>ordered_set</CODE> table type. For
all other table types, <CODE>mnesia:first/1</CODE> and
<CODE>mnesia:last/1</CODE> are synonyms.
</DIV>
<P><A NAME="load_textfile/1"><STRONG><CODE>load_textfile(Filename)</CODE></STRONG></A><BR>
<DIV CLASS=REFBODY>
<P> Loads a series of definitions and data found in the
text file (generated with <CODE>mnesia:dump_to_textfile/1</CODE>)
into Mnesia. This function also starts Mnesia and possibly
creates a new schema. This function is intended for
educational purposes only and using other functions to deal
with real backups, is recommended.
</DIV>
<P><A NAME="lock/2"><STRONG><CODE>lock(LockItem, LockKind) -> GoodNodes | transaction abort</CODE></STRONG></A><BR>
<DIV CLASS=REFBODY>
<P>Write locks are normally acquired on all nodes where a
replica of the table resides (and is active). Read locks are
acquired on one node (the local node if a local
replica exists). Most of the context sensitive access functions
acquire an implicit lock if they are invoked in a
transaction context. The granularity of a lock may either
be a single record or an entire table.
<P>This function <CODE>mnesia:lock/2</CODE> is intended to support
explicit locking on tables but also intended for situations
when locks need to be acquired regardless of how tables are
replicated. Currently, two <CODE>LockKind</CODE>'s are supported:
<P>
<DL>
<DT>
<CODE>write</CODE>
</DT>
<DD>
Write locks are exclusive, which means that if one
transaction manages to acquire a write lock on an item,
no other transaction may acquire any kind of lock on the
same item.
<BR>
</DD>
<DT>
<CODE>read</CODE>
</DT>
<DD>
Read locks may be shared, which means that if one
transaction manages to acquire a read lock on an item,
other transactions may also acquire a read lock on the
same item. However, if someone has a read lock no one can
acquire a write lock at the same item. If some one has a
write lock no one can acquire a read lock nor
a write lock at the same item.
<BR>
</DD>
</DL>
<P>Conflicting lock requests are automatically queued if there
is no risk of a deadlock. Otherwise the transaction must be
aborted and executed again. Mnesia does this automatically
as long as the upper limit of maximum <CODE>retries</CODE> is not
reached. See <CODE>mnesia:transaction/3</CODE> for the details.
<P>For the sake of completeness sticky write locks will also
be described here even if a sticky write lock is not
supported by this particular function:
<P>
<DL>
<DT>
<CODE>stick_write</CODE>
</DT>
<DD>
Sticky write locks are a mechanism which can be used
to optimize write lock acquisition. If your application
uses replicated tables mainly for fault tolerance (as
opposed to read access optimization purpose), sticky
locks may be the best option available.
<BR>
When a sticky write lock is acquired, all nodes will be
informed which node is locked. Subsequently,
sticky lock requests from the same node will be
performed as a local operation without any
communication with other nodes. The sticky lock
lingers on the node even after the transaction has
ended. See the Mnesia User's Guide for more information.
<BR>
</DD>
</DL>
<P>Currently, two kinds of <CODE>LockItem</CODE>'s are supported by
this function:
<P>
<DL>
<DT>
<CODE>{table, Tab}</CODE>
</DT>
<DD>
This acquires a lock of type <CODE>LockKind</CODE> on the
entire table <CODE>Tab</CODE>.
<BR>
</DD>
<DT>
<CODE>{global, GlobalKey, Nodes}</CODE>
</DT>
<DD>
This acquires a lock of type <CODE>LockKind</CODE> on the
global resource <CODE>GlobalKey</CODE>. The lock is acquired
on all active nodes in the <CODE>Nodes</CODE> list.
<BR>
</DD>
</DL>
<P>Locks are released when the outermost transaction ends.
<P>The semantics of this function is context sensitive. See
<CODE>mnesia:activity/4</CODE> for more information. In transaction
context it acquires locks otherwise it just ignores the
request.
</DIV>
<P><A NAME="match_object/1"><STRONG><CODE>match_object(Pattern) ->transaction abort | RecList </CODE></STRONG></A><BR>
<DIV CLASS=REFBODY>
<P>Invokes <CODE>mnesia:match_object(Tab, Pattern, read)</CODE> where
<CODE>Tab</CODE> is <CODE>element(1, Pattern)</CODE>.
</DIV>
<P><A NAME="match_object/3"><STRONG><CODE>match_object(Tab, Pattern, LockKind) ->transaction abort | RecList </CODE></STRONG></A><BR>
<DIV CLASS=REFBODY>
<P>This function takes a pattern with 'don't care' variables
denoted as a '_' parameter. This function returns a list of
records which matched the pattern. Since the second element
of a record in a table is considered to be the key for the
record, the performance of this function depends on whether
this key is bound or not.
<P>For example, the call <CODE>mnesia:match_object(person, {person,
'_', 36, '_', '_'}, read)</CODE> returns a list of all person records with an
age field of thirty-six (36).
<P>The function <CODE>mnesia:match_object/3</CODE>
automatically uses indices if these exist. However, no
heuristics are performed in order to select the best
index.
<P>The semantics of this function is context sensitive. See
<CODE>mnesia:activity/4</CODE> for more information. In transaction
context it acquires a lock of type <CODE>LockKind</CODE> on the
entire table or a single record. Currently, the lock type
<CODE>read</CODE> is supported.
</DIV>
<P><A NAME="move_table_copy/3"><STRONG><CODE>move_table_copy(Tab, From, To) -> {aborted, Reason} | {atomic, ok}
</CODE></STRONG></A><BR>
<DIV CLASS=REFBODY>
<P>Moves the copy of table <CODE>Tab</CODE> from node
<CODE>From</CODE> to node <CODE>To</CODE>.
<P>The storage type is preserved. For example, a RAM table
moved from one node remains a RAM on the new node. It is
still possible for other transactions to read and write in
the table while it is being moved.
<P>This function cannot be used on <CODE>local_content</CODE> tables.
</DIV>
<P><A NAME="next/2"><STRONG><CODE>next(Tab, Key) -> Key | transaction abort </CODE></STRONG></A><BR>
<DIV CLASS=REFBODY>
<P>This function makes it possible to traverse a table
and perform operations on all records in the table. When
the end of the table is reached, the special key
<CODE>'$end_of_table'</CODE> is returned. Otherwise, the function
returns a key which can be used to read the actual record.
</DIV>
<P><A NAME="prev/2"><STRONG><CODE>prev(Tab, Key) -> Key | transaction abort </CODE></STRONG></A><BR>
<DIV CLASS=REFBODY>
<P> This function works exactly
<CODE>mnesia:next/2</CODE> but returns the previous object in
Erlang term order for the ordered_set table type. For
all other table types, <CODE>mnesia:next/2</CODE> and
<CODE>mnesia:prev/2</CODE> are synonyms.
</DIV>
<P><A NAME="read/2"><STRONG><CODE>read({Tab, Key}) -> transaction abort | RecordList </CODE></STRONG></A><BR>
<DIV CLASS=REFBODY>
<P>Invokes <CODE>mnesia:read(Tab, Key, read)</CODE>.
</DIV>
<P><A NAME="read/3"><STRONG><CODE>read(Tab, Key, LockKind) -> transaction abort | RecordList </CODE></STRONG></A><BR>
<DIV CLASS=REFBODY>
<P>This function reads all records from table <CODE>Tab</CODE> with
key <CODE>Key</CODE>. This function has the same semantics
regardless of the location of <CODE>Tab</CODE>. If the table is
of type <CODE>bag</CODE>, the <CODE>mnesia:read(Tab, Key)</CODE> can
return an arbitrarily long list. If the table is of type
<CODE>set</CODE>, the list is either of length 1, or <CODE>[]</CODE>.
<P>The semantics of this function is context sensitive. See
<CODE>mnesia:activity/4</CODE> for more information. In transaction
context it acquires a lock of type
<CODE>LockKind</CODE>. Currently, the lock types <CODE>read</CODE>,
<CODE>write</CODE> and <CODE>sticky_write</CODE> are supported.
<P> If the user wants to update the record it is more efficient to
use <CODE>write/sticky_write</CODE> as the LockKind.
</DIV>
<P><A NAME="read_lock_table/1"><STRONG><CODE>read_lock_table(Tab) -> ok | transaction abort</CODE></STRONG></A><BR>
<DIV CLASS=REFBODY>
<P>Invokes <CODE>mnesia:lock({table, Tab}, read)</CODE>.
</DIV>
<P><A NAME="report_event/1"><STRONG><CODE>report_event(Event) -> ok</CODE></STRONG></A><BR>
<DIV CLASS=REFBODY>
<P>When tracing a system of Mnesia applications it is useful
to be able to interleave Mnesia's own events with
application related events that give information about the
application context.
<P>Whenever the application begins a
new and demanding Mnesia task, or if it is entering a new
interesting phase in its execution, it may be a good idea to
use <CODE>mnesia:report_event/1</CODE>. The <CODE>Event</CODE> may be
any term and generates a <CODE>{mnesia_user, Event}</CODE> event
for any processes that subscribe to Mnesia system
events.
</DIV>
<P><A NAME="restore/2"><STRONG><CODE>restore(Opaque, Args) -> {atomic, RestoredTabs} |{aborted, Reason}</CODE></STRONG></A><BR>
<DIV CLASS=REFBODY>
<P>With this function, tables may be restored online from a
backup without restarting Mnesia. <CODE>Opaque</CODE> is forwarded
to the backup module. <CODE>Args</CODE> is a list of the following
tuples:
<P>
<UL>
<LI>
<CODE>{module,BackupMod}</CODE> The backup module
<CODE>BackupMod</CODE> will be used to access the backup
media. If omitted, the default backup module will be
used.
<BR>
</LI>
<LI>
<CODE>{skip_tables, TabList}</CODE> Where <CODE>TabList</CODE>
is a list of tables which should not be read from the
backup.
</LI>
<LI>
<CODE>{clear_tables, TabList}</CODE> Where
<CODE>TabList</CODE> is a list of tables which should be
cleared, before the records from the backup are inserted,
ie. all records in the tables are deleted before the
tables are restored. Schema information about the tables
is not cleared or read from backup.
</LI>
<LI>
<CODE>{keep_tables, TabList}</CODE> Where <CODE>TabList</CODE>
is a list of tables which should be not be cleared, before
the records from the backup are inserted, i.e. the records
in the backup will be added to the records in the table.
Schema information about the tables is not cleared or read
from backup.
</LI>
<LI>
<CODE>{recreate_tables, TabList}</CODE> Where
<CODE>TabList</CODE> is a list of tables which should be
re-created, before the records from the backup are
inserted. The tables are first deleted and then created with
the schema information from the backup. All the nodes in the
backup needs to be up and running.
</LI>
<LI>
<CODE>{default_op, Operation}</CODE> Where <CODE>Operation</CODE> is
one of the following operations <CODE>skip_tables</CODE>,
<CODE>clear_tables</CODE>, <CODE>keep_tables</CODE> or
<CODE>recreate_tables</CODE>. The default operation specifies
which operation should be used on tables from the backup
which are not specified in any of the lists above. If
omitted, the operation <CODE>clear_tables</CODE> will be used.
</LI>
</UL>
<P>The affected tables are write locked during the
restoration, but regardless of the lock conflicts caused by
this, the applications can continue to do their work while
the restoration is being performed. The restoration is
performed as one single transaction.
<P>If the database is
huge, it may not be possible to restore it online. In such
cases, the old database must be restored by installing a
fallback and then restart.
</DIV>
<P><A NAME="s_delete/2"><STRONG><CODE>s_delete({Tab, Key}) -> ok | transaction abort </CODE></STRONG></A><BR>
<DIV CLASS=REFBODY>
<P>Invokes <CODE>mnesia:delete(Tab, Key, sticky_write)</CODE>
</DIV>
<P><A NAME="s_delete_object/1"><STRONG><CODE>s_delete_object(Record) -> ok | transaction abort </CODE></STRONG></A><BR>
<DIV CLASS=REFBODY>
<P>Invokes <CODE>mnesia:delete_object(Tab, Record,
sticky_write)</CODE> where <CODE>Tab</CODE> is <CODE>element(1,
Record)</CODE>.
</DIV>
<P><A NAME="s_write/1"><STRONG><CODE>s_write(Record) -> ok | transaction abort </CODE></STRONG></A><BR>
<DIV CLASS=REFBODY>
<P>Invokes <CODE>mnesia:write(Tab, Record, sticky_write)</CODE>
where <CODE>Tab</CODE> is <CODE>element(1, Record)</CODE>.
</DIV>
<P><A NAME="schema/0"><STRONG><CODE>schema() -> ok </CODE></STRONG></A><BR>
<DIV CLASS=REFBODY>
<P>Prints information about all table definitions on the tty.
</DIV>
<P><A NAME="schema/1"><STRONG><CODE>schema(Tab) -> ok </CODE></STRONG></A><BR>
<DIV CLASS=REFBODY>
<P>Prints information about one table definition on the tty.
</DIV>
<P><A NAME="select/3"><STRONG><CODE>select(Tab, MatchSpec [, Lock]) -> transaction abort | [Object] </CODE></STRONG></A><BR>
<DIV CLASS=REFBODY>
<P> Matches the objects in the table <CODE>Tab</CODE> using a
match_spec as described in the ERTS Users Guide. Optionally a lock
<CODE>read</CODE> or <CODE>write</CODE> can be given as the third
argument, default is <CODE>read</CODE>. The return value depends
on the <CODE>MatchSpec</CODE>.
<P><STRONG> Note:</STRONG> for best performance <CODE>select</CODE> should
be used before any modifying operations are done on that table
in the same transaction, i.e. don't use <CODE>write</CODE> or <CODE>delete</CODE>
before a <CODE>select</CODE>.
<P> In its simplest forms the match_spec's look like this:
<P>
<UL>
<LI>
MatchSpec = [MatchFunction]
</LI>
<LI>
MatchFunction = {MatchHead, [Guard], [Result]}
</LI>
<LI>
MatchHead = tuple() | record()
</LI>
<LI>
Guard = {"Guardtest name", ...}
</LI>
<LI>
Result = "Term construct"
</LI>
</UL>
<P> See the ERTS Users Guide and <CODE>ets</CODE> documentation for a
complete description of the select.
<P> For example to find the names of all male persons with an age over 30 in table
Tab do:
<PRE>
MatchHead = #person{name='$1', sex=male, age='$2', _='_'},
Guard = {'>', '$2', 30},
Result = '$1',
mnesia:select(Tab,[{MatchHead, [Guard], [Result]}]),
</PRE>
</DIV>
<P><A NAME="select/4"><STRONG><CODE>select(Tab, MatchSpec, NObjects, Lock) -> transaction abort | {[Object],Cont} | '$end_of_table'</CODE></STRONG></A><BR>
<DIV CLASS=REFBODY>
<P> Matches the objects in the table <CODE>Tab</CODE> using a
match_spec as described in ERTS users guide, and returns
a chunk of terms and a continuation, the wanted number
of returned terms is specified by the <CODE>NObjects</CODE> argument.
The lock argument can be <CODE>read</CODE> or <CODE>write</CODE>.
The continuation should be used as argument to <CODE>mnesia:select/1</CODE>,
if more or all answers are needed.
<P><STRONG> Note:</STRONG> for best performance <CODE>select</CODE> should
be used before any modifying operations are done on that
table in the same transaction, i.e. don't use
<CODE>mnesia:write</CODE> or <CODE>mnesia:delete</CODE> before a
<CODE>mnesia:select</CODE>. For efficiency the <CODE>NObjects</CODE> is
a recommendation only and the result may contain anything
from an empty list to all available results.
</DIV>
<P><A NAME="select/1"><STRONG><CODE>select(Cont) -> transaction abort | {[Object],Cont} | '$end_of_table'</CODE></STRONG></A><BR>
<DIV CLASS=REFBODY>
<P>Selects more objects with the match specification initiated
by <CODE>mnesia:select/4</CODE>.
<P><STRONG> Note:</STRONG> Any modifying operations, i.e. <CODE>mnesia:write</CODE>
or <CODE>mnesia:delete</CODE>, that are done between the <CODE>mnesia:select/4</CODE>
and <CODE>mnesia:select/1</CODE> calls will not be visible in the result.
</DIV>
<P><A NAME="set_debug_level/1"><STRONG><CODE>set_debug_level(Level) -> OldLevel</CODE></STRONG></A><BR>
<DIV CLASS=REFBODY>
<P>Changes the internal debug level of Mnesia. See the
chapter about configuration parameters for details.
</DIV>
<P><A NAME="set_master_nodes/1"><STRONG><CODE>set_master_nodes(MasterNodes) -> ok | {error, Reason} </CODE></STRONG></A><BR>
<DIV CLASS=REFBODY>
<P>For each table Mnesia will determine its replica nodes
(<CODE>TabNodes</CODE>) and invoke <CODE>mnesia:set_master_nodes(Tab,
TabMasterNodes)</CODE> where <CODE>TabMasterNodes</CODE> is the
intersection of <CODE>MasterNodes</CODE> and <CODE>TabNodes</CODE>. See
<CODE>mnesia:set_master_nodes/2</CODE> about the semantics.
</DIV>
<P><A NAME="set_master_nodes/2"><STRONG><CODE>set_master_nodes(Tab, MasterNodes) -> ok | {error, Reason} </CODE></STRONG></A><BR>
<DIV CLASS=REFBODY>
<P>If the application detects that there has been a
communication failure (in a potentially partitioned network) which
may have caused an inconsistent database, it may use the
function <CODE>mnesia:set_master_nodes(Tab, MasterNodes)</CODE> to
define from which nodes each table will be loaded.
At startup Mnesia's normal table load algorithm will be
bypassed and the table will be loaded from one of the master
nodes defined for the table, regardless of when and if Mnesia
was terminated on other nodes. The <CODE>MasterNodes</CODE> may only
contain nodes where the table has a replica and if the
<CODE>MasterNodes</CODE> list is empty, the master node recovery
mechanism for the particular table will be reset and the
normal load mechanism will be used at next restart.
<P> The master node setting is always local and it may be
changed regardless of whether Mnesia is started or not.
<P>The database may also become inconsistent if the
<CODE>max_wait_for_decision</CODE> configuration parameter is used
or if <CODE>mnesia:force_load_table/1</CODE> is used.
</DIV>
<P><A NAME="snmp_close_table/1"><STRONG><CODE>snmp_close_table(Tab) -> {aborted, R} | {atomic, ok}
</CODE></STRONG></A><BR>
<DIV CLASS=REFBODY>
<P>Removes the possibility for SNMP to manipulate the
table.
</DIV>
<P><A NAME="snmp_get_mnesia_key/2"><STRONG><CODE>snmp_get_mnesia_key(Tab, RowIndex) -> {ok, Key} | undefined
</CODE></STRONG></A><BR>
<DIV CLASS=REFBODY><P>Types:
<DIV CLASS=REFTYPES>
<P>
<STRONG><CODE>Tab ::= atom()</CODE></STRONG><BR>
<STRONG><CODE>RowIndex ::= [integer()]</CODE></STRONG><BR>
<STRONG><CODE>Key ::= key() | {key(), key(), ...}</CODE></STRONG><BR>
<STRONG><CODE>key() ::= integer() | string() | [integer()]</CODE></STRONG><BR>
</DIV>
</DIV>
<DIV CLASS=REFBODY>
<P>Transforms an SNMP index to the corresponding Mnesia key.
If the SNMP table has multiple keys, the key is a tuple of
the key columns.
</DIV>
<P><A NAME="snmp_get_next_index/2"><STRONG><CODE>snmp_get_next_index(Tab, RowIndex) -> {ok, NextIndex} | endOfTable
</CODE></STRONG></A><BR>
<DIV CLASS=REFBODY><P>Types:
<DIV CLASS=REFTYPES>
<P>
<STRONG><CODE>Tab ::= atom()</CODE></STRONG><BR>
<STRONG><CODE>RowIndex ::= [integer()]</CODE></STRONG><BR>
<STRONG><CODE>NextIndex ::= [integer()]</CODE></STRONG><BR>
</DIV>
</DIV>
<DIV CLASS=REFBODY>
<P>The <CODE>RowIndex</CODE> may specify a non-existing row.
Specifically, it might be the empty list. Returns the index
of the next lexicographical row. If <CODE>RowIndex</CODE> is the
empty list, this function will return the index of the first row
in the table.
</DIV>
<P><A NAME="snmp_get_row/2"><STRONG><CODE>snmp_get_row(Tab, RowIndex) -> {ok, Row} | undefined
</CODE></STRONG></A><BR>
<DIV CLASS=REFBODY><P>Types:
<DIV CLASS=REFTYPES>
<P>
<STRONG><CODE>Tab ::= atom()</CODE></STRONG><BR>
<STRONG><CODE>RowIndex ::= [integer()]</CODE></STRONG><BR>
<STRONG><CODE>Row ::= record(Tab)</CODE></STRONG><BR>
</DIV>
</DIV>
<DIV CLASS=REFBODY>
<P>Makes it possible to read a row by its SNMP index. This
index is specified as an SNMP OBJECT IDENTIFIER, a list of
integers.
</DIV>
<P><A NAME="snmp_open_table/2"><STRONG><CODE>snmp_open_table(Tab, SnmpStruct) -> {aborted, R} |
{atomic, ok}
</CODE></STRONG></A><BR>
<DIV CLASS=REFBODY><P>Types:
<DIV CLASS=REFTYPES>
<P>
<STRONG><CODE>Tab ::= atom()</CODE></STRONG><BR>
<STRONG><CODE>SnmpStruct ::= [{key, type()}]</CODE></STRONG><BR>
<STRONG><CODE>type() ::= type_spec() | {type_spec(), type_spec(), ...}</CODE></STRONG><BR>
<STRONG><CODE>type_spec() ::= fix_string | string | integer</CODE></STRONG><BR>
</DIV>
</DIV>
<DIV CLASS=REFBODY>
<P>It is possible to establish a direct one to one mapping
between Mnesia tables and SNMP tables. Many
telecommunication applications are controlled and monitored
by the SNMP protocol. This connection between Mnesia and
SNMP makes it simple and convenient to achieve this.
<P>The <CODE>SnmpStruct</CODE> argument is a list of SNMP
information. Currently, the only information needed is
information about the key types in the table. It is not
possible to handle multiple keys in Mnesia, but many SNMP
tables have multiple keys. Therefore, the following
convention is used: if a table has multiple keys, these must
always be stored as a tuple of the keys. Information about
the key types is specified as a tuple of atoms describing
the types. The only significant type is
<CODE>fix_string</CODE>. This means that a string has fixed
size. For example:
<PRE>
mnesia:snmp_open_table(person, [{key, string}])
</PRE>
<P>causes the <CODE>person</CODE> table to be ordered as an SNMP
table.
<P>Consider the following schema for a table of company
employees. Each employee is identified by department number
and name. The other table column stores the telephone number:
<PRE>
mnesia:create_table(employee,
[{snmp, [{key, {integer, string}}]},
{attributes, record_info(fields, employees)}]),
</PRE>
<P>The corresponding SNMP table would have three columns;
<CODE>department</CODE>, <CODE>name</CODE> and <CODE>telno</CODE>.
<P>It is possible to have table columns that are not visible
through the SNMP protocol. These columns must be the last
columns of the table. In the previous example, the SNMP
table could have columns <CODE>department</CODE> and <CODE>name</CODE>
only. The application could then use the <CODE>telno</CODE> column
internally, but it would not be visible to the SNMP
managers.
<P>In a table monitored by SNMP, all elements must be
integers, strings, or lists of integers.
<P>When a table is SNMP ordered, modifications are more
expensive than usual, O(logN). And more memory is used.
<P><STRONG>Note:</STRONG>Only the lexicographical SNMP ordering is
implemented in Mnesia, not the actual SNMP monitoring.
</DIV>
<P><A NAME="start/0"><STRONG><CODE>start() -> ok | {error, Reason} </CODE></STRONG></A><BR>
<DIV CLASS=REFBODY>
<P> The start-up procedure for a set of Mnesia nodes is a
fairly complicated operation. A Mnesia system consists of a set
of nodes, with Mnesia started locally on all
participating nodes. Normally, each node has a directory where
all the Mnesia files are written. This directory will be
referred to as the Mnesia directory. Mnesia may also be
started on disc-less nodes. See <CODE>mnesia:create_schema/1</CODE>
and the Mnesia User's Guide for more information about disc-less
nodes.
<P> The set of nodes which makes up a Mnesia system is kept in
a schema and it is possible to add and remove Mnesia nodes
from the schema. The initial schema is normally created on
disc with the function <CODE>mnesia:create_schema/1</CODE>. On
disc-less nodes, a tiny default schema is generated each time
Mnesia is started. During the start-up procedure, Mnesia
will exchange schema information between the nodes in order
to verify that the table definitions are compatible.
<P>Each schema has a unique cookie which may be regarded as a
unique schema identifier. The cookie must be the same on all
nodes where Mnesia is supposed to run. See the Mnesia
User's Guide for more information about these details.
<P> The schema file, as well as all other files which Mnesia
needs, are kept in the Mnesia directory. The command line
option <CODE>-mnesia dir Dir</CODE> can be used to specify the
location of this directory to the Mnesia system. If no such
command line option is found, the name of the directory
defaults to <CODE>Mnesia.Node</CODE>.
<P><CODE>application:start(mnesia)</CODE> may also be used.
</DIV>
<P><A NAME="stop/0"><STRONG><CODE>stop() -> stopped </CODE></STRONG></A><BR>
<DIV CLASS=REFBODY>
<P> Stops Mnesia locally on the current node.
<P><CODE>application:stop(mnesia)</CODE> may also be used.
</DIV>
<P><A NAME="subscribe/1"><STRONG><CODE>subscribe(EventCategory)</CODE></STRONG></A><BR>
<DIV CLASS=REFBODY>
<P>Ensures that a copy of all events of type
<CODE>EventCategory</CODE> are sent to the caller. The event
types available are described in the Mnesia User's Guide.
</DIV>
<P><A NAME="sync_dirty/3"><STRONG><CODE>sync_dirty(Fun, [, Args]) -> ResultOfFun | exit(Reason) </CODE></STRONG></A><BR>
<DIV CLASS=REFBODY>
<P>Call the <CODE>Fun</CODE> in a context which is not protected
by a transaction. The Mnesia function calls performed in the
<CODE>Fun</CODE> are mapped to the corresponding dirty functions.
It is performed in almost the same context as
<CODE>mnesia:async_dirty/1,2</CODE>. The difference is that the
operations are performed synchronously. The caller waits for
the updates to be performed on all active replicas before
the <CODE>Fun</CODE> returns. See <CODE>mnesia:activity/4</CODE> and the
Mnesia User's Guide for more details.
</DIV>
<P><A NAME="sync_transaction/4"><STRONG><CODE>sync_transaction(Fun, [[, Args], Retries]) -> {aborted, Reason} | {atomic, ResultOfFun} </CODE></STRONG></A><BR>
<DIV CLASS=REFBODY>
<P> This function waits until data have been committed and
logged to disk (if disk is used) on every involved node before
it returns, otherwise it behaves as
<CODE>mnesia:transaction/[1,2,3]</CODE>.
<P> This functionality can be used to avoid that one process may overload
a database on another node.
</DIV>
<P><A NAME="system_info/1"><STRONG><CODE>system_info(InfoKey) -> Info | exit({aborted, Reason})</CODE></STRONG></A><BR>
<DIV CLASS=REFBODY>
<P>Returns information about the Mnesia system, such as
transaction statistics, db_nodes, and configuration parameters.
Valid keys are:
<P>
<UL>
<LI>
<CODE>all</CODE>. This argument returns a list of all
local system information. Each element is a
<CODE>{InfoKey, InfoVal}</CODE> tuples.<STRONG>Note:</STRONG> New <CODE>InfoKey</CODE>'s may
be added and old undocumented <CODE>InfoKey</CODE>'s may be removed without
notice.<BR>
</LI>
<LI>
<CODE>access_module</CODE>. This argument returns the name of
the module which is configured to be the activity access
callback module.
<BR>
</LI>
<LI>
<CODE>auto_repair</CODE>. This argument returns
<CODE>true</CODE> or <CODE>false</CODE> to indicate if Mnesia is
configured to invoke the auto repair facility on corrupted
disc files.
<BR>
</LI>
<LI>
<CODE>backup_module</CODE>. This argument returns the name of
the module which is configured to be the backup
callback module.
<BR>
</LI>
<LI>
<CODE>checkpoints</CODE>. This argument
returns a list of the names of the
checkpoints currently active on this node.
<BR>
</LI>
<LI>
<CODE>event_module</CODE>. This argument returns the name of
the module which is the event handler callback module.
<BR>
</LI>
<LI>
<CODE>db_nodes</CODE>. This argument returns
the nodes which make up the persistent database. Disc
less nodes will only be included in the list of nodes if
they explicitly has been added to the schema, e.g. with
<CODE>mnesia:add_table_copy/3</CODE>. The function can be
invoked even if Mnesia is not yet running.
<BR>
</LI>
<LI>
<CODE>debug</CODE>. This argument returns the current
debug level of Mnesia.
<BR>
</LI>
<LI>
<CODE>directory</CODE>. This argument returns the name of
the Mnesia directory. It can be invoked even if Mnesia is
not yet running.
<BR>
</LI>
<LI>
<CODE>dump_log_load_regulation</CODE>. This argument
returns a boolean which tells whether Mnesia is
configured to load regulate the dumper process or not.
This feature is temporary and will disappear in future
releases.
<BR>
</LI>
<LI>
<CODE>dump_log_time_threshold</CODE>. This argument
returns the time threshold for transaction log dumps in
milliseconds.
<BR>
</LI>
<LI>
<CODE>dump_log_update_in_place</CODE>. This argument
returns a boolean which tells whether Mnesia is
configured to perform the updates in the dets files
directly or if the updates should be performed in a copy
of the dets files.
<BR>
</LI>
<LI>
<CODE>dump_log_write_threshold</CODE>. This argument
returns the write threshold for transaction log dumps as
the number of writes to the transaction log.
<BR>
</LI>
<LI>
<CODE>extra_db_nodes</CODE>. This argument returns a list
of extra db_nodes to be contacted at start-up.
<BR>
</LI>
<LI>
<CODE>fallback_activated</CODE>. This argument returns
true if a fallback is activated, otherwise false.
<BR>
</LI>
<LI>
<CODE>held_locks</CODE>. This argument returns a list of
all locks held by the local Mnesia lock manager.
<BR>
</LI>
<LI>
<CODE>is_running</CODE>. This argument returns <CODE>yes</CODE>
or <CODE>no</CODE> to indicate if Mnesia is running. It may
also return <CODE>starting</CODE> or <CODE>stopping</CODE>. Can be
invoked even if Mnesia is not yet running.
<BR>
</LI>
<LI>
<CODE>local_tables</CODE>. This argument returns a list
of all tables which are configured to reside locally.
<BR>
</LI>
<LI>
<CODE>lock_queue</CODE>. This argument returns a list of
all transactions that are queued for execution by the
local lock manager.
<BR>
</LI>
<LI>
<CODE>log_version</CODE>. This argument returns the
version number of the Mnesia transaction log format.
<BR>
</LI>
<LI>
<CODE>master_node_tables</CODE>. This argument returns a
list of all tables with at least one master node.
<BR>
</LI>
<LI>
<CODE>protocol_version</CODE>. This argument
returns the version number
of the Mnesia inter-process communication protocol.
<BR>
</LI>
<LI>
<CODE>running_db_nodes</CODE>. This argument returns a
list of nodes where Mnesia currently is running. This
function can be invoked even if Mnesia is not yet
running, but it will then have slightly different
semantics. If Mnesia is down on the local node, the
function will return those other <CODE>db_nodes</CODE> and
<CODE>extra_db_nodes</CODE> that for the moment are up and
running. If Mnesia is started, the function will return
those nodes that Mnesia on the local node is fully
connected to. Only those nodes that Mnesia has exchanged
schema information with are included as
<CODE>running_db_nodes</CODE>. After the merge of schemas, the
local Mnesia system is fully operable and applications
may perform access of remote replicas. Before the schema
merge Mnesia will only operate locally. Sometimes there
may be more nodes included in the
<CODE>running_db_nodes</CODE> list than all <CODE>db_nodes</CODE>
and <CODE>extra_db_nodes</CODE> together.
<BR>
</LI>
<LI>
<CODE>schema_location</CODE>. This argument returns the
initial schema location.
<BR>
</LI>
<LI>
<CODE>subscribers</CODE>. This argument returns a list of
local processes currently subscribing to system events.
<BR>
</LI>
<LI>
<CODE>tables</CODE>. This argument returns a list of all
locally known tables.
<BR>
</LI>
<LI>
<CODE>transactions</CODE>. This argument returns a list
of all currently active local transactions.
<BR>
</LI>
<LI>
<CODE>transaction_failures</CODE>. This argument returns
a number which indicates how many transactions have
failed since Mnesia was started.
<BR>
</LI>
<LI>
<CODE>transaction_commits</CODE>. This argument returns a
number which indicates how many transactions have
terminated successfully since Mnesia was started.
<BR>
</LI>
<LI>
<CODE>transaction_restarts</CODE>. This argument returns
a number which indicates how many transactions have been
restarted since Mnesia was started.
<BR>
</LI>
<LI>
<CODE>transaction_log_writes</CODE>. This argument
returns a number which indicates the number of write
operation that have been performed to the transaction
log since start-up.
<BR>
</LI>
<LI>
<CODE>use_dir</CODE>. This argument returns a boolean
which indicates whether the Mnesia directory is used or
not. Can be invoked even if Mnesia is not yet running.
<BR>
</LI>
<LI>
<CODE>version</CODE>. This argument returns the current
version number of Mnesia.
<BR>
</LI>
</UL>
</DIV>
<P><A NAME="table/2"><STRONG><CODE>table(Tab [,[Option]]) -> QueryHandle </CODE></STRONG></A><BR>
<DIV CLASS=REFBODY>
<P><A NAME="qlc_table"><!-- Empty --></A>Returns a QLC (Query List Comprehension) query handle, see
<A HREF="javascript:erlhref('../../../../', 'stdlib', 'qlc.html');">qlc(3)</A>.The module <CODE>qlc</CODE> implements a query language, it
can use mnesia tables as sources of data. Calling
<CODE>mnesia:table/1,2</CODE> is the means to make the <CODE>mnesia</CODE>
table <CODE>Tab</CODE> usable to QLC.
<P> The list of Options may contain mnesia options or QLC
options, the following options are recognized by Mnesia:
<CODE>{traverse, SelectMethod},{lock,
Lock},{n_objects,Number}</CODE>, any other option is forwarded
to QLC. The <CODE>lock</CODE> option may be <CODE>read</CODE> or
<CODE>write</CODE>, default is <CODE>read</CODE>. The option
<CODE>n_objects</CODE> specifies (roughly) the number of objects
returned from mnesia to QLC. Queries to remote tables may
need a larger chunks to reduce network overhead, default
<CODE>100</CODE> objects at a time are returned. The option
<CODE>traverse</CODE> determines the method to traverse the whole
table (if needed), the default method is <CODE>select</CODE>:
<P>
<UL>
<LI>
<CODE>select</CODE>. The table is traversed by calling
<CODE>mnesia:select/4</CODE> and <CODE>mnesia:select/1</CODE>. The
match specification (the second argument of <CODE>select/3</CODE>)
is assembled by QLC: simple filters are
translated into equivalent match specifications while
more complicated filters have to be applied to all
objects returned by <CODE>select/3</CODE> given a match
specification that matches all objects.<BR>
</LI>
<LI>
<CODE>{select, MatchSpec}</CODE>. As for <CODE>select</CODE>
the table is traversed by calling <CODE>mnesia:select/3</CODE> and
<CODE>mnesia:select/1</CODE>. The difference is that the match
specification is explicitly given. This is how to state
match specifications that cannot easily be expressed
within the syntax provided by QLC.<BR>
</LI>
</UL>
</DIV>
<P><A NAME="table_info/2"><STRONG><CODE>table_info(Tab, InfoKey) -> Info | exit({aborted, Reason})</CODE></STRONG></A><BR>
<DIV CLASS=REFBODY>
<P>The <CODE>table_info/2</CODE> function takes two arguments.
The first is the name of a Mnesia table, the second is one of
the following keys:
<P>
<UL>
<LI>
<CODE>all</CODE>. This argument returns a list of all
local table information. Each element is a <CODE>{InfoKey,
ItemVal}</CODE> tuples. <STRONG>Note:</STRONG> New <CODE>InfoItem</CODE>'s may be
added and old undocumented <CODE>InfoItem</CODE>'s may be removed without
notice.<BR>
</LI>
<LI>
<CODE>access_mode</CODE>. This argument returns the
access mode of the table. The access mode may either be
read_only or read_write.
<BR>
</LI>
<LI>
<CODE>arity</CODE>. This argument returns the arity of
records in the table as specified in the schema.
<BR>
</LI>
<LI>
<CODE>attributes</CODE>. This argument returns the table
attribute names which are specified in the schema.
<BR>
</LI>
<LI>
<CODE>checkpoints</CODE>. This argument returns the names
of the currently active checkpoints which involves this
table on this node.
<BR>
</LI>
<LI>
<CODE>cookie</CODE>. This argument returns a table cookie
which is a unique system generated identifier for the
table. The cookie is used internally to ensure that two
different table definitions using the same table name
cannot accidentally be intermixed. The cookie is
generated when the table is initially created.
<BR>
</LI>
<LI>
<CODE>disc_copies</CODE>. This argument returns the nodes
where a disc_copy of the table resides according to the
schema.
<BR>
</LI>
<LI>
<CODE>disc_only_copies </CODE>. This argument returns the
nodes where a disc_only_copy of the table resides
according to the schema.
<BR>
</LI>
<LI>
<CODE>index</CODE>. This argument returns the list of
index position integers for the table.
<BR>
</LI>
<LI>
<CODE>load_node</CODE>. This argument returns the name of
the node that Mnesia loaded the table from. The
structure of the returned value is unspecified but may
be useful for debugging purposes.
<BR>
</LI>
<LI>
<CODE>load_order</CODE>. This argument returns the load
order priority of the table. It is an integer and
defaults to <CODE>0</CODE> (zero).
<BR>
</LI>
<LI>
<CODE>load_reason</CODE>. This argument returns the
reason of why Mnesia decided to load the table. The
structure of the returned value is unspecified but may
be useful for debugging purposes.
<BR>
</LI>
<LI>
<CODE>local_content</CODE>. This argument returns
<CODE>true</CODE> or <CODE>false</CODE> to indicate whether the
table is configured to have locally unique content on
each node.
<BR>
</LI>
<LI>
<CODE>master_nodes</CODE>. This argument returns the
master nodes of a table.
<BR>
</LI>
<LI>
<CODE>memory</CODE>. This argument returns the number of
words allocated to the table on this node.
<BR>
</LI>
<LI>
<CODE>ram_copies</CODE>. This argument returns the nodes
where a ram_copy of the table resides according to the
schema.
<BR>
</LI>
<LI>
<CODE>record_name</CODE>. This argument returns the
record name, common for all records in the table
<BR>
</LI>
<LI>
<CODE>size</CODE>. This argument returns the number of
records inserted in the table.
<BR>
</LI>
<LI>
<CODE>snmp</CODE>. This argument returns the SNMP struct.
<CODE>[]</CODE>meaning that the table currently has no SNMP
properties.
<BR>
</LI>
<LI>
<CODE>storage_type</CODE>.This argument returns the local
storage type of the table. It can be <CODE>disc_copies</CODE>,
<CODE>ram_copies</CODE>, <CODE>disc_only_copies</CODE>, or the atom
<CODE>unknown</CODE>. <CODE>unknown</CODE> is returned for all
tables which only reside remotely.
<BR>
</LI>
<LI>
<CODE>subscribers</CODE>. This argument returns a list
of local processes currently subscribing to local table
events which involve this table on this node.
<BR>
</LI>
<LI>
<CODE>type</CODE>. This argument returns the table type,
which is either <CODE>bag</CODE>, <CODE>set</CODE> or <CODE>ordered_set</CODE>..
<BR>
</LI>
<LI>
<CODE>user_properties</CODE>. This argument returns the
user associated table properties of the table. It is a
list of the stored property records.
<BR>
</LI>
<LI>
<CODE>version</CODE>. This argument returns the current
version of the table definition. The table version is
incremented when the table definition is changed. The
table definition may be incremented directly when the
table definition has been changed in a schema
transaction, or when a committed table definition is
merged with table definitions from other nodes during
start-up.
<BR>
</LI>
<LI>
<CODE>where_to_read</CODE>.This argument returns the node
where the table can be read. If the value <CODE>nowhere</CODE>
is returned, the table is not loaded, or it resides at a
remote node which is not running.
<BR>
</LI>
<LI>
<CODE>where_to_write</CODE>. This argument returns a list
of the nodes that currently hold an active replica of
the table.
<BR>
</LI>
<LI>
<CODE>wild_pattern</CODE>. This argument returns a
structure which can be given to the various match
functions for a certain table. A record tuple is where all
record fields have the value <CODE>'_'</CODE>.
<BR>
</LI>
</UL>
</DIV>
<P><A NAME="transaction/3"><STRONG><CODE>transaction(Fun [[, Args], Retries]) -> {aborted, Reason} | {atomic, ResultOfFun}
</CODE></STRONG></A><BR>
<DIV CLASS=REFBODY>
<P> This function executes the functional object <CODE>Fun</CODE>
with arguments <CODE>Args</CODE> as a transaction.
<P> The code which executes inside the transaction
can consist of a series of table manipulation functions.
If something goes wrong inside the transaction as a result of a
user error or a certain table not being available, the
entire transaction is aborted and the function
<CODE>transaction/1</CODE> returns the tuple
<CODE>{aborted, Reason}</CODE>.
<P> If all is well, <CODE>{atomic, ResultOfFun}</CODE> is returned where
<CODE>ResultOfFun</CODE> is the value of the last expression in
<CODE>Fun</CODE>.
<P>A function which adds a family to the database can be
written as follows if we have a structure <CODE>{family,
Father, Mother, ChildrenList}</CODE>:
<PRE>
add_family({family, F, M, Children}) ->
ChildOids = lists:map(fun oid/1, Children),
Trans = fun() ->
mnesia:write(F#person{children = ChildOids},
mnesia:write(M#person{children = ChildOids},
Write = fun(Child) -> mnesia:write(Child) end,
lists:foreach(Write, Children)
end,
mnesia:transaction(Trans).
oid(Rec) -> {element(1, Rec), element(2, Rec)}.
</PRE>
<P>This code adds a set of people to the database. Running this code
within one transaction will ensure that either the whole
family is added to the database, or the whole transaction
aborts. For example, if the last child is badly formatted,
or the executing process terminates due to an
<CODE>'EXIT'</CODE> signal while executing the family code, the
transaction aborts. Accordingly, the situation where half a
family is added can never occur.
<P>It is also useful to update the database within a transaction
if several processes concurrently update the same records.
For example, the function <CODE>raise(Name, Amount)</CODE>, which
adds <CODE>Amount</CODE> to the salary field of a person, should
be implemented as follows:
<PRE>
raise(Name, Amount) ->
mnesia:transaction(fun() ->
case mnesia:wread({person, Name}) of
[P] ->
Salary = Amount + P#person.salary,
P2 = P#person{salary = Salary},
mnesia:write(P2);
_ ->
mnesia:abort("No such person")
end
end).
</PRE>
<P>When this function executes within a transaction,
several processes running on different nodes can concurrently
execute the <CODE>raise/2</CODE> function without interfering
with each other.
<P>Since Mnesia detects deadlocks, a transaction can be
restarted any number of times. This function will attempt a restart as specified in
<CODE>Retries</CODE>. <CODE>Retries</CODE> must
be an integer greater than 0 or the atom <CODE>infinity</CODE>. Default is
<CODE>infinity</CODE>.
</DIV>
<P><A NAME="transform_table/4"><STRONG><CODE>transform_table(Tab, Fun, NewAttributeList, NewRecordName) ->
{aborted, R} | {atomic, ok} </CODE></STRONG></A><BR>
<DIV CLASS=REFBODY>
<P> This function applies the argument <CODE>Fun</CODE> to all
records in the table. <CODE>Fun</CODE> is a function which takes a
record of the old type and returns a transformed record of the
new type. The <CODE>Fun</CODE> argument can also be the atom
<CODE>ignore</CODE>, it indicates that only the meta data about the table will
be updated. Usage of <CODE>ignore</CODE> is not recommended but included
as a possibility for the user do to his own transform.
<CODE>NewAttributeList</CODE> and <CODE>NewRecordName</CODE>
specifies the attributes and the new record type of converted
table. Table name will always remain unchanged, if the
record_name is changed only the mnesia functions which
uses table identifiers will work, e.g. <CODE>mnesia:write/3</CODE>
will work but <CODE>mnesia:write/1</CODE> will not.
</DIV>
<P><A NAME="transform_table/3"><STRONG><CODE>transform_table(Tab, Fun, NewAttributeList) ->
{aborted, R} | {atomic, ok} </CODE></STRONG></A><BR>
<DIV CLASS=REFBODY>
<P> Invokes <CODE>mnesia:transform_table(Tab, Fun, NewAttributeList, RecName)</CODE>
where <CODE>RecName</CODE> is <CODE>mnesia:table_info(Tab, record_name)</CODE>.
</DIV>
<P><A NAME="traverse_backup/6"><STRONG><CODE>traverse_backup(Source, [SourceMod,] Target, [TargetMod,]
Fun, Acc) -> {ok, LastAcc} | {error, Reason}</CODE></STRONG></A><BR>
<DIV CLASS=REFBODY>
<P>With this function it is possible to iterate over a backup,
either for the purpose of transforming it into a new backup,
or just reading it. The arguments are explained briefly
below. See the Mnesia User's Guide for additional
details.
<P>
<UL>
<LI>
<CODE>SourceMod</CODE> and <CODE>TargetMod</CODE> are the names of
the modules which actually access the backup
media.
</LI>
<LI>
<CODE>Source</CODE> and <CODE>Target</CODE> are opaque data used
exclusively by the modules <CODE>SourceMod</CODE> and
<CODE>TargetMod</CODE> for the purpose of initializing the
backup media.
</LI>
<LI>
<CODE>Acc</CODE> is an initial accumulator value.
</LI>
<LI>
<CODE>Fun(BackupItems, Acc)</CODE> is applied to each item in
the backup. The Fun must return a tuple
<CODE>{BackupItems,NewAcc}</CODE>, where <CODE>BackupItems</CODE> is
a list of valid backup items, and <CODE>NewAcc</CODE> is a new
accumulator value. The returned backup items are written
in the target backup.
</LI>
<LI>
<CODE>LastAcc</CODE> is the last accumulator value. This is
the last <CODE>NewAcc</CODE> value that was returned by <CODE>Fun</CODE>.
</LI>
</UL>
</DIV>
<P><A NAME="uninstall_fallback/0"><STRONG><CODE>uninstall_fallback() -> ok | {error,Reason}</CODE></STRONG></A><BR>
<DIV CLASS=REFBODY>
<P>Invokes <CODE>mnesia:uninstall_fallback([{scope, global}])</CODE>.
</DIV>
<P><A NAME="uninstall_fallback/1"><STRONG><CODE>uninstall_fallback(Args) -> ok | {error,Reason}</CODE></STRONG></A><BR>
<DIV CLASS=REFBODY>
<P>This function is used to de-install a fallback before it
has been used to restore the database. This is normally a
distributed operation that is either performed on all
nodes with disc resident schema or none. Uninstallation of
fallbacks requires Erlang to be up and running on all
involved nodes, but it does not matter if Mnesia is running
or not. Which nodes that are considered as disc-resident
nodes is determined from the schema info in the local
fallback.
<P> <CODE>Args</CODE> is a list of the following tuples:
<P>
<UL>
<LI>
<CODE>{module, BackupMod}</CODE>.
See <CODE>mnesia:install_fallback/2</CODE> about the
semantics.<BR>
</LI>
<LI>
<CODE>{scope, Scope}</CODE>
See <CODE>mnesia:install_fallback/2</CODE> about the
semantics.<BR>
</LI>
<LI>
<CODE>{mnesia_dir, AlternateDir}</CODE>
See <CODE>mnesia:install_fallback/2</CODE> about the
semantics.<BR>
</LI>
</UL>
</DIV>
<P><A NAME="unsubscribe/1"><STRONG><CODE>unsubscribe(EventCategory)</CODE></STRONG></A><BR>
<DIV CLASS=REFBODY>
<P>Stops sending events of type
<CODE>EventCategory</CODE> to the caller.
</DIV>
<P><A NAME="wait_for_tables/2"><STRONG><CODE>wait_for_tables(TabList,Timeout) -> ok | {timeout, BadTabList} | {error, Reason} </CODE></STRONG></A><BR>
<DIV CLASS=REFBODY>
<P> Some applications need to wait for certain tables to
be accessible in order to do useful work.
<CODE>mnesia:wait_for_tables/2</CODE> hangs until all tables in the
<CODE>TabList</CODE> are accessible, or until <CODE>timeout</CODE> is
reached.
</DIV>
<P><A NAME="wread/2"><STRONG><CODE>wread({Tab, Key}) -> transaction abort | RecordList </CODE></STRONG></A><BR>
<DIV CLASS=REFBODY>
<P>Invoke <CODE>mnesia:read(Tab, Key, write)</CODE>.
</DIV>
<P><A NAME="write/1"><STRONG><CODE>write(Record) -> transaction abort | ok </CODE></STRONG></A><BR>
<DIV CLASS=REFBODY>
<P>Invoke <CODE>mnesia:write(Tab, Record, write)</CODE> where
<CODE>Tab</CODE> is <CODE>element(1, Record)</CODE>.
</DIV>
<P><A NAME="write/3"><STRONG><CODE>write(Tab, Record, LockKind) -> transaction abort | ok </CODE></STRONG></A><BR>
<DIV CLASS=REFBODY>
<P>Writes the record <CODE>Record</CODE> to the table <CODE>Tab</CODE>.
<P>The function returns <CODE>ok</CODE>, or aborts if an error
occurs. For example, the transaction aborts if no
<CODE>person</CODE> table exists.
<P>The semantics of this function is context sensitive. See
<CODE>mnesia:activity/4</CODE> for more information. In transaction
context it acquires a lock of type <CODE>LockKind</CODE>. The
following lock types are supported: <CODE>write</CODE> and
<CODE>sticky_write</CODE>.
</DIV>
<P><A NAME="write_lock_table/1"><STRONG><CODE>write_lock_table(Tab) -> ok | transaction abort</CODE></STRONG></A><BR>
<DIV CLASS=REFBODY>
<P>Invokes <CODE>mnesia:lock({table, Tab}, write)</CODE>.
</DIV>
<H3>Configuration Parameters</H3>
<DIV CLASS=REFBODY>
<P>Mnesia reads the following application configuration
parameters:
<P>
<UL>
<LI>
<CODE>-mnesia access_module Module</CODE>. The
name of the Mnesia activity access callback module. The default is
<CODE>mnesia</CODE>.
<BR>
</LI>
<LI>
<CODE>-mnesia auto_repair true | false</CODE>. This flag controls
whether Mnesia will try to automatically repair
files that have not been properly closed. The default is
<CODE>true</CODE>.
<BR>
</LI>
<LI>
<CODE>-mnesia backup_module Module</CODE>. The
name of the Mnesia backup callback module. The default is
<CODE>mnesia_backup</CODE>.
<BR>
</LI>
<LI>
<CODE>-mnesia debug Level</CODE>
Controls the debug level of Mnesia.
Possible values are:
<BR>
<DL>
<DT>
<CODE>none</CODE>
</DT>
<DD>
No trace outputs at all. This is the default setting.
<BR>
</DD>
<DT>
<CODE>verbose</CODE>
</DT>
<DD>
Activates tracing of important debug events. These
debug events generate <CODE>{mnesia_info, Format, Args}</CODE>
system events. Processes may subscribe to these events with
<CODE>mnesia:subscribe/1</CODE>. The events are always sent to Mnesia's
event handler.
<BR>
</DD>
<DT>
<CODE>debug</CODE>
</DT>
<DD>
Activates all events at the verbose level plus full
trace of all debug events. These debug events generate
<CODE>{mnesia_info, Format, Args}</CODE> system events. Processes may
subscribe to these events with <CODE>mnesia:subscribe/1</CODE>. The
events are always sent to the Mnesia event handler. On this
debug level, the Mnesia event handler starts subscribing to
updates in the schema table.
<BR>
</DD>
<DT>
<CODE>trace</CODE>
</DT>
<DD>
Activates all events at the level debug. On this
debug level, the Mnesia event handler starts subscribing to
updates on all Mnesia tables. This level is only intended
for debugging small toy systems since many large
events may be generated.
<BR>
</DD>
<DT>
<CODE>false</CODE>
</DT>
<DD>
An alias for none.
<BR>
</DD>
<DT>
<CODE>true</CODE>
</DT>
<DD>
An alias for debug.
<BR>
</DD>
</DL>
</LI>
<LI>
<CODE>-mnesia core_dir Directory</CODE>. The name of the
directory where Mnesia core files is stored or
false. Setting it implies that also ram only nodes, will
generate a core file if a crash occurs.
<BR>
</LI>
<LI>
<CODE>-mnesia dir Directory</CODE>. The name of the directory
where all Mnesia data is stored. The name of the directory must
be unique for the current node. Two nodes may, under no
circumstances, share the same Mnesia directory. The results are
totally unpredictable.<BR>
</LI>
<LI>
<CODE>-mnesia dump_log_load_regulation true | false</CODE>.
Controls if the log dumps should be performed as fast as
possible or if the dumper should do its own load
regulation. This feature is temporary and will disappear in a
future release. The default is <CODE>false</CODE>.
<BR>
</LI>
<LI>
<CODE>-mnesia dump_log_update_in_place true | false</CODE>.
Controls if log dumps are performed on a copy of
the original data file, or if the log dump is
performed on the original data file. The default is <CODE>true</CODE>
<BR>
</LI>
<LI>
<CODE>-mnesia dump_log_write_threshold Max</CODE>, where
<CODE>Max</CODE> is an integer which specifies the maximum number of writes
allowed to the transaction log before a new dump of the log
is performed. It defaults to 100 log writes.
<BR>
</LI>
<LI>
<CODE>-mnesia dump_log_time_threshold Max</CODE>,
where <CODE>Max</CODE> is an integer which
specifies the dump log interval in milliseconds. It defaults
to 3 minutes. If a dump has not been performed within
<CODE>dump_log_time_threshold</CODE> milliseconds, then a new dump is
performed regardless of how many writes have been
performed.
<BR>
</LI>
<LI>
<CODE>-mnesia event_module Module</CODE>. The
name of the Mnesia event handler callback module. The default is
<CODE>mnesia_event</CODE>.
<BR>
</LI>
<LI>
<CODE>-mnesia extra_db_nodes Nodes</CODE> specifies a list of
nodes, in addition to the ones found in the schema, with which
Mnesia should also establish contact. The default value
is the empty list <CODE>[]</CODE>.
<BR>
</LI>
<LI>
<CODE>-mnesia fallback_error_function {UserModule, UserFunc}</CODE>
specifies a user supplied callback function
which will be called if a fallback is installed and mnesia
goes down on another node. Mnesia will call the function
with one argument the name of the dying node, e.g.
<CODE>UserModule:UserFunc(DyingNode)</CODE>.
Mnesia should be restarted or else
the database could be inconsistent.
The default behaviour is to terminate mnesia.
<BR>
</LI>
<LI>
<CODE>-mnesia max_wait_for_decision Timeout</CODE>. Specifies
how long Mnesia will wait for other nodes to share their
knowledge regarding the outcome of an unclear transaction. By
default the <CODE>Timeout</CODE> is set to the atom
<CODE>infinity</CODE>, which implies that if Mnesia upon startup
encounters a "heavyweight transaction" whose outcome is
unclear, the local Mnesia will wait until Mnesia is started
on some (in worst cases all) of the other nodes that were
involved in the interrupted transaction. This is a very rare
situation, but when/if it happens, Mnesia does not guess if
the transaction on the other nodes was committed or aborted.
Mnesia will wait until it knows the outcome and then act
accordingly.
<BR>
If <CODE>Timeout</CODE> is set to an integer value in
milliseconds, Mnesia will force "heavyweight transactions"
to be finished, even if the outcome of the transaction for
the moment is unclear. After <CODE>Timeout</CODE> milliseconds,
Mnesia will commit/abort the transaction and continue with
the startup. This may lead to a situation where the
transaction is committed on some nodes and aborted on other
nodes. If the transaction was a schema transaction, the
inconsistency may be fatal.
<BR>
</LI>
<LI>
<CODE>-mnesia no_table_loaders NUMBER</CODE> specifies the number of
parallel table loaders during start. More loaders can be good if the
network latency is high or if many tables contains few records.
The default value is <CODE>2</CODE>.
<BR>
</LI>
<LI>
<CODE>-mnesia schema_location Loc</CODE> controls where
Mnesia will look for its schema. The parameter
<CODE>Loc</CODE> may be one of the following atoms:
<BR>
<DL>
<DT>
<CODE>disc</CODE>
</DT>
<DD>
Mandatory disc. The schema is assumed to be located
in the Mnesia directory. If the schema cannot be found,
Mnesia refuses to start. This is the old behavior.
<BR>
</DD>
<DT>
<CODE>ram</CODE>
</DT>
<DD>
Mandatory RAM. The schema resides in RAM
only. At start-up, a tiny new schema is generated. This
default schema just contains the definition of the schema
table and only resides on the local node. Since no other
nodes are found in the default schema, the configuration
parameter <CODE>extra_db_nodes</CODE> must be used in
order to let the
node share its table definitions with other nodes. (The
<CODE>extra_db_nodes</CODE> parameter may also be used on disc based nodes.)
<BR>
</DD>
<DT>
<CODE>opt_disc</CODE>
</DT>
<DD>
Optional disc. The schema may reside either on disc
or in RAM. If the schema is found on disc, Mnesia starts as a
disc based node and the storage type of the schema table is
<CODE>disc_copies</CODE>. If no schema is found on disc, Mnesia starts
as a disc-less node and the storage type of the schema table is
<CODE>ram_copies</CODE>. The default value for the application parameter
is <CODE>opt_disc</CODE>.
<BR>
</DD>
</DL>
</LI>
</UL>
<P>First the SASL application parameters are checked, then
the command line flags are checked, and finally, the default
value is chosen.
</DIV>
<H3>See Also</H3>
<DIV CLASS=REFBODY>
<P> mnesia_registry(3), mnesia_session(3), qlc(3),
dets(3), ets(3), disk_log(3), application(3)
</DIV>
<H3>AUTHORS</H3>
<DIV CLASS=REFBODY>
Claes Wikstrm - support@erlang.ericsson.se<BR>
Hans Nilsson - support@erlang.ericsson.se<BR>
Hkan Mattsson - support@erlang.ericsson.se<BR>
</DIV>
<CENTER>
<HR>
<SMALL>mnesia 4.3.3<BR>
Copyright © 1991-2006
<A HREF="http://www.erlang.se">Ericsson AB</A><BR>
</SMALL>
</CENTER>
</BODY>
</HTML>
|