1 | /***************************************************************************** |
2 | |
3 | Copyright (C) 2013, 2017, MariaDB Corporation. All Rights Reserved. |
4 | |
5 | This program is free software; you can redistribute it and/or modify it under |
6 | the terms of the GNU General Public License as published by the Free Software |
7 | Foundation; version 2 of the License. |
8 | |
9 | This program is distributed in the hope that it will be useful, but WITHOUT |
10 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
11 | FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. |
12 | |
13 | You should have received a copy of the GNU General Public License along with |
14 | this program; if not, write to the Free Software Foundation, Inc., |
15 | 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
16 | |
17 | *****************************************************************************/ |
18 | |
19 | /******************************************************************//** |
20 | @file include/fsp0pagecompress.ic |
21 | Implementation for helper functions for extracting/storing page |
22 | compression and atomic writes information to file space. |
23 | |
24 | Created 11/12/2013 Jan Lindström jan.lindstrom@mariadb.com |
25 | |
26 | ***********************************************************************/ |
27 | |
28 | /********************************************************************//** |
29 | Determine the tablespace is page compression level from dict_table_t::flags. |
30 | @return page compression level or 0 if not compressed*/ |
31 | UNIV_INLINE |
32 | ulint |
33 | fsp_flags_get_page_compression_level( |
34 | /*=================================*/ |
35 | ulint flags) /*!< in: tablespace flags */ |
36 | { |
37 | return(FSP_FLAGS_GET_PAGE_COMPRESSION_LEVEL(flags)); |
38 | } |
39 | |
40 | |
41 | /*******************************************************************//** |
42 | Find out wheather the page is index page or not |
43 | @return true if page type index page, false if not */ |
44 | UNIV_INLINE |
45 | bool |
46 | fil_page_is_index_page( |
47 | /*===================*/ |
48 | byte* buf) /*!< in: page */ |
49 | { |
50 | return(mach_read_from_2(buf+FIL_PAGE_TYPE) == FIL_PAGE_INDEX); |
51 | } |
52 | |
53 | /*******************************************************************//** |
54 | Find out wheather the page is page compressed |
55 | @return true if page is page compressed, false if not */ |
56 | UNIV_INLINE |
57 | bool |
58 | fil_page_is_compressed( |
59 | /*===================*/ |
60 | const byte* buf) /*!< in: page */ |
61 | { |
62 | return(mach_read_from_2(buf+FIL_PAGE_TYPE) == FIL_PAGE_PAGE_COMPRESSED); |
63 | } |
64 | |
65 | /*******************************************************************//** |
66 | Find out wheather the page is page compressed |
67 | @return true if page is page compressed, false if not */ |
68 | UNIV_INLINE |
69 | bool |
70 | fil_page_is_compressed_encrypted( |
71 | /*=============================*/ |
72 | const byte* buf) /*!< in: page */ |
73 | { |
74 | return(mach_read_from_2(buf+FIL_PAGE_TYPE) == FIL_PAGE_PAGE_COMPRESSED_ENCRYPTED); |
75 | } |
76 | |
77 | /****************************************************************//** |
78 | Get the name of the compression algorithm used for page |
79 | compression. |
80 | @return compression algorithm name or "UNKNOWN" if not known*/ |
81 | UNIV_INLINE |
82 | const char* |
83 | fil_get_compression_alg_name( |
84 | /*=========================*/ |
85 | ib_uint64_t comp_alg) /*!<in: compression algorithm number */ |
86 | { |
87 | switch(comp_alg) { |
88 | case PAGE_UNCOMPRESSED: |
89 | return ("uncompressed" ); |
90 | break; |
91 | case PAGE_ZLIB_ALGORITHM: |
92 | return ("ZLIB" ); |
93 | break; |
94 | case PAGE_LZ4_ALGORITHM: |
95 | return ("LZ4" ); |
96 | break; |
97 | case PAGE_LZO_ALGORITHM: |
98 | return ("LZO" ); |
99 | break; |
100 | case PAGE_LZMA_ALGORITHM: |
101 | return ("LZMA" ); |
102 | break; |
103 | case PAGE_BZIP2_ALGORITHM: |
104 | return ("BZIP2" ); |
105 | break; |
106 | case PAGE_SNAPPY_ALGORITHM: |
107 | return ("SNAPPY" ); |
108 | break; |
109 | /* No default to get compiler warning */ |
110 | } |
111 | |
112 | return ("NULL" ); |
113 | } |
114 | |
115 | #ifndef UNIV_INNOCHECKSUM |
116 | /*******************************************************************//** |
117 | Find out wheather the page is page compressed with lzo method |
118 | @return true if page is page compressed with lzo method, false if not */ |
119 | UNIV_INLINE |
120 | bool |
121 | fil_page_is_lzo_compressed( |
122 | /*=======================*/ |
123 | byte* buf) /*!< in: page */ |
124 | { |
125 | return((mach_read_from_2(buf+FIL_PAGE_TYPE) == FIL_PAGE_PAGE_COMPRESSED && |
126 | mach_read_from_8(buf+FIL_PAGE_FILE_FLUSH_LSN_OR_KEY_VERSION) == PAGE_LZO_ALGORITHM) || |
127 | (mach_read_from_2(buf+FIL_PAGE_TYPE) == FIL_PAGE_PAGE_COMPRESSED_ENCRYPTED && |
128 | mach_read_from_2(buf+FIL_PAGE_DATA+FIL_PAGE_COMPRESSED_SIZE) == PAGE_LZO_ALGORITHM)); |
129 | } |
130 | |
131 | #endif /* UNIV_INNOCHECKSUM */ |
132 | |