mirror of https://github.com/citusdata/citus.git
parent
0ea4e52df5
commit
5ff1821411
|
@ -251,7 +251,7 @@ StartNodeUserDatabaseConnection(uint32 flags, const char *hostname, int32 port,
|
|||
}
|
||||
else
|
||||
{
|
||||
strlcpy(key.database, get_database_name(MyDatabaseId), NAMEDATALEN);
|
||||
strlcpy(key.database, CurrentDatabaseName(), NAMEDATALEN);
|
||||
}
|
||||
|
||||
if (CurrentCoordinatedTransactionState == COORD_TRANS_NONE)
|
||||
|
|
|
@ -871,7 +871,7 @@ TrackerConnectPoll(TaskTracker *taskTracker)
|
|||
{
|
||||
char *nodeName = taskTracker->workerName;
|
||||
uint32 nodePort = taskTracker->workerPort;
|
||||
char *nodeDatabase = get_database_name(MyDatabaseId);
|
||||
char *nodeDatabase = CurrentDatabaseName();
|
||||
char *nodeUser = taskTracker->userName;
|
||||
|
||||
int32 connectionId = MultiClientConnectStart(nodeName, nodePort,
|
||||
|
|
|
@ -507,7 +507,7 @@ ExplainTaskPlacement(ShardPlacement *taskPlacement, List *explainOutputList,
|
|||
StringInfo nodeAddress = makeStringInfo();
|
||||
char *nodeName = taskPlacement->nodeName;
|
||||
uint32 nodePort = taskPlacement->nodePort;
|
||||
char *nodeDatabase = get_database_name(MyDatabaseId);
|
||||
char *nodeDatabase = CurrentDatabaseName();
|
||||
ListCell *explainOutputCell = NULL;
|
||||
int rowIndex = 0;
|
||||
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
#include "catalog/pg_namespace.h"
|
||||
#include "catalog/pg_type.h"
|
||||
#include "citus_version.h"
|
||||
#include "commands/dbcommands.h"
|
||||
#include "commands/extension.h"
|
||||
#include "commands/trigger.h"
|
||||
#include "distributed/colocation_utils.h"
|
||||
|
@ -137,6 +138,8 @@ typedef struct MetadataCacheData
|
|||
Oid unavailableNodeRoleId;
|
||||
Oid pgTableIsVisibleFuncId;
|
||||
Oid citusTableIsVisibleFuncId;
|
||||
bool databaseNameValid;
|
||||
char databaseName[NAMEDATALEN];
|
||||
} MetadataCacheData;
|
||||
|
||||
|
||||
|
@ -2102,6 +2105,33 @@ CitusTableVisibleFuncId(void)
|
|||
}
|
||||
|
||||
|
||||
/*
|
||||
* CurrentDatabaseName gets the name of the current database and caches
|
||||
* the result.
|
||||
*
|
||||
* Given that the database name cannot be changed when there is at least
|
||||
* one session connected to it, we do not need to implement any invalidation
|
||||
* mechanism.
|
||||
*/
|
||||
char *
|
||||
CurrentDatabaseName(void)
|
||||
{
|
||||
if (!MetadataCache.databaseNameValid)
|
||||
{
|
||||
char *databaseName = get_database_name(MyDatabaseId);
|
||||
if (databaseName == NULL)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
strlcpy(MetadataCache.databaseName, databaseName, NAMEDATALEN);
|
||||
MetadataCache.databaseNameValid = true;
|
||||
}
|
||||
|
||||
return MetadataCache.databaseName;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* CitusExtensionOwner() returns the owner of the 'citus' extension. That user
|
||||
* is, amongst others, used to perform actions a normal user might not be
|
||||
|
|
|
@ -368,7 +368,7 @@ CreateTask(uint64 jobId, uint32 taskId, char *taskCallString)
|
|||
{
|
||||
WorkerTask *workerTask = NULL;
|
||||
uint32 assignmentTime = 0;
|
||||
char *databaseName = get_database_name(MyDatabaseId);
|
||||
char *databaseName = CurrentDatabaseName();
|
||||
char *userName = CurrentUserName();
|
||||
|
||||
/* increase task priority for cleanup tasks */
|
||||
|
|
|
@ -248,7 +248,7 @@ ReceiveRegularFile(const char *nodeName, uint32 nodePort, const char *nodeUser,
|
|||
}
|
||||
|
||||
/* we use the same database name on the master and worker nodes */
|
||||
nodeDatabase = get_database_name(MyDatabaseId);
|
||||
nodeDatabase = CurrentDatabaseName();
|
||||
|
||||
/* connect to remote node */
|
||||
connectionId = MultiClientConnect(nodeName, nodePort, nodeDatabase, nodeUser);
|
||||
|
|
|
@ -167,4 +167,7 @@ extern Oid BinaryCopyFormatId(void);
|
|||
extern Oid CitusExtensionOwner(void);
|
||||
extern char * CitusExtensionOwnerName(void);
|
||||
extern char * CurrentUserName(void);
|
||||
extern char * CurrentDatabaseName(void);
|
||||
|
||||
|
||||
#endif /* METADATA_CACHE_H */
|
||||
|
|
Loading…
Reference in New Issue