| 1831 | |
| 1832 | |
| 1833 | void TRA_sweep(thread_db* tdbb) |
| 1834 | { |
| 1835 | /************************************** |
| 1836 | * |
| 1837 | * T R A _ s w e e p |
| 1838 | * |
| 1839 | ************************************** |
| 1840 | * |
| 1841 | * Functional description |
| 1842 | * Make a garbage collection pass thru database. |
| 1843 | * |
| 1844 | **************************************/ |
| 1845 | SET_TDBB(tdbb); |
| 1846 | Database* const dbb = tdbb->getDatabase(); |
| 1847 | CHECK_DBB(dbb); |
| 1848 | |
| 1849 | dbb->initiateSweepRun(tdbb); |
| 1850 | |
| 1851 | fb_assert(dbb->dbb_flags & DBB_sweep_in_progress); |
| 1852 | |
| 1853 | Jrd::Attachment* const attachment = tdbb->getAttachment(); |
| 1854 | |
| 1855 | jrd_tra* const tdbb_old_trans = tdbb->getTransaction(); |
| 1856 | |
| 1857 | jrd_tra* transaction = NULL; |
| 1858 | |
| 1859 | // Clean up the temporary locks we've gotten in case anything goes wrong |
| 1860 | |
| 1861 | try { |
| 1862 | |
| 1863 | // Identify ourselves as a sweeper thread. This accomplishes two goals: |
| 1864 | // 1) Sweep transaction is started "precommitted" and |
| 1865 | // 2) Execution is throttled in JRD_reschedule() by |
| 1866 | // yielding the processor when our quantum expires. |
| 1867 | |
| 1868 | ThreadSweepGuard sweepGuard(tdbb); |
| 1869 | |
| 1870 | TraceSweepEvent traceSweep(tdbb); |
| 1871 | |
| 1872 | // Start a transaction, if necessary, to perform the sweep. |
| 1873 | // Save the transaction's oldest snapshot as it is refreshed |
| 1874 | // during the course of the database sweep. Since it is used |
| 1875 | // below to advance the OIT we must save it before it changes. |
| 1876 | |
| 1877 | transaction = TRA_start(tdbb, sizeof(sweep_tpb), sweep_tpb); |
| 1878 | |
| 1879 | TraNumber transaction_oldest_active = transaction->tra_oldest_active; |
| 1880 | tdbb->setTransaction(transaction); |
| 1881 | |
| 1882 | // The garbage collector runs asynchronously with respect to |
| 1883 | // our database sweep. This isn't good enough since we must |
| 1884 | // be absolutely certain that all dead transactions have been |
| 1885 | // swept from the database before advancing the OIT. Turn off |
| 1886 | // the "notify garbage collector" flag for the attachment and |
| 1887 | // synchronously perform the garbage collection ourselves. |
| 1888 | |
| 1889 | attachment->att_flags &= ~ATT_notify_gc; |
| 1890 |
no test coverage detected