cdbcopy.h 2.6 KB
Newer Older
1
/*--------------------------------------------------------------------------
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
 *
 * cdbcopy.h
 *	 Definitions and API functions for cdbcopy.c
 *	 These are functions that are used by the backend
 *	 COPY command in Greenplum Database.
 *
 * Portions Copyright (c) 2005-2008, Greenplum inc
 * Portions Copyright (c) 2012-Present Pivotal Software, Inc.
 *
 *
 * IDENTIFICATION
 *	    src/include/cdb/cdbcopy.h
 *
 *--------------------------------------------------------------------------
 */
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
#ifndef CDBCOPY_H
#define CDBCOPY_H

#include "access/aosegfiles.h" /* for InvalidFileSegNumber const */ 
#include "lib/stringinfo.h"
#include "cdb/cdbgang.h"

#define COPYOUT_CHUNK_SIZE 16 * 1024

typedef enum SegDbState
{
	/*
	 * (it is best to avoid names like OUT that are likely to be #define'd or
	 * typedef'd in some platform-dependent runtime library header file)
	 */
	SEGDB_OUT,					/* Not participating in COPY (invalid etc...) */
	SEGDB_IDLE,					/* Participating but COPY not yet started */
	SEGDB_COPY,					/* COPY in progress */
	SEGDB_DONE					/* COPY completed (with or without errors) */
}	SegDbState;

typedef struct CdbCopy
{
	Gang	   *primary_writer;
	int			total_segs;		/* total number of segments in cdb */
	int		   *mirror_map;		/* indicates how many db's each segment has */
	bool		copy_in;		/* direction: true for COPY FROM false for COPY TO */
	bool		remote_data_err;/* data error occurred on a remote COPY session */
	bool		io_errors;		/* true if any I/O error occurred trying to
								 * communicate with segDB's */
	bool		skip_ext_partition;/* skip external partition */ 

	SegDbState		**segdb_state;
	
	StringInfoData	err_msg;		/* error message for cdbcopy operations */
	StringInfoData  err_context; /* error context from QE error */
	StringInfoData	copy_out_buf;/* holds a chunk of data from the database */
		
	List			*outseglist;    /* segs that currently take part in copy out. 
									 * Once a segment gave away all it's data rows
									 * it is taken out of the list */
	PartitionNode *partitions;
	List		  *ao_segnos;
	HTAB		  *aotupcounts; /* hash of ao relation id to processed tuple count */
P
Pengzhou Tang 已提交
61
	bool		hasReplicatedTable;
62 63 64 65 66 67
} CdbCopy;



/* global function declarations */
CdbCopy    *makeCdbCopy(bool copy_in);
68
void		cdbCopyStart(CdbCopy *cdbCopy, char *copyCmd, struct GpPolicy *policy);
A
alldefector 已提交
69
void		cdbCopySendDataToAll(CdbCopy *c, const char *buffer, int nbytes);
70 71 72
void		cdbCopySendData(CdbCopy *c, int target_seg, const char *buffer, int nbytes);
bool		cdbCopyGetData(CdbCopy *c, bool cancel, uint64 *rows_processed);
int			cdbCopyEnd(CdbCopy *c);
73
int			cdbCopyEndAndFetchRejectNum(CdbCopy *c, int64 *total_rows_completed);
74 75

#endif   /* CDBCOPY_H */