1 #ifndef S3_FUNC_INCLUDED
2 #define S3_FUNC_INCLUDED
3 /* Copyright (C) 2019, 2020 MariaDB Corporation Ab
4 
5    This program is free software; you can redistribute it and/or modify
6    it under the terms of the GNU General Public License as published by
7    the Free Software Foundation; version 2 of the License.
8 
9    This program is distributed in the hope that it will be useful,
10    but WITHOUT ANY WARRANTY; without even the implied warranty of
11    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12    GNU General Public License for more details.
13 
14    You should have received a copy of the GNU General Public License
15    along with this program; if not, write to the Free Software Foundation,
16    Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA */
17 
18 /*
19   Interface function used by S3 storage engine and aria_copy_for_s3
20 */
21 
22 #ifdef WITH_S3_STORAGE_ENGINE
23 #include <libmarias3/marias3.h>
24 
25 C_MODE_START
26 #define DEFAULT_AWS_HOST_NAME "s3.amazonaws.com"
27 
28 extern struct s3_func {
29   uint8_t (*set_option)(ms3_st *, ms3_set_option_t, void *);
30   void (*free)(S3_BLOCK *);
31   void (*deinit)(ms3_st *);
32   int32 (*unique_file_number)(void);
33   my_bool (*read_index_header)(ms3_st *, S3_INFO *, S3_BLOCK *);
34   int (*check_frm_version)(ms3_st *, S3_INFO *);
35   S3_INFO *(*info_copy)(S3_INFO *);
36   my_bool (*set_database_and_table_from_path)(S3_INFO *, const char *);
37   ms3_st *(*open_connection)(S3_INFO *);
38 } s3f;
39 
40 extern TYPELIB s3_protocol_typelib;
41 
42 /* Store information about a s3 connection */
43 
44 typedef struct s3_info
45 {
46   /* Connection strings */
47   LEX_CSTRING access_key, secret_key, region, bucket, host_name;
48   int port; // 0 means 'Use default'
49   my_bool use_http;
50 
51   /* Will be set by caller or by ma_open() */
52   LEX_CSTRING database, table;
53 
54   /*
55     Name of the partition table if the table is partitioned. If not, it's set
56     to be same as table. This is used to know which frm file to read to
57     check table version.
58   */
59   LEX_CSTRING base_table;
60 
61   /* Sent to open to verify version */
62   LEX_CUSTRING tabledef_version;
63 
64   /* Protocol for the list bucket API call. 1 for Amazon, 2 for some others */
65   uint8_t protocol_version;
66 } S3_INFO;
67 
68 
69 /* flag + length is stored in this header */
70 #define COMPRESS_HEADER 4
71 
72 /* Max length of an AWS PATH */
73 #define AWS_PATH_LENGTH ((NAME_LEN)*3+3+10+6+11)
74 
75 void s3_init_library(void);
76 void s3_deinit_library(void);
77 int aria_copy_to_s3(ms3_st *s3_client, const char *aws_bucket,
78                     const char *path,
79                     const char *database, const char *table_name,
80                     ulong block_size, my_bool compression,
81                     my_bool force, my_bool display, my_bool copy_frm);
82 int aria_copy_from_s3(ms3_st *s3_client, const char *aws_bucket,
83                       const char *path,const char *database,
84                       my_bool compression, my_bool force, my_bool display);
85 int aria_delete_from_s3(ms3_st *s3_client, const char *aws_bucket,
86                         const char *database, const char *table,
87                         my_bool display);
88 int aria_rename_s3(ms3_st *s3_client, const char *aws_bucket,
89                    const char *from_database, const char *from_table,
90                    const char *to_database, const char *to_table,
91                    my_bool rename_frm);
92 ms3_st *s3_open_connection(S3_INFO *s3);
93 void s3_deinit(ms3_st *s3_client);
94 int s3_put_object(ms3_st *s3_client, const char *aws_bucket,
95                   const char *name, uchar *data, size_t length,
96                   my_bool compression);
97 int s3_get_object(ms3_st *s3_client, const char *aws_bucket,
98                   const char *name, S3_BLOCK *block, my_bool compression,
99                   int print_error);
100 int s3_delete_object(ms3_st *s3_client, const char *aws_bucket,
101                      const char *name, myf error_flags);
102 my_bool s3_rename_object(ms3_st *s3_client, const char *aws_bucket,
103                          const char *from_name, const char *to_name,
104                          myf error_flags);
105 void s3_free(S3_BLOCK *data);
106 my_bool s3_copy_from_file(ms3_st *s3_client, const char *aws_bucket,
107                           char *aws_path, File file, my_off_t start,
108                           my_off_t file_end, uchar *block, size_t block_size,
109                           my_bool compression, my_bool display);
110 my_bool s3_copy_to_file(ms3_st *s3_client, const char *aws_bucket,
111                         char *aws_path, File file, my_off_t start,
112                         my_off_t file_end, my_bool compression,
113                         my_bool display);
114 int s3_delete_directory(ms3_st *s3_client, const char *aws_bucket,
115                         const char *path);
116 int s3_rename_directory(ms3_st *s3_client, const char *aws_bucket,
117                         const char *from_name, const char *to_name,
118                         myf error_flags);
119 int partition_delete_from_s3(ms3_st *s3_client, const char *aws_bucket,
120                              const char *database, const char *table,
121                              myf error_flags);
122 int partition_copy_to_s3(ms3_st *s3_client, const char *aws_bucket,
123                          const char *path, const char *old_path,
124                          const char *database, const char *table_name);
125 
126 S3_INFO *s3_info_copy(S3_INFO *old);
127 my_bool set_database_and_table_from_path(S3_INFO *s3, const char *path);
128 my_bool s3_get_def(ms3_st *s3_client, S3_INFO *S3_info, S3_BLOCK *block,
129                    const char *ext);
130 my_bool s3_frm_exists(ms3_st *s3_client, S3_INFO *s3_info);
131 int s3_check_frm_version(ms3_st *s3_client, S3_INFO *s3_info);
132 my_bool read_index_header(ms3_st *client, S3_INFO *s3, S3_BLOCK *block);
133 int32 s3_unique_file_number(void);
134 my_bool s3_block_read(struct st_pagecache *pagecache,
135                       PAGECACHE_IO_HOOK_ARGS *args,
136                       struct st_pagecache_file *file,
137                       S3_BLOCK *block);
138 C_MODE_END
139 #else
140 
141 C_MODE_START
142 /* Dummy structures and interfaces to be used when compiling without S3 */
143 struct s3_info;
144 typedef struct s3_info S3_INFO;
145 struct ms3_st;
146 C_MODE_END
147 #endif /* WITH_S3_STORAGE_ENGINE */
148 #endif /* HA_S3_FUNC_INCLUDED */
149