COptServer.h 3.0 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
//---------------------------------------------------------------------------
//	Greenplum Database
//	Copyright (C) 2012 EMC Corp.
//
//	@filename:
//		COptServer.h
//
//	@doc:
//		API for optimizer server
//
//	@test:
//
//
//---------------------------------------------------------------------------
#ifndef COptServer_H
#define COptServer_H

18
#include "naucrates/md/CSystemId.h"
19 20 21 22 23 24 25 26 27 28 29 30

#include "gpos/base.h"
#include "gpos/common/CSyncHashtable.h"
#include "gpos/common/CSyncHashtableAccessByKey.h"
#include "gpos/common/CSyncHashtableAccessByIter.h"
#include "gpos/common/CSyncHashtableIter.h"
#include "gpos/net/CSocket.h"
#include "gpos/task/CTask.h"

// forward declarations
namespace gpopt
{
J
Jesse Zhang 已提交
31 32 33 34 35
class CExpression;
class CMDAccessor;
class CMiniDumperDXL;
class CQueryContext;
}  // namespace gpopt
36 37 38

namespace gpnaucrates
{
J
Jesse Zhang 已提交
39
class CCommunicator;
40 41 42 43 44
}


namespace gpoptudfs
{
J
Jesse Zhang 已提交
45 46 47
using namespace gpos;
using namespace gpopt;
using namespace gpnaucrates;
48

J
Jesse Zhang 已提交
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
//---------------------------------------------------------------------------
//	@class:
//		COptServer
//
//	@doc:
//		Optimizer server; processes optimization requests from QDs;
//
//---------------------------------------------------------------------------
class COptServer
{
private:
	// connection descriptor
	struct SConnectionDescriptor
	{
		// ID
		ULONG_PTR m_id;
65

J
Jesse Zhang 已提交
66 67
		// task
		CTask *m_task;
68

J
Jesse Zhang 已提交
69 70
		// socket
		CSocket *m_socket;
71

J
Jesse Zhang 已提交
72 73
		// link for hashtable
		SLink m_link;
74

J
Jesse Zhang 已提交
75 76
		// invalid connection id
		static ULONG_PTR m_invalid_id;
77

J
Jesse Zhang 已提交
78 79 80 81 82 83
		// ctor
		SConnectionDescriptor(CTask *task, CSocket *socket)
			: m_id((ULONG_PTR) task), m_task(task), m_socket(socket)
		{
		}
	};
84

J
Jesse Zhang 已提交
85
	typedef CSyncHashtable<SConnectionDescriptor, ULONG_PTR> ConnectionHT;
86

J
Jesse Zhang 已提交
87 88
	// path where socket is initialized
	const CHAR *m_socket_path;
89

J
Jesse Zhang 已提交
90 91
	// memory pool for connections
	CMemoryPool *m_mp;
92

J
Jesse Zhang 已提交
93 94
	// hashtable of connections
	ConnectionHT *m_connections_ht;
95

J
Jesse Zhang 已提交
96 97
	// default id for the source system
	static const CSystemId m_default_id;
98

J
Jesse Zhang 已提交
99 100
	// ctor
	explicit COptServer(const CHAR *path);
101

J
Jesse Zhang 已提交
102 103
	// dtor
	~COptServer();
104

J
Jesse Zhang 已提交
105 106
	// start serving requests
	void Loop();
107

J
Jesse Zhang 已提交
108 109
	// initialize hashtable
	void InitHT();
110

J
Jesse Zhang 已提交
111 112
	// register connection for status checking
	void TrackConnection(CTask *task, CSocket *socket);
113

J
Jesse Zhang 已提交
114 115
	// release connection
	void ReleaseConnection(CTask *task);
116

J
Jesse Zhang 已提交
117 118
	// connection check task
	static void *CheckConnections(void *ptr);
119

J
Jesse Zhang 已提交
120 121
	// optimization task
	static void *Optimize(void *ptr);
122

J
Jesse Zhang 已提交
123 124 125 126
	// receive optimization request and construct query context for it
	static CQueryContext *RecvQuery(CMemoryPool *mp,
									CCommunicator *communicator,
									CMDAccessor *md_accessor);
127

J
Jesse Zhang 已提交
128 129 130 131
	// extract query plan, serialize it and send it to client
	static void SendPlan(CMemoryPool *mp, CCommunicator *communicator,
						 CMDAccessor *md_accessor, CQueryContext *query_ctxt,
						 CExpression *plan_expr);
132

J
Jesse Zhang 已提交
133 134
	// dump collected artifacts to file
	static void FinalizeMinidump(CMiniDumperDXL *dump);
135

J
Jesse Zhang 已提交
136 137 138
public:
	// invoke optimizer instance
	static void *Run(void *ptr);
139

J
Jesse Zhang 已提交
140 141
};	// class COptServer
}  // namespace gpoptudfs
142

J
Jesse Zhang 已提交
143
#endif	// !COptServer_H
144 145 146


// EOF