forked from EnterpriseDB/hdfs_fdw
-
Notifications
You must be signed in to change notification settings - Fork 0
/
hdfs_connection.c
68 lines (59 loc) · 1.56 KB
/
hdfs_connection.c
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
/*-------------------------------------------------------------------------
*
* hdfs_connection.c
* Foreign-data wrapper for remote Hadoop servers
*
* Portions Copyright (c) 2012-2014, PostgreSQL Global Development Group
*
* Portions Copyright (c) 2004-2014, EnterpriseDB Corporation.
*
* IDENTIFICATION
* hdfs_connection.c
*
*-------------------------------------------------------------------------
*/
#include "postgres.h"
#include "hdfs_fdw.h"
#include "access/xact.h"
#include "mb/pg_wchar.h"
#include "miscadmin.h"
#include "utils/hsearch.h"
#include "utils/memutils.h"
#include "utils/resowner.h"
int
hdfs_get_connection(ForeignServer *server, UserMapping *user, hdfs_opt *opt)
{
int conn;
char *err = "unknown";
char *err_buf = err;
conn = DBOpenConnection(opt->host,
opt->port,
opt->dbname,
opt->username,
opt->password,
opt->connect_timeout,
opt->receive_timeout,
opt->auth_type,
opt->client_type,
&err_buf);
if (conn < 0)
ereport(ERROR,
(errcode(ERRCODE_FDW_OUT_OF_MEMORY),
errmsg("failed to initialize the HDFS connection object (%s)", err_buf)));
ereport(DEBUG1, (errmsg("hdfs_fdw: connection opened %d", conn)));
return conn;
}
/*
* Release connection created by calling GetConnection.
*/
void
hdfs_rel_connection(int con_index)
{
int r;
r = DBCloseConnection(con_index);
if (r < 0)
ereport(ERROR,
(errcode(ERRCODE_FDW_OUT_OF_MEMORY),
errmsg("failed to close HDFS connection object")));
ereport(DEBUG1, (errmsg("hdfs_fdw: connection closed %d", con_index)));
}