Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
Derby - Class com.pivotal.gemfirexd.internal.iapi.services.sanity.SanityManager
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file 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 KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/*
* Changes for GemFireXD distributed data platform (some marked by "GemStone changes")
*
* Portions Copyright (c) 2010-2015 Pivotal Software, Inc. All rights reserved.
*
* Licensed 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 KIND, either express or
* implied. See the License for the specific language governing
* permissions and limitations under the License. See accompanying
* LICENSE file.
*/
package com.pivotal.gemfirexd.internal.shared.common.sanity;
import java.io.PrintWriter;
import java.util.Map;
import java.util.StringTokenizer;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicLong;
// GemStone changes BEGIN
import java.io.InputStream;
import java.io.PrintStream;
import java.nio.ByteBuffer;
import com.gemstone.gemfire.internal.shared.ClientSharedUtils;
import com.pivotal.gemfirexd.internal.shared.common.SharedUtils;
import io.snappydata.thrift.snappydataConstants;
// GemStone changes END
/**
* The SanityService provides assertion checking and debug
* control.
*
* Assertions and debug checks
* can only be used for testing conditions that might occur
* in development code but not in production code.
* They are compiled out of production code.
*
* Uses of assertions should not add AssertFailure catches or
* throws clauses; AssertFailure is under RuntimeException
* in the java exception hierarchy. Our outermost system block
* will bring the system down when it detects an assertion
* failure.
*
* In addition to ASSERTs in code, classes can choose to implement
* an isConsistent method that would be used by ASSERTs, UnitTests,
* and any other code wanting to check the consistency of an object.
*
* Assertions are meant to be used to verify the state of the system
* and bring the system down if the state is not correct. Debug checks
* are meant to display internal information about a running system.
*
* @see AssertFailure
*/
public class SanityManager {
/**
* The build tool may be configured to alter
* this source file to reset the static final variables
* so that assertion and debug checks can be compiled out
* of the code.
*/
public static final boolean ASSERT = SanityState.ASSERT; // code should use DEBUG
public static final boolean DEBUG = SanityState.DEBUG;
public static final String DEBUGDEBUG = "DumpSanityDebug";
/**
* debugStream holds a pointer to the debug stream for writing out
* debug messages. It is cached at the first debug write request.
*/
// GemStone changes BEGIN
public static final boolean DEBUG_ASSERT = SanityState.DEBUG_ASSERT;
static private final java.io.PrintWriter DEFAULT_WRITER =
new java.io.PrintWriter(System.err);
// static private java.io.PrintWriter debugStream = new java.io.PrintWriter(System.err);
static private java.io.PrintWriter debugStream = DEFAULT_WRITER;
/**
* DebugFlags holds the values of all debug flags in
* the configuration file.
*/
// static private Hashtable DebugFlags = new Hashtable();
static private Map DebugFlags;
/**
* Flag to enable tracing of client server selection, locator detection,
* failover etc.
*/
public static final String TRACE_CLIENT_HA = "TraceClientHA";
/**
* Flag to enable tracing of client connection create/close stack traces
*/
public static final String TRACE_CLIENT_CONN = "TraceClientConn";
/**
* Flag to enable tracing of statement prepare/execution/iteration.
*/
public static final String TRACE_CLIENT_STMT = "TraceClientStatement";
/**
* Flag to enable logging of wall clock millis time in the tracing for
* {@link #TRACE_CLIENT_STMT}. Also turns on {@link #TRACE_CLIENT_STMT}.
*/
public static final String TRACE_CLIENT_STMT_MS =
"TraceClientStatementMillis";
/**
* Flag to enable tracing of possible memory leaks in some places.
*/
public static final String TRACE_MEMORY_LEAK = "TraceMemoryLeak";
/**
* Flag to enable tracing of ConcurrentCache operations.
*/
public static final String TRACE_CACHE = "TraceCache";
/**
* Flag to enable tracing for single hop.
*/
public static final String TRACE_SINGLE_HOP = "TraceSingleHop";
/** Test flag to run tests in non-transactional mode.
* If provided as true in system and environment variable, the tests will use
* connections with transaction isolation level NONE
* and autocommit false. If not, the tests will use connections with READ_COMMITTED
* isolation level and autocommit true.*/
public static final String TEST_MODE_NON_TX = "TEST_MODE_NON_TX";
/**
* Static boolean set if client HA logging is turned on.
*/
public static boolean TraceClientHA = false;
/**
* Static boolean set if client connection creation/close stack
* traces are to be traced.
*/
public static boolean TraceClientConn = false;
/**
* Static boolean set if client statement verbose logging is turned on.
*/
public static boolean TraceClientStatement = false;
/**
* Static boolean set if client statement verbose logging should also
* log wall clock time in millis.
*/
public static boolean TraceClientStatementMillis = false;
/**
* Set when either of {@link #TRACE_CLIENT_HA} or
* {@link #TRACE_CLIENT_STMT} are set.
*/
public static boolean TraceClientStatementHA = false;
/**
* Static boolean set if memory leak tracing is turned on.
*/
public static boolean TraceMemoryLeak = false;
/**
* Static boolean set if ConcurrentCache tracing is turned on.
*/
public static boolean TraceCache = false;
/**
* Static boolean set if single hop tracing is turned on.
*/
public static boolean TraceSingleHop = false;
public static final String DEBUG_TRUE = "gemfirexd.debug.true";
public static final String DEBUG_FALSE = "gemfirexd.debug.false";
public static boolean isFineEnabled = false;
public static boolean isFinerEnabled = false;
static {
DebugFlags = new ConcurrentHashMap(16, 0.75f, 4);
}
// GemStone changes END
/**
* AllDebugOn and AllDebugOff override individual flags
*/
static private boolean AllDebugOn = false;
static private boolean AllDebugOff = false;
//
// class interface
//
/**
* ASSERT checks the condition, and if it is
* false, throws AssertFailure.
* A message about the assertion failing is
* printed.
*
* @see AssertFailure
*/
public static final void ASSERT(boolean mustBeTrue) {
if (DEBUG)
if (! mustBeTrue) {
if (DEBUG) {
AssertFailure af = new AssertFailure("ASSERT FAILED");
if (TRACE_ON("AssertFailureTrace")) {
showTrace(af);
}
throw af;
}
else
throw new AssertFailure("ASSERT FAILED");
}
}
/**
* ASSERT checks the condition, and if it is
* false, throws AssertFailure. The message will
* be printed and included in the assertion.
*
* @see AssertFailure
*/
public static final void ASSERT(boolean mustBeTrue, String msgIfFail) {
if (DEBUG)
if (! mustBeTrue) {
if (DEBUG) {
AssertFailure af = new AssertFailure("ASSERT FAILED " + msgIfFail);
if (TRACE_ON("AssertFailureTrace")) {
showTrace(af);
}
throw af;
}
else
throw new AssertFailure("ASSERT FAILED " + msgIfFail);
}
}
/**
* THROWASSERT throws AssertFailure. This is used in cases where
* the caller has already detected the assertion failure (such as
* in the default case of a switch). This method should be used,
* rather than throwing AssertFailure directly, to allow us to
* centralize all sanity checking. The message argument will
* be printed and included in the assertion.
*
* @param msgIfFail message to print with the assertion
*
* @see AssertFailure
*/
public static final void THROWASSERT(String msgIfFail) {
// XXX (nat) Hmm, should we check ASSERT here? The caller is
// not expecting this function to return, whether assertions
// are compiled in or not.
THROWASSERT(msgIfFail, null);
}
/**
* THROWASSERT throws AssertFailure.
* This flavor will print the stack associated with the exception.
* The message argument will
* be printed and included in the assertion.
*
* @param msg message to print with the assertion
* @param t exception to print with the assertion
*
* @see AssertFailure
*/
public static final void THROWASSERT(String msg, Throwable t) {
// GemStone changes BEGIN
try {
Class cls = Class.forName(
"com.pivotal.gemfirexd.internal.engine.store.GemFireStore");
if (cls != null) {
msg = msg + "; myID: " + cls.getMethod("getMyId",
(Class[])null).invoke(null, (Object[])null);
}
} catch (Throwable ignored) {
// ignore here
}
// GemStone changes END
AssertFailure af = new AssertFailure("ASSERT FAILED " + msg, t);
if (DEBUG) {
if (TRACE_ON("AssertFailureTrace")) {
showTrace(af);
}
}
if (t != null) {
showTrace(t);
}
throw af;
}
/**
* THROWASSERT throws AssertFailure.
* This flavor will print the stack associated with the exception.
*
* @param t exception to print with the assertion
*
* @see AssertFailure
*/
public static final void THROWASSERT(Throwable t) {
THROWASSERT(t.toString(), t);
}
/**
* The DEBUG calls provide the ability to print information or
* perform actions based on whether a debug flag is set or not.
* debug flags are set in configurations and picked up by the
* sanity manager when the monitor finds them (see CONFIG below).
*
* The message is output to the trace stream, so it ends up in
* db2j.LOG. It will include a header line of
* DEBUG OUTPUT:
* before the message.
*
* If the debugStream stream cannot be found, the message is printed to
* System.out.
*/
public static final void DEBUG(String flag, String message) {
if (DEBUG) {
if (flag == null || DEBUG_ON(flag)) {
DEBUG_PRINT(flag, message);
}
}
}
/**
* This can be called directly if you want to control
* what is done once the debug flag has been verified --
* for example, if you are calling a routine that prints to
* the trace stream directly rather than returning a string to
* be printed, or if you want to perform more (or fewer!)
*
*
* Calls to this method should be surrounded with
* if (SanityManager.DEBUG) {
* }
* so that they can be compiled out completely.
*
* @return true if the flag has been set to "true"; false
* if the flag is not set, or is set to something other than "true".
*/
public static final boolean DEBUG_ON(String flag) {
if (DEBUG) {
if (AllDebugOn) return true;
else if (AllDebugOff) return false;
else {
Boolean flagValue = (Boolean) DebugFlags.get(flag);
if (! DEBUGDEBUG.equals(flag)) {
if (DEBUG_ON(DEBUGDEBUG)) {
DEBUG_PRINT(DEBUGDEBUG, "DEBUG_ON: Debug flag "+flag+" = "+flagValue);
}
}
if (flagValue == null) return false;
else return flagValue.booleanValue();
}
}
else return false;
}
// GemStone changes BEGIN
public static final void TRACE_SET_IF_ABSENT(String flag) {
if (!DebugFlags.containsKey(flag)) {
// alter the flags even in insane build to allow explicit tracing
if (!DEBUGDEBUG.equals(flag)) {
if (TRACE_ON(DEBUGDEBUG)) {
DEBUG_PRINT(DEBUGDEBUG, "TRACE_SET_IF_ABSENT: Debug flag " + flag);
}
}
DebugFlags.put(flag, Boolean.TRUE);
}
}
/**
* This is different from DEBUG_ON as it doesn't check for .DEBUG (i.e.
* sane/insane build). Flags that can be enabled in production version.
*/
public static final boolean TRACE_ON(String flag) {
if (AllDebugOn) {
return true;
}
else if (AllDebugOff) {
return false;
}
else {
Boolean flagValue = (Boolean)DebugFlags.get(flag);
if (!DEBUGDEBUG.equals(flag)) {
if (TRACE_ON(DEBUGDEBUG)) {
DEBUG_PRINT(DEBUGDEBUG, "TRACE_ON: Debug flag " + flag
+ " = " + flagValue);
}
}
return (flagValue != null ? flagValue.booleanValue() : false);
}
}
/**
* Returns true only if debug.false/true is explicitly set for the flag.
*/
public static final boolean TRACE_OFF(String flag) {
if (AllDebugOn) {
return false;
}
else if (AllDebugOff) {
return true;
}
else {
Boolean flagValue = (Boolean)DebugFlags.get(flag);
if (!DEBUGDEBUG.equals(flag)) {
if (TRACE_ON(DEBUGDEBUG)) {
DEBUG_PRINT(DEBUGDEBUG, "TRACE_OFF: Debug flag " + flag
+ " = " + flagValue);
}
}
return (flagValue != null ? !flagValue.booleanValue() : false);
}
}
public static final void clearFlags(boolean forBoot) {
// don't clear DebugFlags in boot since they have already been
// initialized and we will lose all of them
if (!forBoot) {
DebugFlags.clear();
}
isFineEnabled = false;
isFinerEnabled = false;
}
private static final class FlagsInit {
static {
addDebugFlags(System.getProperty(DEBUG_FALSE), false);
addDebugFlags(System.getProperty(DEBUG_TRUE), true);
initCustomFlags();
}
static void init() {
// nothing to do here
}
}
private static void initFlags() {
FlagsInit.init();
}
static void initCustomFlags() {
TraceClientHA = TRACE_ON(TRACE_CLIENT_HA);
TraceClientConn = TRACE_ON(TRACE_CLIENT_CONN);
TraceClientStatementMillis = TRACE_ON(TRACE_CLIENT_STMT_MS);
TraceClientStatement = TraceClientStatementMillis ||
TRACE_ON(TRACE_CLIENT_STMT);
TraceClientStatementHA = (TraceClientHA || TraceClientStatement);
TraceMemoryLeak = TRACE_ON(TRACE_MEMORY_LEAK);
TraceCache = TRACE_ON(TRACE_CACHE);
TraceSingleHop = TRACE_ON(TRACE_SINGLE_HOP);
if (TraceClientStatement) {
sqlIdMap = new ConcurrentHashMap