HAWQ-316. Rework SSE42 implementation and runtime logic to be more similar to PostgreSQL9.5
Project: http://git-wip-us.apache.org/repos/asf/incubator-hawq/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-hawq/commit/f988a712 Tree: http://git-wip-us.apache.org/repos/asf/incubator-hawq/tree/f988a712 Diff: http://git-wip-us.apache.org/repos/asf/incubator-hawq/diff/f988a712 Branch: refs/heads/master Commit: f988a7120b88dcf641bd824d6c5f9c205aaf5061 Parents: 7442666 Author: Ming LI <m...@pivotal.io> Authored: Fri Feb 19 09:42:43 2016 +0800 Committer: Ming LI <m...@pivotal.io> Committed: Fri Feb 19 09:48:03 2016 +0800 ---------------------------------------------------------------------- config/c-compiler.m4 | 35 + configure | 236 +++++ configure.in | 90 ++ src/Makefile.global.in | 4 + src/all_src_files.txt | 1 - src/backend/access/transam/xlog.c | 76 +- src/backend/cdb/cdbappendonlystorage.c | 1 + src/backend/cdb/cdbappendonlystorageformat.c | 255 ++--- src/backend/cdb/motion/ic_udp.c | 11 +- src/backend/storage/file/bfz.c | 8 +- src/backend/utils/hash/Makefile | 2 +- src/backend/utils/hash/crc32c.c | 702 ------------- src/backend/utils/hash/pg_crc.c | 427 +------- src/bin/gpupgrade/.gitignore | 1 - src/bin/gpupgrade/Makefile | 6 +- src/bin/gpupgrade/gpmodcatversion.c | 33 +- src/bin/pg_controldata/.gitignore | 1 - src/bin/pg_controldata/Makefile | 7 +- src/bin/pg_controldata/pg_controldata.c | 15 +- src/bin/pg_resetxlog/.gitignore | 1 - src/bin/pg_resetxlog/Makefile | 7 +- src/bin/pg_resetxlog/pg_resetxlog.c | 41 +- src/include/access/xlog.h | 1 + src/include/catalog/pg_control.h | 1 + src/include/cdb/cdbappendonlystorage.h | 1 + src/include/cdb/cdbsreh.h | 32 +- src/include/pg_config.h.in | 15 + src/include/pg_config.h.win32 | 22 +- src/include/port/pg_crc32c.h | 93 ++ src/include/utils/pg_crc.h | 202 ++-- src/port/Makefile | 6 +- src/port/pg_crc32c_choose.c | 63 ++ src/port/pg_crc32c_sb8.c | 1169 +++++++++++++++++++++ src/port/pg_crc32c_sse42.c | 68 ++ 34 files changed, 2124 insertions(+), 1509 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/f988a712/config/c-compiler.m4 ---------------------------------------------------------------------- diff --git a/config/c-compiler.m4 b/config/c-compiler.m4 index 778a8f8..88fbbb7 100644 --- a/config/c-compiler.m4 +++ b/config/c-compiler.m4 @@ -181,3 +181,38 @@ AC_RUN_IFELSE([AC_LANG_PROGRAM([extern void $2 (); void (*fptr) () = $2;],[])], [LDFLAGS="$pgac_save_LDFLAGS" AC_MSG_RESULT(assuming no)]) ])# PGAC_PROG_CC_LDFLAGS_OPT + + + +# PGAC_SSE42_CRC32_INTRINSICS +# ----------------------- +# Check if the compiler supports the x86 CRC instructions added in SSE 4.2, +# using the _mm_crc32_u8 and _mm_crc32_u32 intrinsic functions. (We don't +# test the 8-byte variant, _mm_crc32_u64, but it is assumed to be present if +# the other ones are, on x86-64 platforms) +# +# An optional compiler flag can be passed as argument (e.g. -msse4.2). If the +# intrinsics are supported, sets pgac_sse42_crc32_intrinsics, and CFLAGS_SSE42. +# +# Copied from upstream. +# +AC_DEFUN([PGAC_SSE42_CRC32_INTRINSICS], +[define([Ac_cachevar], [AS_TR_SH([pgac_cv_sse42_crc32_intrinsics_$1])])dnl +AC_CACHE_CHECK([for _mm_crc32_u8 and _mm_crc32_u32 with CFLAGS=$1], [Ac_cachevar], +[pgac_save_CFLAGS=$CFLAGS +CFLAGS="$pgac_save_CFLAGS $1" +AC_LINK_IFELSE([AC_LANG_PROGRAM([#include <nmmintrin.h>], + [unsigned int crc = 0; + crc = _mm_crc32_u8(crc, 0); + crc = _mm_crc32_u32(crc, 0); + /* return computed value, to prevent the above being optimized away */ + return crc == 0;])], + [Ac_cachevar=yes], + [Ac_cachevar=no]) +CFLAGS="$pgac_save_CFLAGS"]) +if test x"$Ac_cachevar" = x"yes"; then + CFLAGS_SSE42="$1" + pgac_sse42_crc32_intrinsics=yes +fi +undefine([Ac_cachevar])dnl +])# PGAC_SSE42_CRC32_INTRINSICS http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/f988a712/configure ---------------------------------------------------------------------- diff --git a/configure b/configure index e6ffa43..137fdb1 100755 --- a/configure +++ b/configure @@ -746,6 +746,8 @@ HQ_MAJORVERSION GP_MAJORVERSION GCC CPP +PG_CRC32C_OBJS +CFLAGS_SSE42 SUN_STUDIO_CC OBJEXT EXEEXT @@ -4426,6 +4428,240 @@ if test "$GCC" = yes; then fi fi + +# Check for x86 cpuid instruction to determine if we can perform a +# runtime check +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for __get_cpuid" >&5 +$as_echo_n "checking for __get_cpuid... " >&6; } +if ${pgac_cv__get_cpuid+:} false; then : + $as_echo_n "(cached) " >&6 +else + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +#include <cpuid.h> +int +main () +{ +unsigned int exx[4] = {0, 0, 0, 0}; + __get_cpuid(1, &exx[0], &exx[1], &exx[2], &exx[3]); + + ; + return 0; +} +_ACEOF +if ac_fn_c_try_link "$LINENO"; then : + pgac_cv__get_cpuid="yes" +else + pgac_cv__get_cpuid="no" +fi +rm -f core conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $pgac_cv__get_cpuid" >&5 +$as_echo "$pgac_cv__get_cpuid" >&6; } +if test x"$pgac_cv__get_cpuid" = x"yes"; then + +$as_echo "#define HAVE__GET_CPUID 1" >>confdefs.h + +fi + +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for __cpuid" >&5 +$as_echo_n "checking for __cpuid... " >&6; } +if ${pgac_cv__cpuid+:} false; then : + $as_echo_n "(cached) " >&6 +else + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +#include <intrin.h> +int +main () +{ +unsigned int exx[4] = {0, 0, 0, 0}; + __get_cpuid(exx[0], 1); + + ; + return 0; +} +_ACEOF +if ac_fn_c_try_link "$LINENO"; then : + pgac_cv__cpuid="yes" +else + pgac_cv__cpuid="no" +fi +rm -f core conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $pgac_cv__cpuid" >&5 +$as_echo "$pgac_cv__cpuid" >&6; } +if test x"$pgac_cv__cpuid" = x"yes"; then + +$as_echo "#define HAVE__CPUID 1" >>confdefs.h + +fi + +# Check for Intel SSE 4.2 intrinsics to do CRC calculations. +# +# First check if the _mm_crc32_u8 and _mm_crc32_u64 intrinsics can be used +# with the default compiler flags. If not, check if adding the -msse4.2 +# flag helps. CFLAGS_SSE42 is set to -msse4.2 if that's required. +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for _mm_crc32_u8 and _mm_crc32_u32 with CFLAGS=" >&5 +$as_echo_n "checking for _mm_crc32_u8 and _mm_crc32_u32 with CFLAGS=... " >&6; } +if ${pgac_cv_sse42_crc32_intrinsics_+:} false; then : + $as_echo_n "(cached) " >&6 +else + pgac_save_CFLAGS=$CFLAGS +CFLAGS="$pgac_save_CFLAGS " +cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +#include <nmmintrin.h> +int +main () +{ +unsigned int crc = 0; + crc = _mm_crc32_u8(crc, 0); + crc = _mm_crc32_u32(crc, 0); + /* return computed value, to prevent the above being optimized away */ + return crc == 0; + ; + return 0; +} +_ACEOF +if ac_fn_c_try_link "$LINENO"; then : + pgac_cv_sse42_crc32_intrinsics_=yes +else + pgac_cv_sse42_crc32_intrinsics_=no +fi +rm -f core conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext +CFLAGS="$pgac_save_CFLAGS" +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $pgac_cv_sse42_crc32_intrinsics_" >&5 +$as_echo "$pgac_cv_sse42_crc32_intrinsics_" >&6; } +if test x"$pgac_cv_sse42_crc32_intrinsics_" = x"yes"; then + CFLAGS_SSE42="" + pgac_sse42_crc32_intrinsics=yes +fi + +if test x"$pgac_sse42_crc32_intrinsics" != x"yes"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for _mm_crc32_u8 and _mm_crc32_u32 with CFLAGS=-msse4.2" >&5 +$as_echo_n "checking for _mm_crc32_u8 and _mm_crc32_u32 with CFLAGS=-msse4.2... " >&6; } +if ${pgac_cv_sse42_crc32_intrinsics__msse4_2+:} false; then : + $as_echo_n "(cached) " >&6 +else + pgac_save_CFLAGS=$CFLAGS +CFLAGS="$pgac_save_CFLAGS -msse4.2" +cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +#include <nmmintrin.h> +int +main () +{ +unsigned int crc = 0; + crc = _mm_crc32_u8(crc, 0); + crc = _mm_crc32_u32(crc, 0); + /* return computed value, to prevent the above being optimized away */ + return crc == 0; + ; + return 0; +} +_ACEOF +if ac_fn_c_try_link "$LINENO"; then : + pgac_cv_sse42_crc32_intrinsics__msse4_2=yes +else + pgac_cv_sse42_crc32_intrinsics__msse4_2=no +fi +rm -f core conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext +CFLAGS="$pgac_save_CFLAGS" +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $pgac_cv_sse42_crc32_intrinsics__msse4_2" >&5 +$as_echo "$pgac_cv_sse42_crc32_intrinsics__msse4_2" >&6; } +if test x"$pgac_cv_sse42_crc32_intrinsics__msse4_2" = x"yes"; then + CFLAGS_SSE42="-msse4.2" + pgac_sse42_crc32_intrinsics=yes +fi + +fi + + +# Are we targeting a processor that supports SSE 4.2? gcc, clang and icc all +# define __SSE4_2__ in that case. +cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +int +main () +{ + +#ifndef __SSE4_2__ +#error __SSE4_2__ not defined +#endif + + ; + return 0; +} +_ACEOF +if ac_fn_c_try_compile "$LINENO"; then : + SSE4_2_TARGETED=1 +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext + +# Select CRC-32C implementation. +# +# If we are targeting a processor that has SSE 4.2 instructions, we can use the +# special CRC instructions for calculating CRC-32C. If we're not targeting such +# a processor, but we can nevertheless produce code that uses the SSE +# intrinsics, perhaps with some extra CFLAGS, compile both implementations and +# select which one to use at runtime, depending on whether SSE 4.2 is supported +# by the processor we're running on. +# +# You can override this logic by setting the appropriate USE_*_CRC32 flag to 1 +# in the template or configure command line. +if test x"$USE_SSE42_CRC32C" = x"" && test x"$USE_SSE42_CRC32C_WITH_RUNTIME_CHECK" = x"" && test x"$USE_SLICING_BY_8_CRC32C" = x""; then + if test x"$pgac_sse42_crc32_intrinsics" = x"yes" && test x"$SSE4_2_TARGETED" = x"1" ; then + USE_SSE42_CRC32C=1 + else + # the CPUID instruction is needed for the runtime check. + if test x"$pgac_sse42_crc32_intrinsics" = x"yes" && (test x"$pgac_cv__get_cpuid" = x"yes" || test x"$pgac_cv__cpuid" = x"yes"); then + USE_SSE42_CRC32C_WITH_RUNTIME_CHECK=1 + else + # fall back to slicing-by-8 algorithm which doesn't require any special + # CPU support. + USE_SLICING_BY_8_CRC32C=1 + fi + fi +fi + +# Set PG_CRC32C_OBJS appropriately depending on the selected implementation. +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking which CRC-32C implementation to use" >&5 +$as_echo_n "checking which CRC-32C implementation to use... " >&6; } +if test x"$USE_SSE42_CRC32C" = x"1"; then + +$as_echo "#define USE_SSE42_CRC32C 1" >>confdefs.h + + PG_CRC32C_OBJS="pg_crc32c_sse42.o" + { $as_echo "$as_me:${as_lineno-$LINENO}: result: SSE 4.2" >&5 +$as_echo "SSE 4.2" >&6; } +else + if test x"$USE_SSE42_CRC32C_WITH_RUNTIME_CHECK" = x"1"; then + +$as_echo "#define USE_SSE42_CRC32C_WITH_RUNTIME_CHECK 1" >>confdefs.h + + PG_CRC32C_OBJS="pg_crc32c_sse42.o pg_crc32c_sb8.o pg_crc32c_choose.o" + { $as_echo "$as_me:${as_lineno-$LINENO}: result: SSE 4.2 with runtime check" >&5 +$as_echo "SSE 4.2 with runtime check" >&6; } + else + +$as_echo "#define USE_SLICING_BY_8_CRC32C 1" >>confdefs.h + + PG_CRC32C_OBJS="pg_crc32c_sb8.o" + { $as_echo "$as_me:${as_lineno-$LINENO}: result: slicing-by-8" >&5 +$as_echo "slicing-by-8" >&6; } + fi +fi + + + # Some versions of GCC support some additional useful warning flags. # Check whether they are supported, and add them to CFLAGS if so. # ICC pretends to be GCC but it's lying; it doesn't support these flags, http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/f988a712/configure.in ---------------------------------------------------------------------- diff --git a/configure.in b/configure.in index 4df5a55..fc1798c 100644 --- a/configure.in +++ b/configure.in @@ -325,6 +325,96 @@ if test "$GCC" = yes; then fi fi + +# Check for x86 cpuid instruction to determine if we can perform a +# runtime check +AC_CACHE_CHECK([for __get_cpuid], [pgac_cv__get_cpuid], +[AC_LINK_IFELSE([AC_LANG_PROGRAM([#include <cpuid.h>], + [[unsigned int exx[4] = {0, 0, 0, 0}; + __get_cpuid(1, &exx[0], &exx[1], &exx[2], &exx[3]); + ]])], + [pgac_cv__get_cpuid="yes"], + [pgac_cv__get_cpuid="no"])]) +if test x"$pgac_cv__get_cpuid" = x"yes"; then + AC_DEFINE(HAVE__GET_CPUID, 1, [Define to 1 if you have __get_cpuid.]) +fi + +AC_CACHE_CHECK([for __cpuid], [pgac_cv__cpuid], +[AC_LINK_IFELSE([AC_LANG_PROGRAM([#include <intrin.h>], + [[unsigned int exx[4] = {0, 0, 0, 0}; + __get_cpuid(exx[0], 1); + ]])], + [pgac_cv__cpuid="yes"], + [pgac_cv__cpuid="no"])]) +if test x"$pgac_cv__cpuid" = x"yes"; then + AC_DEFINE(HAVE__CPUID, 1, [Define to 1 if you have __cpuid.]) +fi + +# Check for Intel SSE 4.2 intrinsics to do CRC calculations. +# +# First check if the _mm_crc32_u8 and _mm_crc32_u64 intrinsics can be used +# with the default compiler flags. If not, check if adding the -msse4.2 +# flag helps. CFLAGS_SSE42 is set to -msse4.2 if that's required. +PGAC_SSE42_CRC32_INTRINSICS([]) +if test x"$pgac_sse42_crc32_intrinsics" != x"yes"; then + PGAC_SSE42_CRC32_INTRINSICS([-msse4.2]) +fi +AC_SUBST(CFLAGS_SSE42) + +# Are we targeting a processor that supports SSE 4.2? gcc, clang and icc all +# define __SSE4_2__ in that case. +AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [ +#ifndef __SSE4_2__ +#error __SSE4_2__ not defined +#endif +])], [SSE4_2_TARGETED=1]) + +# Select CRC-32C implementation. +# +# If we are targeting a processor that has SSE 4.2 instructions, we can use the +# special CRC instructions for calculating CRC-32C. If we're not targeting such +# a processor, but we can nevertheless produce code that uses the SSE +# intrinsics, perhaps with some extra CFLAGS, compile both implementations and +# select which one to use at runtime, depending on whether SSE 4.2 is supported +# by the processor we're running on. +# +# You can override this logic by setting the appropriate USE_*_CRC32 flag to 1 +# in the template or configure command line. +if test x"$USE_SSE42_CRC32C" = x"" && test x"$USE_SSE42_CRC32C_WITH_RUNTIME_CHECK" = x"" && test x"$USE_SLICING_BY_8_CRC32C" = x""; then + if test x"$pgac_sse42_crc32_intrinsics" = x"yes" && test x"$SSE4_2_TARGETED" = x"1" ; then + USE_SSE42_CRC32C=1 + else + # the CPUID instruction is needed for the runtime check. + if test x"$pgac_sse42_crc32_intrinsics" = x"yes" && (test x"$pgac_cv__get_cpuid" = x"yes" || test x"$pgac_cv__cpuid" = x"yes"); then + USE_SSE42_CRC32C_WITH_RUNTIME_CHECK=1 + else + # fall back to slicing-by-8 algorithm which doesn't require any special + # CPU support. + USE_SLICING_BY_8_CRC32C=1 + fi + fi +fi + +# Set PG_CRC32C_OBJS appropriately depending on the selected implementation. +AC_MSG_CHECKING([which CRC-32C implementation to use]) +if test x"$USE_SSE42_CRC32C" = x"1"; then + AC_DEFINE(USE_SSE42_CRC32C, 1, [Define to 1 use Intel SSE 4.2 CRC instructions.]) + PG_CRC32C_OBJS="pg_crc32c_sse42.o" + AC_MSG_RESULT(SSE 4.2) +else + if test x"$USE_SSE42_CRC32C_WITH_RUNTIME_CHECK" = x"1"; then + AC_DEFINE(USE_SSE42_CRC32C_WITH_RUNTIME_CHECK, 1, [Define to 1 to use Intel SSSE 4.2 CRC instructions with a runtime check.]) + PG_CRC32C_OBJS="pg_crc32c_sse42.o pg_crc32c_sb8.o pg_crc32c_choose.o" + AC_MSG_RESULT(SSE 4.2 with runtime check) + else + AC_DEFINE(USE_SLICING_BY_8_CRC32C, 1, [Define to 1 to use Intel SSE 4.2 CRC instructions with a runtime check.]) + PG_CRC32C_OBJS="pg_crc32c_sb8.o" + AC_MSG_RESULT(slicing-by-8) + fi +fi +AC_SUBST(PG_CRC32C_OBJS) + + # Some versions of GCC support some additional useful warning flags. # Check whether they are supported, and add them to CFLAGS if so. # ICC pretends to be GCC but it's lying; it doesn't support these flags, http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/f988a712/src/Makefile.global.in ---------------------------------------------------------------------- diff --git a/src/Makefile.global.in b/src/Makefile.global.in index 1e569d1..73af93d 100644 --- a/src/Makefile.global.in +++ b/src/Makefile.global.in @@ -233,6 +233,7 @@ CC = @CC@ GCC = @GCC@ SUN_STUDIO_CC = @SUN_STUDIO_CC@ CFLAGS = @CFLAGS@ +CFLAGS_SSE42 = @CFLAGS_SSE42@ # Kind-of compilers @@ -511,6 +512,9 @@ endif LIBOBJS = @LIBOBJS@ +# files needed for the chosen CRC-32C implementation +PG_CRC32C_OBJS = @PG_CRC32C_OBJS@ + LIBS := -lpgport $(LIBS) # add location of libpgport.a to LDFLAGS ifdef PGXS http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/f988a712/src/all_src_files.txt ---------------------------------------------------------------------- diff --git a/src/all_src_files.txt b/src/all_src_files.txt index f7ca7ad..31630c8 100644 --- a/src/all_src_files.txt +++ b/src/all_src_files.txt @@ -703,7 +703,6 @@ backend/utils/fmgr/funcapi.c backend/utils/gp/persistentutil.c backend/utils/gp/segadmin.c backend/utils/gpmon/gpmon.c -backend/utils/hash/crc32c.c backend/utils/hash/dynahash.c backend/utils/hash/hashfn.c backend/utils/hash/pg_crc.c http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/f988a712/src/backend/access/transam/xlog.c ---------------------------------------------------------------------- diff --git a/src/backend/access/transam/xlog.c b/src/backend/access/transam/xlog.c index ed33cd5..7a50c17 100644 --- a/src/backend/access/transam/xlog.c +++ b/src/backend/access/transam/xlog.c @@ -66,6 +66,7 @@ #include "utils/memutils.h" #include "utils/syscache.h" #include "utils/pg_crc.h" +#include "port/pg_crc32c.h" #include "storage/backendid.h" #include "storage/sinvaladt.h" @@ -832,7 +833,7 @@ begin:; */ doPageWrites = fullPageWrites || Insert->forcePageWrites; - rdata_crc = crc32cInit(); + INIT_CRC32C(rdata_crc); len = 0; for (rdt = rdata;;) { @@ -840,7 +841,7 @@ begin:; { /* Simple data, just include it */ len += rdt->len; - rdata_crc = crc32c(rdata_crc, rdt->data, rdt->len); + COMP_CRC32C(rdata_crc, rdt->data, rdt->len); } else { @@ -855,7 +856,7 @@ begin:; else if (rdt->data) { len += rdt->len; - rdata_crc = crc32c(rdata_crc, rdt->data, rdt->len); + COMP_CRC32C(rdata_crc, rdt->data, rdt->len); } break; } @@ -872,7 +873,7 @@ begin:; else if (rdt->data) { len += rdt->len; - rdata_crc = crc32c(rdata_crc, rdt->data, rdt->len); + COMP_CRC32C(rdata_crc, rdt->data, rdt->len); } break; } @@ -897,23 +898,23 @@ begin:; BkpBlock *bkpb = &(dtbuf_xlg[i]); char *page; - rdata_crc = crc32c(rdata_crc, + COMP_CRC32C(rdata_crc, (char *) bkpb, sizeof(BkpBlock)); page = (char *) BufferGetBlock(dtbuf[i]); if (bkpb->hole_length == 0) { - rdata_crc = crc32c(rdata_crc, + COMP_CRC32C(rdata_crc, page, BLCKSZ); } else { /* must skip the hole */ - rdata_crc = crc32c(rdata_crc, + COMP_CRC32C(rdata_crc, page, bkpb->hole_offset); - rdata_crc = crc32c(rdata_crc, + COMP_CRC32C(rdata_crc, page + (bkpb->hole_offset + bkpb->hole_length), BLCKSZ - (bkpb->hole_offset + bkpb->hole_length)); } @@ -1145,9 +1146,9 @@ begin:; record->xl_rmid = rmid; /* Now we can finish computing the record's CRC */ - rdata_crc = crc32c(rdata_crc, (char *) record + sizeof(pg_crc32), + COMP_CRC32C(rdata_crc, (char *) record + sizeof(pg_crc32), SizeOfXLogRecord - sizeof(pg_crc32)); - crc32cFinish(rdata_crc); + FIN_CRC32C(rdata_crc); record->xl_crc = rdata_crc; /* Record begin of record in appropriate places */ @@ -3832,7 +3833,8 @@ RecordIsValid(XLogRecord *record, XLogRecPtr recptr, int emode) */ /* First the rmgr data */ - crc = crc32c(crc32cInit(), XLogRecGetData(record), len); + INIT_CRC32C(crc); + COMP_CRC32C(crc, XLogRecGetData(record), len); /* Add in the backup blocks, if any */ blk = (char *) XLogRecGetData(record) + len; @@ -3852,7 +3854,7 @@ RecordIsValid(XLogRecord *record, XLogRecPtr recptr, int emode) return false; } blen = sizeof(BkpBlock) + BLCKSZ - bkpb.hole_length; - crc = crc32c(crc, blk, blen); + COMP_CRC32C(crc, blk, blen); blk += blen; } @@ -3866,11 +3868,11 @@ RecordIsValid(XLogRecord *record, XLogRecPtr recptr, int emode) } /* Finally include the record header */ - crc = crc32c(crc, (char *) record + sizeof(pg_crc32), + COMP_CRC32C(crc, (char *) record + sizeof(pg_crc32), SizeOfXLogRecord - sizeof(pg_crc32)); - crc32cFinish(crc); + FIN_CRC32C(crc); - if (!EQ_CRC32(record->xl_crc, crc)) + if (!EQ_LEGACY_CRC32(record->xl_crc, crc)) { /* * Ok, the crc failed, but it may be that we have a record using the old crc algorithm. @@ -3878,8 +3880,8 @@ RecordIsValid(XLogRecord *record, XLogRecPtr recptr, int emode) */ /* First the rmgr data */ - INIT_CRC32(crc); - COMP_CRC32(crc, XLogRecGetData(record), len); + INIT_LEGACY_CRC32(crc); + COMP_LEGACY_CRC32(crc, XLogRecGetData(record), len); /* Add in the backup blocks, if any */ blk = (char *) XLogRecGetData(record) + len; @@ -3899,17 +3901,17 @@ RecordIsValid(XLogRecord *record, XLogRecPtr recptr, int emode) return false; } blen = sizeof(BkpBlock) + BLCKSZ - bkpb.hole_length; - COMP_CRC32(crc, blk, blen); + COMP_LEGACY_CRC32(crc, blk, blen); blk += blen; } /* Finally include the record header */ - COMP_CRC32(crc, (char *) record + sizeof(pg_crc32), + COMP_LEGACY_CRC32(crc, (char *) record + sizeof(pg_crc32), SizeOfXLogRecord - sizeof(pg_crc32)); - FIN_CRC32(crc); + FIN_LEGACY_CRC32(crc); } - if (!EQ_CRC32(record->xl_crc, crc)) + if (!EQ_LEGACY_CRC32(record->xl_crc, crc)) { ereport(emode, (errmsg("incorrect resource manager data checksum in record at %X/%X", @@ -4914,10 +4916,11 @@ WriteControlFile(void) StrNCpy(ControlFile->lc_ctype, localeptr, LOCALE_NAME_BUFLEN); /* Contents are protected with a CRC */ - ControlFile->crc = crc32c(crc32cInit(), + INIT_CRC32C(ControlFile->crc); + COMP_CRC32C(ControlFile->crc, (char *) ControlFile, offsetof(ControlFileData, crc)); - crc32cFinish(ControlFile->crc); + FIN_CRC32C(ControlFile->crc); /* * We write out PG_CONTROL_SIZE bytes into pg_control, zero-padding the @@ -4998,20 +5001,21 @@ ReadControlFile(void) errhint("It looks like you need to initdb."))); /* Now check the CRC. */ - crc = crc32c(crc32cInit(), + INIT_CRC32C(crc); + COMP_CRC32C(crc, (char *) ControlFile, offsetof(ControlFileData, crc)); - crc32cFinish(crc); + FIN_CRC32C(crc); - if (!EQ_CRC32(crc, ControlFile->crc)) + if (!EQ_LEGACY_CRC32(crc, ControlFile->crc)) { /* We might have an old record. Recompute using old crc algorithm, and re-check. */ - INIT_CRC32(crc); - COMP_CRC32(crc, + INIT_LEGACY_CRC32(crc); + COMP_LEGACY_CRC32(crc, (char *) ControlFile, offsetof(ControlFileData, crc)); - FIN_CRC32(crc); - if (!EQ_CRC32(crc, ControlFile->crc)) + FIN_LEGACY_CRC32(crc); + if (!EQ_LEGACY_CRC32(crc, ControlFile->crc)) ereport(FATAL, (errmsg("incorrect checksum in control file"))); } @@ -5164,10 +5168,11 @@ UpdateControlFile(void) { MirroredFlatFileOpen mirroredOpen; - ControlFile->crc = crc32c(crc32cInit(), + INIT_CRC32C(ControlFile->crc); + COMP_CRC32C(ControlFile->crc, (char *) ControlFile, offsetof(ControlFileData, crc)); - crc32cFinish(ControlFile->crc); + FIN_CRC32C(ControlFile->crc); MirroredFlatFile_Open( &mirroredOpen, @@ -5376,10 +5381,11 @@ BootStrapXLOG(void) record->xl_rmid = RM_XLOG_ID; memcpy(XLogRecGetData(record), &checkPoint, sizeof(checkPoint)); - crc = crc32c(crc32cInit(), &checkPoint, sizeof(checkPoint)); - crc = crc32c(crc, (char *) record + sizeof(pg_crc32), + INIT_CRC32C(crc); + COMP_CRC32C(crc, &checkPoint, sizeof(checkPoint)); + COMP_CRC32C(crc, (char *) record + sizeof(pg_crc32), SizeOfXLogRecord - sizeof(pg_crc32)); - crc32cFinish(crc); + FIN_CRC32C(crc); record->xl_crc = crc; http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/f988a712/src/backend/cdb/cdbappendonlystorage.c ---------------------------------------------------------------------- diff --git a/src/backend/cdb/cdbappendonlystorage.c b/src/backend/cdb/cdbappendonlystorage.c index e81d8f7..ad6e467 100644 --- a/src/backend/cdb/cdbappendonlystorage.c +++ b/src/backend/cdb/cdbappendonlystorage.c @@ -28,6 +28,7 @@ #include "cdb/cdbappendonlystorage_int.h" #include "cdb/cdbappendonlystorage.h" #include "utils/pg_crc.h" +#include "port/pg_crc32c.h" #include "utils/guc.h" int32 AppendOnlyStorage_GetUsableBlockSize(int32 configBlockSize) http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/f988a712/src/backend/cdb/cdbappendonlystorageformat.c ---------------------------------------------------------------------- diff --git a/src/backend/cdb/cdbappendonlystorageformat.c b/src/backend/cdb/cdbappendonlystorageformat.c index 1aa5af8..72e70c9 100644 --- a/src/backend/cdb/cdbappendonlystorageformat.c +++ b/src/backend/cdb/cdbappendonlystorageformat.c @@ -6,9 +6,9 @@ * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY @@ -29,6 +29,7 @@ #include "cdb/cdbappendonlystorage.h" #include "cdb/cdbappendonlystorageformat.h" #include "utils/pg_crc.h" +#include "port/pg_crc32c.h" #include "utils/guc.h" static pg_crc32 @@ -37,20 +38,20 @@ AppendOnlyStorageFormat_ComputeHeaderChecksum( int32 headerLen) { pg_crc32 crc; - + Assert(headerPtr != NULL); - INIT_CRC32(crc); + INIT_CRC32C(crc); - /* + /* * Compute CRC of the header. The header length does not include the * header checksum. */ - COMP_CRC32(crc, - headerPtr, + COMP_CRC32C(crc, + headerPtr, headerLen); + FIN_CRC32C(crc); - /* BUG: This routine does not return a correct CRC32, since it never calls FIN_CRC32 */ return crc; } @@ -62,7 +63,7 @@ AppendOnlyStorageFormat_ComputeBlockChecksum( { int32 dataOffset; pg_crc32 crc; - + Assert(headerPtr != NULL); /* @@ -71,19 +72,19 @@ AppendOnlyStorageFormat_ComputeBlockChecksum( */ dataOffset = headerLen + sizeof(pg_crc32); - INIT_CRC32(crc); + INIT_CRC32C(crc); /* Compute CRC of the header. */ - COMP_CRC32(crc, - headerPtr + dataOffset, + COMP_CRC32C(crc, + headerPtr + dataOffset, overallBlockLen - dataOffset); + FIN_CRC32C(crc); - /* BUG: This routine does not return a correct CRC32, since it never calls FIN_CRC32 */ return crc; } -int32 +int32 AppendOnlyStorageFormat_RegularHeaderLenNeeded( bool usingChecksum) { @@ -98,7 +99,7 @@ AppendOnlyStorageFormat_AddFirstRowNum( int64 firstRowNum) { AOSmallContentHeader *blockHeader = (AOSmallContentHeader*)headerPtr; - + int32 offsetToFirstRowNum; int64 *firstRowNumPtr; @@ -110,13 +111,13 @@ AppendOnlyStorageFormat_AddFirstRowNum( { offsetToFirstRowNum = AoHeader_LongSize; } - - if (usingChecksums) + + if (usingChecksums) offsetToFirstRowNum += 2 * sizeof(pg_crc32); // Header and Block checksums. - + firstRowNumPtr = (int64*)&headerPtr[offsetToFirstRowNum]; *firstRowNumPtr = firstRowNum; - + if (Debug_appendonly_print_storage_headers) elog(LOG, "Append-Only storage first row number header result: block_bytes_0_3 0x%X, block_bytes_4_7 0x%X, " @@ -151,7 +152,7 @@ AppendOnlyStorageFormat_AddBlockHeaderChecksums( firstHeaderLen = AoHeader_RegularSize; firstHeaderAndBlockChecksumLen = firstHeaderLen + sizeof(pg_crc32); // Block checksum. - + offset = firstHeaderAndBlockChecksumLen + sizeof(pg_crc32); // Header checksum. if (AoHeader_IsLong(headerKind)) @@ -171,15 +172,15 @@ AppendOnlyStorageFormat_AddBlockHeaderChecksums( AOStorage_RoundUp( (isCompressed ? compressedLength : dataLength), version); - + /* - * Calculate Block checksum first since it is included in the + * Calculate Block checksum first since it is included in the * header checksum. */ blockChecksumPtr = (pg_crc32*)&headerPtr[firstHeaderLen]; *blockChecksumPtr = AppendOnlyStorageFormat_ComputeBlockChecksum( headerPtr, - firstHeaderAndBlockChecksumLen, + firstHeaderAndBlockChecksumLen, overallBlockLen); /* * Now the Header checksum after the header and block checksum. @@ -188,7 +189,7 @@ AppendOnlyStorageFormat_AddBlockHeaderChecksums( *headerChecksumPtr = AppendOnlyStorageFormat_ComputeHeaderChecksum( headerPtr, firstHeaderAndBlockChecksumLen); - + if (Debug_appendonly_print_storage_headers) { switch (headerKind) @@ -211,7 +212,7 @@ AppendOnlyStorageFormat_AddBlockHeaderChecksums( AOBulkDenseContentHeader *bulkDenseHeader = (AOBulkDenseContentHeader*)headerPtr; AOBulkDenseContentHeaderExt *bulkDenseHeaderExt; - bulkDenseHeaderExt = + bulkDenseHeaderExt = (AOBulkDenseContentHeaderExt*) (headerPtr + extHeaderOffset); @@ -229,10 +230,10 @@ AppendOnlyStorageFormat_AddBlockHeaderChecksums( overallBlockLen); break; } - + default: ereport(ERROR, - (errmsg("Unexpected Append-Only header kind %d", + (errmsg("Unexpected Append-Only header kind %d", headerKind))); break; } @@ -256,7 +257,7 @@ AppendOnlyStorageFormat_MakeSmallContentHeader( bool isCompressed; Assert(headerPtr != NULL); - + blockHeader = (AOSmallContentHeader*)headerPtr; if (Debug_appendonly_print_storage_headers) @@ -269,16 +270,16 @@ AppendOnlyStorageFormat_MakeSmallContentHeader( rowCount, dataLength, compressedLength); - + /* Zero out whole header */ AOSmallContentHeaderInit_Init(blockHeader); - + AOSmallContentHeaderInit_headerKind(blockHeader,AoHeaderKind_SmallContent); AOSmallContentHeaderInit_executorBlockKind(blockHeader,executorKind); AOSmallContentHeaderInit_rowCount(blockHeader,rowCount); AOSmallContentHeaderInit_dataLength(blockHeader,dataLength); AOSmallContentHeaderInit_hasFirstRowNum(blockHeader,hasFirstRowNum); - + isCompressed = (compressedLength > 0); if (isCompressed) AOSmallContentHeaderInit_compressedLength(blockHeader,compressedLength); @@ -301,7 +302,7 @@ AppendOnlyStorageFormat_MakeSmallContentHeader( usingChecksums, firstRowNum); } - + if (usingChecksums) { AppendOnlyStorageFormat_AddBlockHeaderChecksums( @@ -357,12 +358,12 @@ AppendOnlyStorageFormat_SmallContentHeaderStr( executorBlockKind = AOSmallContentHeaderGet_executorBlockKind(blockHeader); rowCount = AOSmallContentHeaderGet_rowCount(blockHeader); - - wholeHeaderLen = headerLen + + + wholeHeaderLen = headerLen + (usingChecksums ? 2 * sizeof(pg_crc32) : 0); - + dataLength = AOSmallContentHeaderGet_dataLength(blockHeader); - + compressedLength = AOSmallContentHeaderGet_compressedLength(blockHeader); overallBlockLen = wholeHeaderLen + @@ -374,9 +375,9 @@ AppendOnlyStorageFormat_SmallContentHeaderStr( { blockChecksumPtr = (pg_crc32*)&headerPtr[headerLen]; blockChecksum = *blockChecksumPtr; - + headerLen += sizeof(pg_crc32); - + headerChecksumPtr = (pg_crc32*)&headerPtr[headerLen]; headerChecksum = *headerChecksumPtr; } @@ -461,21 +462,21 @@ AppendOnlyStorageFormat_LargeContentHeaderStr( executorBlockKind = AOLargeContentHeaderGet_executorBlockKind(blockHeader); rowCount = AOLargeContentHeaderGet_largeRowCount(blockHeader); - - wholeHeaderLen = headerLen + + + wholeHeaderLen = headerLen + (usingChecksums ? 2 * sizeof(pg_crc32) : 0); - + largeContentLength = AOLargeContentHeaderGet_largeContentLength(blockHeader); - + overallBlockLen = wholeHeaderLen; // No data with this kind of header. if (usingChecksums) { blockChecksumPtr = (pg_crc32*)&headerPtr[headerLen]; blockChecksum = *blockChecksumPtr; - + headerLen += sizeof(pg_crc32); - + headerChecksumPtr = (pg_crc32*)&headerPtr[headerLen]; headerChecksum = *headerChecksumPtr; } @@ -559,12 +560,12 @@ AppendOnlyStorageFormat_NonBulkDenseContentHeaderStr( executorBlockKind = AONonBulkDenseContentHeaderGet_executorBlockKind(blockHeader); rowCount = AONonBulkDenseContentHeaderGet_largeRowCount(blockHeader); - - wholeHeaderLen = headerLen + + + wholeHeaderLen = headerLen + (usingChecksums ? 2 * sizeof(pg_crc32) : 0); - + dataLength = AONonBulkDenseContentHeaderGet_dataLength(blockHeader); - + overallBlockLen = wholeHeaderLen + AOStorage_RoundUp( dataLength, @@ -574,9 +575,9 @@ AppendOnlyStorageFormat_NonBulkDenseContentHeaderStr( { blockChecksumPtr = (pg_crc32*)&headerPtr[headerLen]; blockChecksum = *blockChecksumPtr; - + headerLen += sizeof(pg_crc32); - + headerChecksumPtr = (pg_crc32*)&headerPtr[headerLen]; headerChecksum = *headerChecksumPtr; } @@ -666,9 +667,9 @@ AppendOnlyStorageFormat_BulkDenseContentHeaderStr( extHeaderLen = AoHeader_RegularSize; executorBlockKind = AOBulkDenseContentHeaderGet_executorBlockKind(blockHeader); - - firstHeaderAndChecksumsLen = - firstHeaderLen + + + firstHeaderAndChecksumsLen = + firstHeaderLen + (usingChecksums ? 2 * sizeof(pg_crc32) : 0); /* @@ -676,9 +677,9 @@ AppendOnlyStorageFormat_BulkDenseContentHeaderStr( */ extHeader = (AOBulkDenseContentHeaderExt*)(headerPtr + firstHeaderAndChecksumsLen); rowCount = AOBulkDenseContentHeaderExtGet_largeRowCount(extHeader); - + dataLength = AOBulkDenseContentHeaderGet_dataLength(blockHeader); - + compressedLength = AOBulkDenseContentHeaderGet_compressedLength(blockHeader); overallBlockLen = firstHeaderAndChecksumsLen + @@ -692,7 +693,7 @@ AppendOnlyStorageFormat_BulkDenseContentHeaderStr( { blockChecksumPtr = (pg_crc32*)&headerPtr[firstHeaderLen]; blockChecksum = *blockChecksumPtr; - + headerChecksumPtr = (pg_crc32*)&headerPtr[firstHeaderLen + sizeof(pg_crc32)]; headerChecksum = *headerChecksumPtr; } @@ -795,7 +796,7 @@ AppendOnlyStorageFormat_BlockHeaderStr( default: { StringInfoData buf; - + initStringInfo(&buf); appendStringInfo( &buf, @@ -961,9 +962,9 @@ errdetail_appendonly_storage_content_header( return errdetail_appendonly_storage_bulkdensecontent_header(header, usingChecksum, version); default: - return errdetail( + return errdetail( "Append-Only storage header kind %d unknown", - aoHeaderKind); + aoHeaderKind); } } @@ -982,7 +983,7 @@ AppendOnlyStorageFormat_MakeLargeContentHeader( AOLargeContentHeader *largeContentHeader; Assert(headerPtr != NULL); - + largeContentHeader = (AOLargeContentHeader*)headerPtr; if (Debug_appendonly_print_storage_headers) @@ -993,10 +994,10 @@ AppendOnlyStorageFormat_MakeLargeContentHeader( executorKind, largeRowCount, largeContentLength); - + /* Zero out whole header */ AOLargeContentHeaderInit_Init(largeContentHeader); - + AOLargeContentHeaderInit_headerKind(largeContentHeader,AoHeaderKind_LargeContent); AOLargeContentHeaderInit_executorBlockKind(largeContentHeader,executorKind); AOLargeContentHeaderInit_largeRowCount(largeContentHeader,largeRowCount); @@ -1021,7 +1022,7 @@ AppendOnlyStorageFormat_MakeLargeContentHeader( usingChecksums, firstRowNum); } - + if (usingChecksums) { // UNDONE: Set 2nd checksum to 0 when there is no content??? @@ -1057,7 +1058,7 @@ AppendOnlyStorageFormat_MakeNonBulkDenseContentHeader( AONonBulkDenseContentHeader *blockHeader; Assert(headerPtr != NULL); - + blockHeader = (AONonBulkDenseContentHeader*)headerPtr; if (Debug_appendonly_print_storage_headers) @@ -1069,16 +1070,16 @@ AppendOnlyStorageFormat_MakeNonBulkDenseContentHeader( executorKind, rowCount, dataLength); - + /* Zero out whole header */ AONonBulkDenseContentHeaderInit_Init(blockHeader); - + AONonBulkDenseContentHeaderInit_headerKind(blockHeader,AoHeaderKind_NonBulkDenseContent); AONonBulkDenseContentHeaderInit_executorBlockKind(blockHeader,executorKind); AONonBulkDenseContentHeaderInit_largeRowCount(blockHeader,rowCount); AONonBulkDenseContentHeaderInit_dataLength(blockHeader,dataLength); AONonBulkDenseContentHeaderInit_hasFirstRowNum(blockHeader,hasFirstRowNum); - + /* * Add the optional firstRowNum. * @@ -1097,7 +1098,7 @@ AppendOnlyStorageFormat_MakeNonBulkDenseContentHeader( usingChecksums, firstRowNum); } - + if (usingChecksums) { AppendOnlyStorageFormat_AddBlockHeaderChecksums( @@ -1139,10 +1140,10 @@ AppendOnlyStorageFormat_MakeBulkDenseContentHeader( bool isCompressed; Assert(headerPtr != NULL); - + blockHeader = (AOBulkDenseContentHeader*)headerPtr; - firstHeaderAndChecksumsLen = - AoHeader_RegularSize + + firstHeaderAndChecksumsLen = + AoHeader_RegularSize + (usingChecksums ? 2 * sizeof(pg_crc32) : 0); /* @@ -1160,15 +1161,15 @@ AppendOnlyStorageFormat_MakeBulkDenseContentHeader( rowCount, dataLength, compressedLength); - + /* Zero out whole header */ AOBulkDenseContentHeaderInit_Init(blockHeader); - + AOBulkDenseContentHeaderInit_headerKind(blockHeader,AoHeaderKind_BulkDenseContent); AOBulkDenseContentHeaderInit_executorBlockKind(blockHeader,executorKind); AOBulkDenseContentHeaderInit_dataLength(blockHeader,dataLength); AOBulkDenseContentHeaderInit_hasFirstRowNum(blockHeader,hasFirstRowNum); - + isCompressed = (compressedLength > 0); if (isCompressed) AOBulkDenseContentHeaderInit_compressedLength(blockHeader,compressedLength); @@ -1176,7 +1177,7 @@ AppendOnlyStorageFormat_MakeBulkDenseContentHeader( /* Zero out whole extension */ AOBulkDenseContentHeaderExtInit_Init(extHeader); AOBulkDenseContentHeaderExtInit_largeRowCount(extHeader,rowCount); - + /* * Add the optional firstRowNum. * @@ -1195,7 +1196,7 @@ AppendOnlyStorageFormat_MakeBulkDenseContentHeader( usingChecksums, firstRowNum); } - + if (usingChecksums) { AppendOnlyStorageFormat_AddBlockHeaderChecksums( @@ -1361,10 +1362,10 @@ AppendOnlyStorageFormat_GetHeaderInfo( MAX_AOHEADER_CHECK_ERROR_STR, "Append-only storage header is invalid -- first 32 bits are all zeroes (header_bytes_0_3 0x%08x, header_bytes_4_7 0x%08x)", header->header_bytes_0_3, header->header_bytes_4_7); - + Assert(snprintfResult >= 0); Assert(snprintfResult < MAX_AOHEADER_CHECK_ERROR_STR); - + return AOHeaderCheckFirst32BitsAllZeroes; } @@ -1376,10 +1377,10 @@ AppendOnlyStorageFormat_GetHeaderInfo( MAX_AOHEADER_CHECK_ERROR_STR, "Append-only storage header is invalid -- reserved bit 0 of the header is not zero (header_bytes_0_3 0x%08x, header_bytes_4_7 0x%08x)", header->header_bytes_0_3, header->header_bytes_4_7); - + Assert(snprintfResult >= 0); Assert(snprintfResult < MAX_AOHEADER_CHECK_ERROR_STR); - + return AOHeaderCheckReservedBit0Not0; } @@ -1393,10 +1394,10 @@ AppendOnlyStorageFormat_GetHeaderInfo( MAX_AOHEADER_CHECK_ERROR_STR, "Append-only storage header is invalid -- invalid value 0 (none) for header kind (header_bytes_0_3 0x%08x, header_bytes_4_7 0x%08x)", header->header_bytes_0_3, header->header_bytes_4_7); - + Assert(snprintfResult >= 0); Assert(snprintfResult < MAX_AOHEADER_CHECK_ERROR_STR); - + return AOHeaderCheckInvalidHeaderKindNone; } @@ -1409,10 +1410,10 @@ AppendOnlyStorageFormat_GetHeaderInfo( "Append-only storage header is invalid -- invalid header kind value %d (header_bytes_0_3 0x%08x, header_bytes_4_7 0x%08x)", (int)*headerKind, header->header_bytes_0_3, header->header_bytes_4_7); - + Assert(snprintfResult >= 0); Assert(snprintfResult < MAX_AOHEADER_CHECK_ERROR_STR); - + return AOHeaderCheckInvalidHeaderKind; } @@ -1424,22 +1425,22 @@ AppendOnlyStorageFormat_GetHeaderInfo( blockHeader = (AOSmallContentHeader*)headerPtr; - *actualHeaderLen = - AoHeader_RegularSize+ + *actualHeaderLen = + AoHeader_RegularSize+ (usingChecksums ? 2 * sizeof(pg_crc32) : 0); if (AOSmallContentHeaderGet_hasFirstRowNum(blockHeader)) (*actualHeaderLen) += sizeof(int64); } break; - + case AoHeaderKind_LargeContent: { AOLargeContentHeader *largeContentHeader; largeContentHeader = (AOLargeContentHeader*)headerPtr; - *actualHeaderLen = - AoHeader_RegularSize + + *actualHeaderLen = + AoHeader_RegularSize + (usingChecksums ? 2 * sizeof(pg_crc32) : 0); if (AOLargeContentHeaderGet_hasFirstRowNum(largeContentHeader)) (*actualHeaderLen) += sizeof(int64); @@ -1452,8 +1453,8 @@ AppendOnlyStorageFormat_GetHeaderInfo( denseContentHeader = (AONonBulkDenseContentHeader*)headerPtr; - *actualHeaderLen = - AoHeader_RegularSize + + *actualHeaderLen = + AoHeader_RegularSize + (usingChecksums ? 2 * sizeof(pg_crc32) : 0); if (AONonBulkDenseContentHeaderGet_hasFirstRowNum(denseContentHeader)) (*actualHeaderLen) += sizeof(int64); @@ -1466,20 +1467,20 @@ AppendOnlyStorageFormat_GetHeaderInfo( blockHeader = (AOBulkDenseContentHeader*)headerPtr; - *actualHeaderLen = - AoHeader_LongSize + + *actualHeaderLen = + AoHeader_LongSize + (usingChecksums ? 2 * sizeof(pg_crc32) : 0); if (AOBulkDenseContentHeaderGet_hasFirstRowNum(blockHeader)) (*actualHeaderLen) += sizeof(int64); } break; - + default: - elog(ERROR, "Unexpected Append-Only header kind %d", + elog(ERROR, "Unexpected Append-Only header kind %d", *headerKind); break; - } - + } + return AOHeaderCheckOk; } @@ -1509,9 +1510,9 @@ AppendOnlyStorageFormat_GetSmallContentHeaderInfo( *executorBlockKind = AOSmallContentHeaderGet_executorBlockKind(blockHeader); *hasFirstRowNum = AOSmallContentHeaderGet_hasFirstRowNum(blockHeader); - *rowCount = AOSmallContentHeaderGet_rowCount(blockHeader); + *rowCount = AOSmallContentHeaderGet_rowCount(blockHeader); - *offset = AoHeader_RegularSize + + *offset = AoHeader_RegularSize + (usingChecksums ? 2 * sizeof(pg_crc32) : 0); if (*hasFirstRowNum) { @@ -1519,17 +1520,17 @@ AppendOnlyStorageFormat_GetSmallContentHeaderInfo( firstRowNumPtr = (int64*)&headerPtr[*offset]; *firstRowNum = *firstRowNumPtr; - + (*offset) += sizeof(int64); } else *firstRowNum = INT64CONST(-1); - + if (*offset != headerLen) elog(ERROR, "Content offset %d doesn't equal header length parameter %d", *offset, headerLen); - + *uncompressedLen = AOSmallContentHeaderGet_dataLength(blockHeader); *compressedLen = AOSmallContentHeaderGet_compressedLength(blockHeader); if (*compressedLen == 0) @@ -1557,7 +1558,7 @@ AppendOnlyStorageFormat_GetSmallContentHeaderInfo( return AOHeaderCheckInvalidCompressedLen; } } - + *overallBlockLen = *offset + AOStorage_RoundUp(length, version); @@ -1640,8 +1641,8 @@ AppendOnlyStorageFormat_GetLargeContentHeaderInfo( largeContentHeader->largecontent_bytes_0_3, largeContentHeader->largecontent_bytes_4_7); return AOHeaderCheckLargeContentLenIsZero; } - - offset = AoHeader_RegularSize + + + offset = AoHeader_RegularSize + (usingChecksums ? 2 * sizeof(pg_crc32) : 0); if (*hasFirstRowNum) { @@ -1649,7 +1650,7 @@ AppendOnlyStorageFormat_GetLargeContentHeaderInfo( firstRowNumPtr = (int64*)&headerPtr[offset]; *firstRowNum = *firstRowNumPtr; - + offset += sizeof(int64); } else @@ -1686,9 +1687,9 @@ AppendOnlyStorageFormat_GetNonBulkDenseContentHeaderInfo( *executorBlockKind = AONonBulkDenseContentHeaderGet_executorBlockKind(blockHeader); *hasFirstRowNum = AONonBulkDenseContentHeaderGet_hasFirstRowNum(blockHeader); - *rowCount = AONonBulkDenseContentHeaderGet_largeRowCount(blockHeader); + *rowCount = AONonBulkDenseContentHeaderGet_largeRowCount(blockHeader); - *offset = AoHeader_RegularSize + + *offset = AoHeader_RegularSize + (usingChecksums ? 2 * sizeof(pg_crc32) : 0); if (*hasFirstRowNum) { @@ -1696,19 +1697,19 @@ AppendOnlyStorageFormat_GetNonBulkDenseContentHeaderInfo( firstRowNumPtr = (int64*)&headerPtr[*offset]; *firstRowNum = *firstRowNumPtr; - + (*offset) += sizeof(int64); } else *firstRowNum = INT64CONST(-1); - + if (*offset != headerLen) elog(ERROR, "Content offset %d doesn't equal header length parameter %d", *offset, headerLen); - + *uncompressedLen = AONonBulkDenseContentHeaderGet_dataLength(blockHeader); - + *overallBlockLen = *offset + AOStorage_RoundUp(*uncompressedLen, version); @@ -1722,7 +1723,7 @@ AppendOnlyStorageFormat_GetNonBulkDenseContentHeaderInfo( blockHeader->nonbulkdensecontent_bytes_0_3, blockHeader->nonbulkdensecontent_bytes_4_7); return AOHeaderCheckInvalidOverallBlockLen; } - + return AOHeaderCheckOk; } @@ -1752,8 +1753,8 @@ AppendOnlyStorageFormat_GetBulkDenseContentHeaderInfo( Assert(headerPtr != NULL); blockHeader = (AOBulkDenseContentHeader*)headerPtr; - firstHeaderAndChecksumsLen = - AoHeader_RegularSize + + firstHeaderAndChecksumsLen = + AoHeader_RegularSize + (usingChecksums ? 2 * sizeof(pg_crc32) : 0); /* * The extension header is in the data portion with first row number. @@ -1765,7 +1766,7 @@ AppendOnlyStorageFormat_GetBulkDenseContentHeaderInfo( *executorBlockKind = AOBulkDenseContentHeaderGet_executorBlockKind(blockHeader); *hasFirstRowNum = AOBulkDenseContentHeaderGet_hasFirstRowNum(blockHeader); - *rowCount = AOBulkDenseContentHeaderExtGet_largeRowCount(extHeader); + *rowCount = AOBulkDenseContentHeaderExtGet_largeRowCount(extHeader); if (*hasFirstRowNum) { @@ -1773,17 +1774,17 @@ AppendOnlyStorageFormat_GetBulkDenseContentHeaderInfo( firstRowNumPtr = (int64*)&headerPtr[*offset]; *firstRowNum = *firstRowNumPtr; - + (*offset) += sizeof(int64); } else *firstRowNum = INT64CONST(-1); - + if (*offset != headerLen) elog(ERROR, "Content offset %d doesn't equal header length parameter %d", *offset, headerLen); - + *uncompressedLen = AOBulkDenseContentHeaderGet_dataLength(blockHeader); *compressedLen = AOBulkDenseContentHeaderGet_compressedLength(blockHeader); if (*compressedLen == 0) @@ -1813,7 +1814,7 @@ AppendOnlyStorageFormat_GetBulkDenseContentHeaderInfo( return AOHeaderCheckInvalidCompressedLen; } } - + *overallBlockLen = *offset + AOStorage_RoundUp(length, version); @@ -1829,7 +1830,7 @@ AppendOnlyStorageFormat_GetBulkDenseContentHeaderInfo( extHeader->bulkdensecontent_ext_bytes_0_3, extHeader->bulkdensecontent_ext_bytes_4_7); return AOHeaderCheckInvalidOverallBlockLen; } - + return AOHeaderCheckOk; } @@ -1843,7 +1844,7 @@ AppendOnlyStorageFormat_VerifyHeaderChecksum( int32 firstHeaderAndBlockChecksumLen; pg_crc32 *headerChecksumPtr; - + Assert(headerPtr != NULL); Assert(storedChecksum != NULL); Assert(computedChecksum != NULL); @@ -1856,12 +1857,12 @@ AppendOnlyStorageFormat_VerifyHeaderChecksum( */ headerChecksumPtr = (pg_crc32*)&headerPtr[firstHeaderAndBlockChecksumLen]; *storedChecksum = *headerChecksumPtr; - + *computedChecksum = AppendOnlyStorageFormat_ComputeHeaderChecksum( headerPtr, firstHeaderAndBlockChecksumLen); - return (*storedChecksum == *computedChecksum); + return (*storedChecksum == *computedChecksum); } bool @@ -1874,7 +1875,7 @@ AppendOnlyStorageFormat_VerifyBlockChecksum( int32 firstHeaderLen; pg_crc32 *blockChecksumPtr; - + Assert(headerPtr != NULL); Assert(storedChecksum != NULL); Assert(computedChecksum != NULL); @@ -1886,11 +1887,11 @@ AppendOnlyStorageFormat_VerifyBlockChecksum( */ blockChecksumPtr = (pg_crc32*)&headerPtr[firstHeaderLen]; *storedChecksum = *blockChecksumPtr; - + *computedChecksum = AppendOnlyStorageFormat_ComputeBlockChecksum( headerPtr, firstHeaderLen + sizeof(pg_crc32), overallBlockLen); - return (*storedChecksum == *computedChecksum); + return (*storedChecksum == *computedChecksum); } http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/f988a712/src/backend/cdb/motion/ic_udp.c ---------------------------------------------------------------------- diff --git a/src/backend/cdb/motion/ic_udp.c b/src/backend/cdb/motion/ic_udp.c index 56201bb..bd7e197 100644 --- a/src/backend/cdb/motion/ic_udp.c +++ b/src/backend/cdb/motion/ic_udp.c @@ -49,6 +49,7 @@ #include "utils/builtins.h" #include "utils/debugbreak.h" #include "utils/pg_crc.h" +#include "port/pg_crc32c.h" #include "cdb/cdbselect.h" #include "cdb/tupchunklist.h" @@ -4662,8 +4663,9 @@ addCRC(icpkthdr *pkt) { pg_crc32 local_crc; - local_crc = crc32c(crc32cInit(), pkt, pkt->len); - crc32cFinish(local_crc); + INIT_CRC32C(local_crc); + COMP_CRC32C(local_crc, pkt, pkt->len); + FIN_CRC32C(local_crc); pkt->crc = local_crc; } @@ -4680,8 +4682,9 @@ checkCRC(icpkthdr *pkt) rx_crc = pkt->crc; pkt->crc = 0; - local_crc = crc32c(crc32cInit(), pkt, pkt->len); - crc32cFinish(local_crc); + INIT_CRC32C(local_crc); + COMP_CRC32C(local_crc, pkt, pkt->len); + FIN_CRC32C(local_crc); if (rx_crc != local_crc) { http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/f988a712/src/backend/storage/file/bfz.c ---------------------------------------------------------------------- diff --git a/src/backend/storage/file/bfz.c b/src/backend/storage/file/bfz.c index 0599896..c150634 100644 --- a/src/backend/storage/file/bfz.c +++ b/src/backend/storage/file/bfz.c @@ -84,7 +84,7 @@ bfz_close_callback(XactEvent event, void *arg) bfz_close(arg, false, (event!=XACT_EVENT_ABORT)); } -#define BFZ_CHECKSUM_EQ(c1, c2) EQ_CRC32(c1, c2) +#define BFZ_CHECKSUM_EQ(c1, c2) EQ_LEGACY_CRC32(c1, c2) /* * Compute a checksum for a given char array. @@ -99,17 +99,17 @@ compute_checksum(const char *buffer, uint32 size) */ uint32 currSectorBegin = 0; - crc = crc32cInit(); + INIT_CRC32C(crc); while (currSectorBegin < size) { - crc = crc32c(crc, buffer + currSectorBegin, + COMP_CRC32C(crc, buffer + currSectorBegin, Min(size - currSectorBegin, gp_workfile_bytes_to_checksum)); currSectorBegin += BFZ_CHECKSUM_SECTOR_SIZE; } - crc32cFinish(crc); + FIN_CRC32C(crc); return crc; } http://git-wip-us.apache.org/repos/asf/incubator-hawq/blob/f988a712/src/backend/utils/hash/Makefile ---------------------------------------------------------------------- diff --git a/src/backend/utils/hash/Makefile b/src/backend/utils/hash/Makefile index c3a8533..bfe658f 100644 --- a/src/backend/utils/hash/Makefile +++ b/src/backend/utils/hash/Makefile @@ -14,6 +14,6 @@ include $(top_builddir)/src/Makefile.global #override CPPFLAGS :=-msse4.2 $(CPPFLAGS) -OBJS = dynahash.o hashfn.o pg_crc.o crc32c.o +OBJS = dynahash.o hashfn.o pg_crc.o include $(top_srcdir)/src/backend/common.mk