11
11
#include "storage/procarray.h"
12
12
#include "storage/shm_toc.h"
13
13
#include "catalog/pg_type.h"
14
+ #include "commands/extension.h"
15
+ #include "nodes/makefuncs.h"
14
16
15
17
#include "pg_config.h"
16
18
#include "fmgr.h"
50
52
extern volatile sig_atomic_t got_sighup ;
51
53
extern volatile sig_atomic_t got_sigterm ;
52
54
extern Oid scheduler_atjob_id_OID ;
55
+ extern Oid scheduler_schema_oid ;
53
56
54
- int checkSchedulerNamespace (void )
57
+ bool checkSchedulerExtension (void )
55
58
{
56
- const char * sql = "select count(*) from pg_catalog.pg_namespace where nspname = $1" ;
57
- int count = 0 ;
58
- const char * schema ;
59
- Oid argtypes [1 ] = { TEXTOID };
60
- Datum values [1 ];
61
-
62
- SetCurrentStatementStartTimestamp ();
63
- pgstat_report_activity (STATE_RUNNING , "initialize: check namespace" );
64
-
65
- schema = GetConfigOption ("schedule.schema" , false, true);
66
-
67
- START_SPI_SNAP ();
68
-
69
- values [0 ] = CStringGetTextDatum (schema );
70
- count = select_count_with_args (sql , 1 , argtypes , values , NULL );
71
-
72
- if (count == -1 )
73
- {
74
- STOP_SPI_SNAP ();
75
- elog (ERROR , "Scheduler manager: %s: cannot check namespace: sql error" ,
76
- MyBgworkerEntry -> bgw_name );
77
- }
78
- else if (count > 1 || count == 0 )
59
+ Oid extoid ;
60
+ bool use_transaction = false;
61
+ if (!IsTransactionState ())
79
62
{
80
- elog (LOG , "Scheduler manager: %s: cannot check namespace: "
81
- "found %d namespaces" , MyBgworkerEntry -> bgw_name , count );
82
- }
83
- else if (count == -2 )
84
- {
85
- elog (LOG , "Scheduler manager: %s: cannot check namespace: "
86
- "count return null" , MyBgworkerEntry -> bgw_name );
87
- }
88
- else if (count != 1 )
89
- {
90
- STOP_SPI_SNAP ();
91
- elog (ERROR , "Scheduler manager: %s: cannot check namespace: "
92
- "unknown error %d" , MyBgworkerEntry -> bgw_name , count );
93
- }
94
- STOP_SPI_SNAP ();
95
-
96
- if (count ) {
97
- SetConfigOption ("search_path" , schema , PGC_USERSET , PGC_S_SESSION );
63
+ StartTransactionCommand ();
64
+ use_transaction = true;
98
65
}
66
+
67
+ extoid = get_extension_oid ("pgpro_scheduler" , true);
68
+ if (use_transaction ) CommitTransactionCommand ();
99
69
100
- return count ;
70
+ return extoid != InvalidOid ? true: false ;
101
71
}
102
72
103
73
int get_scheduler_maxworkers (void )
@@ -1822,14 +1792,15 @@ void manager_worker_main(Datum arg)
1822
1792
elog (LOG , "Started scheduler manager for '%s'" , database );
1823
1793
SetConfigOption ("application_name" , buffer , PGC_USERSET , PGC_S_SESSION );
1824
1794
1825
- if (!checkSchedulerNamespace ())
1795
+ if (!checkSchedulerExtension ())
1826
1796
{
1827
- elog (LOG , "cannot start scheduler for %s - there is no namespace " , database );
1797
+ elog (LOG , "cannot start scheduler for %s - there is no extention " , database );
1828
1798
changeChildBgwState (shared , SchdManagerQuit );
1829
1799
dsm_detach (seg );
1830
1800
delete_worker_mem_ctx (NULL );
1831
1801
proc_exit (0 );
1832
1802
}
1803
+ set_schema (NULL , false);
1833
1804
SetCurrentStatementStartTimestamp ();
1834
1805
pgstat_report_activity (STATE_RUNNING , "initialize." );
1835
1806
@@ -1841,8 +1812,9 @@ void manager_worker_main(Datum arg)
1841
1812
ctx = initialize_scheduler_manager_context (longTerm , database , seg );
1842
1813
1843
1814
START_SPI_SNAP ();
1844
- reloid = RangeVarGetRelid (makeRangeVarFromNameList (
1845
- stringToQualifiedNameList ("schedule.at_jobs_submitted" )), NoLock , true);
1815
+ reloid = RangeVarGetRelid (
1816
+ makeRangeVar (get_scheduler_schema_name (), "at_jobs_submitted" , -1 )
1817
+ , NoLock , true);
1846
1818
STOP_SPI_SNAP ();
1847
1819
if (reloid == InvalidOid )
1848
1820
{
@@ -1854,7 +1826,6 @@ void manager_worker_main(Datum arg)
1854
1826
start_at_workers (ctx , shared );
1855
1827
clean_at_table (ctx );
1856
1828
set_slots_stat_report (ctx );
1857
- /* SetConfigOption("enable_seqscan", "off", PGC_USERSET, PGC_S_SESSION); */
1858
1829
1859
1830
while (!got_sigterm )
1860
1831
{
@@ -1867,9 +1838,13 @@ void manager_worker_main(Datum arg)
1867
1838
if (got_sighup )
1868
1839
{
1869
1840
got_sighup = false;
1841
+ /* make read extension schema again */
1842
+ scheduler_schema_oid = InvalidOid ;
1843
+ set_schema (NULL , false);
1844
+
1870
1845
ProcessConfigFile (PGC_SIGHUP );
1871
1846
reload_db_role_config (database );
1872
- refresh_scheduler_manager_context (ctx ); /* TODO */
1847
+ refresh_scheduler_manager_context (ctx );
1873
1848
set_slots_stat_report (ctx );
1874
1849
}
1875
1850
if (!got_sigterm )
0 commit comments