Merge branch 'cassandra-3.11' into trunk

Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo
Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/2ad06d65
Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/2ad06d65
Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/2ad06d65

Branch: refs/heads/trunk
Commit: 2ad06d65b31d6221ac5c78991c13e125800bc48d
Parents: 39bcdcd bd08040
Author: Jason Brown <jasedbr...@gmail.com>
Authored: Mon Mar 26 04:11:03 2018 -0700
Committer: Jason Brown <jasedbr...@gmail.com>
Committed: Mon Mar 26 04:20:54 2018 -0700

----------------------------------------------------------------------
 CHANGES.txt                                     |   1 +
 .../cql3/functions/JavaBasedUDFunction.java     |   3 +
 .../cql3/functions/ScriptBasedUDFunction.java   |   2 +
 .../cql3/functions/SecurityThreadGroup.java     |  53 ----
 .../functions/ThreadAwareSecurityManager.java   | 275 -------------------
 .../cassandra/security/SecurityThreadGroup.java |  53 ++++
 .../security/ThreadAwareSecurityManager.java    | 214 +++++++++++++++
 .../cassandra/service/CassandraDaemon.java      |   2 +-
 .../cassandra/service/StorageService.java       |  51 +---
 .../utils/logging/LogbackLoggingSupport.java    | 151 ++++++++++
 .../cassandra/utils/logging/LoggingSupport.java |  34 +++
 .../utils/logging/LoggingSupportFactory.java    |  42 +++
 .../logging/NoOpFallbackLoggingSupport.java     |  30 ++
 .../org/apache/cassandra/cql3/CQLTester.java    |   2 +-
 14 files changed, 537 insertions(+), 376 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/2ad06d65/CHANGES.txt
----------------------------------------------------------------------
diff --cc CHANGES.txt
index 76803a8,5646081..8c8ddd2
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@@ -1,213 -1,5 +1,214 @@@
 +4.0
 + * Fix scheduling of speculative retry threshold recalculation 
(CASSANDRA-14338)
 + * Add support for hybrid MIN(), MAX() speculative retry policies 
(CASSANDRA-14293)
 + * Correct and clarify SSLFactory.getSslContext method and call sites 
(CASSANDRA-14314)
 + * Handle static and partition deletion properly on 
ThrottledUnfilteredIterator (CASSANDRA-14315)
 + * NodeTool clientstats should show SSL Cipher (CASSANDRA-14322)
 + * Add ability to specify driver name and version (CASSANDRA-14275)
 + * Abstract streaming for pluggable storage (CASSANDRA-14115)
 + * Forced incremental repairs should promote sstables if they can 
(CASSANDRA-14294)
 + * Use Murmur3 for validation compactions (CASSANDRA-14002)
 + * Comma at the end of the seed list is interpretated as localhost 
(CASSANDRA-14285)
 + * Refactor read executor and response resolver, abstract read repair 
(CASSANDRA-14058)
 + * Add optional startup delay to wait until peers are ready (CASSANDRA-13993)
 + * Add a few options to nodetool verify (CASSANDRA-14201)
 + * CVE-2017-5929 Security vulnerability and redefine default log rotation 
policy (CASSANDRA-14183)
 + * Use JVM default SSL validation algorithm instead of custom default 
(CASSANDRA-13259)
 + * Better document in code InetAddressAndPort usage post 7544, incorporate 
port into UUIDGen node (CASSANDRA-14226)
 + * Fix sstablemetadata date string for minLocalDeletionTime (CASSANDRA-14132)
 + * Make it possible to change neverPurgeTombstones during runtime 
(CASSANDRA-14214)
 + * Remove GossipDigestSynVerbHandler#doSort() (CASSANDRA-14174)
 + * Add nodetool clientlist (CASSANDRA-13665)
 + * Revert ProtocolVersion changes from CASSANDRA-7544 (CASSANDRA-14211)
 + * Non-disruptive seed node list reload (CASSANDRA-14190)
 + * Nodetool tablehistograms to print statics for all the tables 
(CASSANDRA-14185)
 + * Migrate dtests to use pytest and python3 (CASSANDRA-14134)
 + * Allow storage port to be configurable per node (CASSANDRA-7544)
 + * Make sub-range selection for non-frozen collections return null instead of 
empty (CASSANDRA-14182)
 + * BloomFilter serialization format should not change byte ordering 
(CASSANDRA-9067)
 + * Remove unused on-heap BloomFilter implementation (CASSANDRA-14152)
 + * Delete temp test files on exit (CASSANDRA-14153)
 + * Make PartitionUpdate and Mutation immutable (CASSANDRA-13867)
 + * Fix CommitLogReplayer exception for CDC data (CASSANDRA-14066)
 + * Fix cassandra-stress startup failure (CASSANDRA-14106)
 + * Remove initialDirectories from CFS (CASSANDRA-13928)
 + * Fix trivial log format error (CASSANDRA-14015)
 + * Allow sstabledump to do a json object per partition (CASSANDRA-13848)
 + * Add option to optimise merkle tree comparison across replicas 
(CASSANDRA-3200)
 + * Remove unused and deprecated methods from AbstractCompactionStrategy 
(CASSANDRA-14081)
 + * Fix Distribution.average in cassandra-stress (CASSANDRA-14090)
 + * Support a means of logging all queries as they were invoked 
(CASSANDRA-13983)
 + * Presize collections (CASSANDRA-13760)
 + * Add GroupCommitLogService (CASSANDRA-13530)
 + * Parallelize initial materialized view build (CASSANDRA-12245)
 + * Fix flaky SecondaryIndexManagerTest.assert[Not]MarkedAsBuilt 
(CASSANDRA-13965)
 + * Make LWTs send resultset metadata on every request (CASSANDRA-13992)
 + * Fix flaky indexWithFailedInitializationIsNotQueryableAfterPartialRebuild 
(CASSANDRA-13963)
 + * Introduce leaf-only iterator (CASSANDRA-9988)
 + * Upgrade Guava to 23.3 and Airline to 0.8 (CASSANDRA-13997)
 + * Allow only one concurrent call to StatusLogger (CASSANDRA-12182)
 + * Refactoring to specialised functional interfaces (CASSANDRA-13982)
 + * Speculative retry should allow more friendly params (CASSANDRA-13876)
 + * Throw exception if we send/receive repair messages to incompatible nodes 
(CASSANDRA-13944)
 + * Replace usages of MessageDigest with Guava's Hasher (CASSANDRA-13291)
 + * Add nodetool cmd to print hinted handoff window (CASSANDRA-13728)
 + * Fix some alerts raised by static analysis (CASSANDRA-13799)
 + * Checksum sstable metadata (CASSANDRA-13321, CASSANDRA-13593)
 + * Add result set metadata to prepared statement MD5 hash calculation 
(CASSANDRA-10786)
 + * Refactor GcCompactionTest to avoid boxing (CASSANDRA-13941)
 + * Expose recent histograms in JmxHistograms (CASSANDRA-13642)
 + * Fix buffer length comparison when decompressing in netty-based streaming 
(CASSANDRA-13899)
 + * Properly close StreamCompressionInputStream to release any ByteBuf 
(CASSANDRA-13906)
 + * Add SERIAL and LOCAL_SERIAL support for cassandra-stress (CASSANDRA-13925)
 + * LCS needlessly checks for L0 STCS candidates multiple times 
(CASSANDRA-12961)
 + * Correctly close netty channels when a stream session ends (CASSANDRA-13905)
 + * Update lz4 to 1.4.0 (CASSANDRA-13741)
 + * Optimize Paxos prepare and propose stage for local requests 
(CASSANDRA-13862)
 + * Throttle base partitions during MV repair streaming to prevent OOM 
(CASSANDRA-13299)
 + * Use compaction threshold for STCS in L0 (CASSANDRA-13861)
 + * Fix problem with min_compress_ratio: 1 and disallow ratio < 1 
(CASSANDRA-13703)
 + * Add extra information to SASI timeout exception (CASSANDRA-13677)
 + * Add incremental repair support for --hosts, --force, and subrange repair 
(CASSANDRA-13818)
 + * Rework CompactionStrategyManager.getScanners synchronization 
(CASSANDRA-13786)
 + * Add additional unit tests for batch behavior, TTLs, Timestamps 
(CASSANDRA-13846)
 + * Add keyspace and table name in schema validation exception 
(CASSANDRA-13845)
 + * Emit metrics whenever we hit tombstone failures and warn thresholds 
(CASSANDRA-13771)
 + * Make netty EventLoopGroups daemon threads (CASSANDRA-13837)
 + * Race condition when closing stream sessions (CASSANDRA-13852)
 + * NettyFactoryTest is failing in trunk on macOS (CASSANDRA-13831)
 + * Allow changing log levels via nodetool for related classes 
(CASSANDRA-12696)
 + * Add stress profile yaml with LWT (CASSANDRA-7960)
 + * Reduce memory copies and object creations when acting on ByteBufs 
(CASSANDRA-13789)
 + * Simplify mx4j configuration (Cassandra-13578)
 + * Fix trigger example on 4.0 (CASSANDRA-13796)
 + * Force minumum timeout value (CASSANDRA-9375)
 + * Use netty for streaming (CASSANDRA-12229)
 + * Use netty for internode messaging (CASSANDRA-8457)
 + * Add bytes repaired/unrepaired to nodetool tablestats (CASSANDRA-13774)
 + * Don't delete incremental repair sessions if they still have sstables 
(CASSANDRA-13758)
 + * Fix pending repair manager index out of bounds check (CASSANDRA-13769)
 + * Don't use RangeFetchMapCalculator when RF=1 (CASSANDRA-13576)
 + * Don't optimise trivial ranges in RangeFetchMapCalculator (CASSANDRA-13664)
 + * Use an ExecutorService for repair commands instead of new 
Thread(..).start() (CASSANDRA-13594)
 + * Fix race / ref leak in anticompaction (CASSANDRA-13688)
 + * Expose tasks queue length via JMX (CASSANDRA-12758)
 + * Fix race / ref leak in PendingRepairManager (CASSANDRA-13751)
 + * Enable ppc64le runtime as unsupported architecture (CASSANDRA-13615)
 + * Improve sstablemetadata output (CASSANDRA-11483)
 + * Support for migrating legacy users to roles has been dropped 
(CASSANDRA-13371)
 + * Introduce error metrics for repair (CASSANDRA-13387)
 + * Refactoring to primitive functional interfaces in AuthCache 
(CASSANDRA-13732)
 + * Update metrics to 3.1.5 (CASSANDRA-13648)
 + * batch_size_warn_threshold_in_kb can now be set at runtime (CASSANDRA-13699)
 + * Avoid always rebuilding secondary indexes at startup (CASSANDRA-13725)
 + * Upgrade JMH from 1.13 to 1.19 (CASSANDRA-13727)
 + * Upgrade SLF4J from 1.7.7 to 1.7.25 (CASSANDRA-12996)
 + * Default for start_native_transport now true if not set in config 
(CASSANDRA-13656)
 + * Don't add localhost to the graph when calculating where to stream from 
(CASSANDRA-13583)
 + * Make CDC availability more deterministic via hard-linking (CASSANDRA-12148)
 + * Allow skipping equality-restricted clustering columns in ORDER BY clause 
(CASSANDRA-10271)
 + * Use common nowInSec for validation compactions (CASSANDRA-13671)
 + * Improve handling of IR prepare failures (CASSANDRA-13672)
 + * Send IR coordinator messages synchronously (CASSANDRA-13673)
 + * Flush system.repair table before IR finalize promise (CASSANDRA-13660)
 + * Fix column filter creation for wildcard queries (CASSANDRA-13650)
 + * Add 'nodetool getbatchlogreplaythrottle' and 'nodetool 
setbatchlogreplaythrottle' (CASSANDRA-13614)
 + * fix race condition in PendingRepairManager (CASSANDRA-13659)
 + * Allow noop incremental repair state transitions (CASSANDRA-13658)
 + * Run repair with down replicas (CASSANDRA-10446)
 + * Added started & completed repair metrics (CASSANDRA-13598)
 + * Added started & completed repair metrics (CASSANDRA-13598)
 + * Improve secondary index (re)build failure and concurrency handling 
(CASSANDRA-10130)
 + * Improve calculation of available disk space for compaction 
(CASSANDRA-13068)
 + * Change the accessibility of RowCacheSerializer for third party row cache 
plugins (CASSANDRA-13579)
 + * Allow sub-range repairs for a preview of repaired data (CASSANDRA-13570)
 + * NPE in IR cleanup when columnfamily has no sstables (CASSANDRA-13585)
 + * Fix Randomness of stress values (CASSANDRA-12744)
 + * Allow selecting Map values and Set elements (CASSANDRA-7396)
 + * Fast and garbage-free Streaming Histogram (CASSANDRA-13444)
 + * Update repairTime for keyspaces on completion (CASSANDRA-13539)
 + * Add configurable upper bound for validation executor threads 
(CASSANDRA-13521)
 + * Bring back maxHintTTL propery (CASSANDRA-12982)
 + * Add testing guidelines (CASSANDRA-13497)
 + * Add more repair metrics (CASSANDRA-13531)
 + * RangeStreamer should be smarter when picking endpoints for streaming 
(CASSANDRA-4650)
 + * Avoid rewrapping an exception thrown for cache load functions 
(CASSANDRA-13367)
 + * Log time elapsed for each incremental repair phase (CASSANDRA-13498)
 + * Add multiple table operation support to cassandra-stress (CASSANDRA-8780)
 + * Fix incorrect cqlsh results when selecting same columns multiple times 
(CASSANDRA-13262)
 + * Fix WriteResponseHandlerTest is sensitive to test execution order 
(CASSANDRA-13421)
 + * Improve incremental repair logging (CASSANDRA-13468)
 + * Start compaction when incremental repair finishes (CASSANDRA-13454)
 + * Add repair streaming preview (CASSANDRA-13257)
 + * Cleanup isIncremental/repairedAt usage (CASSANDRA-13430)
 + * Change protocol to allow sending key space independent of query string 
(CASSANDRA-10145)
 + * Make gc_log and gc_warn settable at runtime (CASSANDRA-12661)
 + * Take number of files in L0 in account when estimating remaining compaction 
tasks (CASSANDRA-13354)
 + * Skip building views during base table streams on range movements 
(CASSANDRA-13065)
 + * Improve error messages for +/- operations on maps and tuples 
(CASSANDRA-13197)
 + * Remove deprecated repair JMX APIs (CASSANDRA-11530)
 + * Fix version check to enable streaming keep-alive (CASSANDRA-12929)
 + * Make it possible to monitor an ideal consistency level separate from 
actual consistency level (CASSANDRA-13289)
 + * Outbound TCP connections ignore internode authenticator (CASSANDRA-13324)
 + * Upgrade junit from 4.6 to 4.12 (CASSANDRA-13360)
 + * Cleanup ParentRepairSession after repairs (CASSANDRA-13359)
 + * Upgrade snappy-java to 1.1.2.6 (CASSANDRA-13336)
 + * Incremental repair not streaming correct sstables (CASSANDRA-13328)
 + * Upgrade the jna version to 4.3.0 (CASSANDRA-13300)
 + * Add the currentTimestamp, currentDate, currentTime and currentTimeUUID 
functions (CASSANDRA-13132)
 + * Remove config option index_interval (CASSANDRA-10671)
 + * Reduce lock contention for collection types and serializers 
(CASSANDRA-13271)
 + * Make it possible to override MessagingService.Verb ids (CASSANDRA-13283)
 + * Avoid synchronized on prepareForRepair in ActiveRepairService 
(CASSANDRA-9292)
 + * Adds the ability to use uncompressed chunks in compressed files 
(CASSANDRA-10520)
 + * Don't flush sstables when streaming for incremental repair 
(CASSANDRA-13226)
 + * Remove unused method (CASSANDRA-13227)
 + * Fix minor bugs related to #9143 (CASSANDRA-13217)
 + * Output warning if user increases RF (CASSANDRA-13079)
 + * Remove pre-3.0 streaming compatibility code for 4.0 (CASSANDRA-13081)
 + * Add support for + and - operations on dates (CASSANDRA-11936)
 + * Fix consistency of incrementally repaired data (CASSANDRA-9143)
 + * Increase commitlog version (CASSANDRA-13161)
 + * Make TableMetadata immutable, optimize Schema (CASSANDRA-9425)
 + * Refactor ColumnCondition (CASSANDRA-12981)
 + * Parallelize streaming of different keyspaces (CASSANDRA-4663)
 + * Improved compactions metrics (CASSANDRA-13015)
 + * Speed-up start-up sequence by avoiding un-needed flushes (CASSANDRA-13031)
 + * Use Caffeine (W-TinyLFU) for on-heap caches (CASSANDRA-10855)
 + * Thrift removal (CASSANDRA-11115)
 + * Remove pre-3.0 compatibility code for 4.0 (CASSANDRA-12716)
 + * Add column definition kind to dropped columns in schema (CASSANDRA-12705)
 + * Add (automate) Nodetool Documentation (CASSANDRA-12672)
 + * Update bundled cqlsh python driver to 3.7.0 (CASSANDRA-12736)
 + * Reject invalid replication settings when creating or altering a keyspace 
(CASSANDRA-12681)
 + * Clean up the SSTableReader#getScanner API wrt removal of RateLimiter 
(CASSANDRA-12422)
 + * Use new token allocation for non bootstrap case as well (CASSANDRA-13080)
 + * Avoid byte-array copy when key cache is disabled (CASSANDRA-13084)
 + * Require forceful decommission if number of nodes is less than replication 
factor (CASSANDRA-12510)
 + * Allow IN restrictions on column families with collections (CASSANDRA-12654)
 + * Log message size in trace message in OutboundTcpConnection 
(CASSANDRA-13028)
 + * Add timeUnit Days for cassandra-stress (CASSANDRA-13029)
 + * Add mutation size and batch metrics (CASSANDRA-12649)
 + * Add method to get size of endpoints to TokenMetadata (CASSANDRA-12999)
 + * Expose time spent waiting in thread pool queue (CASSANDRA-8398)
 + * Conditionally update index built status to avoid unnecessary flushes 
(CASSANDRA-12969)
 + * cqlsh auto completion: refactor definition of compaction strategy options 
(CASSANDRA-12946)
 + * Add support for arithmetic operators (CASSANDRA-11935)
 + * Add histogram for delay to deliver hints (CASSANDRA-13234)
 + * Fix cqlsh automatic protocol downgrade regression (CASSANDRA-13307)
 + * Changing `max_hint_window_in_ms` at runtime (CASSANDRA-11720)
 + * Trivial format error in StorageProxy (CASSANDRA-13551)
 + * Nodetool repair can hang forever if we lose the notification for the 
repair completing/failing (CASSANDRA-13480)
 + * Anticompaction can cause noisy log messages (CASSANDRA-13684)
 + * Switch to client init for sstabledump (CASSANDRA-13683)
 + * CQLSH: Don't pause when capturing data (CASSANDRA-13743)
 + * nodetool clearsnapshot requires --all to clear all snapshots 
(CASSANDRA-13391)
 + * Correctly count range tombstones in traces and tombstone thresholds 
(CASSANDRA-8527)
 + * cqlshrc.sample uses incorrect option for time formatting (CASSANDRA-14243)
 +
 +
  3.11.3
+  * Allow logging implementation to be interchanged for embedded testing 
(CASSANDRA-13396)
   * SASI tokenizer for simple delimiter based entries (CASSANDRA-14247)
   * Fix Loss of digits when doing CAST from varint/bigint to decimal 
(CASSANDRA-14170)
   * RateBasedBackPressure unnecessarily invokes a lock on the Guava 
RateLimiter (CASSANDRA-14163)

http://git-wip-us.apache.org/repos/asf/cassandra/blob/2ad06d65/src/java/org/apache/cassandra/cql3/functions/ScriptBasedUDFunction.java
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/cassandra/blob/2ad06d65/src/java/org/apache/cassandra/service/CassandraDaemon.java
----------------------------------------------------------------------
diff --cc src/java/org/apache/cassandra/service/CassandraDaemon.java
index 95dd6ac,d9bd5c3..5ca3844
--- a/src/java/org/apache/cassandra/service/CassandraDaemon.java
+++ b/src/java/org/apache/cassandra/service/CassandraDaemon.java
@@@ -48,14 -45,12 +48,13 @@@ import com.google.common.util.concurren
  import org.slf4j.Logger;
  import org.slf4j.LoggerFactory;
  
 -import org.apache.cassandra.batchlog.LegacyBatchlogMigrator;
  import org.apache.cassandra.concurrent.ScheduledExecutors;
 -import org.apache.cassandra.config.CFMetaData;
 +import org.apache.cassandra.locator.InetAddressAndPort;
 +import org.apache.cassandra.net.StartupClusterConnectivityChecker;
 +import org.apache.cassandra.schema.TableMetadata;
  import org.apache.cassandra.config.DatabaseDescriptor;
 -import org.apache.cassandra.config.Schema;
 -import org.apache.cassandra.config.SchemaConstants;
 +import org.apache.cassandra.schema.Schema;
 +import org.apache.cassandra.schema.SchemaConstants;
- import org.apache.cassandra.cql3.functions.ThreadAwareSecurityManager;
  import org.apache.cassandra.cql3.QueryProcessor;
  import org.apache.cassandra.db.*;
  import org.apache.cassandra.db.commitlog.CommitLog;
@@@ -68,8 -64,11 +67,9 @@@ import org.apache.cassandra.io.util.Fil
  import org.apache.cassandra.metrics.CassandraMetricsRegistry;
  import org.apache.cassandra.metrics.DefaultNameFactory;
  import org.apache.cassandra.metrics.StorageMetrics;
 -import org.apache.cassandra.schema.LegacySchemaMigrator;
 -import org.apache.cassandra.thrift.ThriftServer;
  import org.apache.cassandra.tracing.Tracing;
  import org.apache.cassandra.utils.*;
+ import org.apache.cassandra.security.ThreadAwareSecurityManager;
  
  /**
   * The <code>CassandraDaemon</code> is an abstraction for a Cassandra daemon

http://git-wip-us.apache.org/repos/asf/cassandra/blob/2ad06d65/src/java/org/apache/cassandra/service/StorageService.java
----------------------------------------------------------------------
diff --cc src/java/org/apache/cassandra/service/StorageService.java
index 51b77a6,373493c..ce1f9ad
--- a/src/java/org/apache/cassandra/service/StorageService.java
+++ b/src/java/org/apache/cassandra/service/StorageService.java
@@@ -46,13 -46,8 +46,8 @@@ import org.apache.commons.lang3.StringU
  import org.slf4j.Logger;
  import org.slf4j.LoggerFactory;
  
- import ch.qos.logback.classic.LoggerContext;
- import ch.qos.logback.classic.jmx.JMXConfiguratorMBean;
- import ch.qos.logback.classic.spi.ILoggingEvent;
- import ch.qos.logback.core.Appender;
- import ch.qos.logback.core.hook.DelayingShutdownHook;
  import org.apache.cassandra.auth.AuthKeyspace;
 -import org.apache.cassandra.auth.AuthMigrationListener;
 +import org.apache.cassandra.auth.AuthSchemaChangeListener;
  import org.apache.cassandra.batchlog.BatchRemoveVerbHandler;
  import org.apache.cassandra.batchlog.BatchStoreVerbHandler;
  import org.apache.cassandra.batchlog.BatchlogManager;

http://git-wip-us.apache.org/repos/asf/cassandra/blob/2ad06d65/src/java/org/apache/cassandra/utils/logging/LogbackLoggingSupport.java
----------------------------------------------------------------------
diff --cc src/java/org/apache/cassandra/utils/logging/LogbackLoggingSupport.java
index 0000000,3229460..7249caf
mode 000000,100644..100644
--- a/src/java/org/apache/cassandra/utils/logging/LogbackLoggingSupport.java
+++ b/src/java/org/apache/cassandra/utils/logging/LogbackLoggingSupport.java
@@@ -1,0 -1,146 +1,151 @@@
+ package org.apache.cassandra.utils.logging;
+ 
+ import java.lang.management.ManagementFactory;
+ import java.security.AccessControlException;
+ import java.util.Iterator;
+ import java.util.Map;
+ 
+ import javax.management.JMX;
+ import javax.management.ObjectName;
+ 
+ import org.apache.cassandra.security.ThreadAwareSecurityManager;
+ import org.apache.commons.lang3.StringUtils;
+ import org.slf4j.LoggerFactory;
+ 
+ import com.google.common.collect.Maps;
+ 
+ import ch.qos.logback.classic.Level;
+ import ch.qos.logback.classic.Logger;
+ import ch.qos.logback.classic.LoggerContext;
+ import ch.qos.logback.classic.jmx.JMXConfiguratorMBean;
+ import ch.qos.logback.classic.spi.ILoggingEvent;
+ import ch.qos.logback.classic.spi.TurboFilterList;
+ import ch.qos.logback.classic.turbo.ReconfigureOnChangeFilter;
+ import ch.qos.logback.classic.turbo.TurboFilter;
+ import ch.qos.logback.core.Appender;
+ import ch.qos.logback.core.hook.DelayingShutdownHook;
+ 
+ /**
+  * Encapsulates all logback-specific implementations in a central place.
+  * Generally, the Cassandra code-base should be logging-backend agnostic and 
only use slf4j-api.
+  * This class MUST NOT be used directly, but only via {@link 
LoggingSupportFactory} which dynamically loads and
+  * instantiates an appropriate implementation according to the used slf4j 
binding.
+  */
+ public class LogbackLoggingSupport implements LoggingSupport
+ {
+ 
+     private static final org.slf4j.Logger logger = 
LoggerFactory.getLogger(LogbackLoggingSupport.class);
+ 
+     @Override
+     public void onStartup()
+     {
+         // The default logback configuration in conf/logback.xml allows 
reloading the
+         // configuration when the configuration file has changed (every 60 
seconds by default).
+         // This requires logback to use file I/O APIs. But file I/O is not 
allowed from UDFs.
+         // I.e. if logback decides to check for a modification of the config 
file while
+         // executing a sandbox thread, the UDF execution and therefore the 
whole request
+         // execution will fail with an AccessControlException.
+         // To work around this, a custom ReconfigureOnChangeFilter is 
installed, that simply
+         // prevents this configuration file check and possible reload of the 
configuration,
+         // while executing sandboxed UDF code.
++        //
++        // NOTE: this is obsolte with logback versions (at least since 1.2.3)
+         Logger logbackLogger = (Logger) 
LoggerFactory.getLogger(ThreadAwareSecurityManager.class);
+         LoggerContext ctx = logbackLogger.getLoggerContext();
+ 
+         TurboFilterList turboFilterList = ctx.getTurboFilterList();
+         for (int i = 0; i < turboFilterList.size(); i++)
+         {
+             TurboFilter turboFilter = turboFilterList.get(i);
+             if (turboFilter instanceof ReconfigureOnChangeFilter)
+             {
+                 ReconfigureOnChangeFilter reconfigureOnChangeFilter = 
(ReconfigureOnChangeFilter) turboFilter;
+                 turboFilterList.set(i, new 
SMAwareReconfigureOnChangeFilter(reconfigureOnChangeFilter));
+                 break;
+             }
+         }
+     }
+ 
+     @Override
+     public void onShutdown()
+     {
+         DelayingShutdownHook logbackHook = new DelayingShutdownHook();
+         logbackHook.setContext((LoggerContext) 
LoggerFactory.getILoggerFactory());
+         logbackHook.run();
+     }
+ 
+     @Override
+     public void setLoggingLevel(String classQualifier, String rawLevel) 
throws Exception
+     {
+         Logger logBackLogger = (Logger) 
LoggerFactory.getLogger(classQualifier);
+ 
+         // if both classQualifier and rawLevel are empty, reload from 
configuration
+         if (StringUtils.isBlank(classQualifier) && 
StringUtils.isBlank(rawLevel))
+         {
+             JMXConfiguratorMBean jmxConfiguratorMBean = 
JMX.newMBeanProxy(ManagementFactory.getPlatformMBeanServer(),
+                                                                           new 
ObjectName("ch.qos.logback.classic:Name=default,Type=ch.qos.logback.classic.jmx.JMXConfigurator"),
+                                                                           
JMXConfiguratorMBean.class);
+             jmxConfiguratorMBean.reloadDefaultConfiguration();
+             return;
+         }
+         // classQualifier is set, but blank level given
+         else if (StringUtils.isNotBlank(classQualifier) && 
StringUtils.isBlank(rawLevel))
+         {
+             if (logBackLogger.getLevel() != null || 
hasAppenders(logBackLogger))
+                 logBackLogger.setLevel(null);
+             return;
+         }
+ 
+         Level level = Level.toLevel(rawLevel);
+         logBackLogger.setLevel(level);
+         logger.info("set log level to {} for classes under '{}' (if the level 
doesn't look like '{}' then the logger couldn't parse '{}')", level, 
classQualifier, rawLevel, rawLevel);
+     }
+ 
+     @Override
+     public Map<String, String> getLoggingLevels()
+     {
+         Map<String, String> logLevelMaps = Maps.newLinkedHashMap();
+         LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
+         for (Logger logBackLogger : lc.getLoggerList())
+         {
+             if (logBackLogger.getLevel() != null || 
hasAppenders(logBackLogger))
+                 logLevelMaps.put(logBackLogger.getName(), 
logBackLogger.getLevel().toString());
+         }
+         return logLevelMaps;
+     }
+ 
+     private boolean hasAppenders(Logger logBackLogger)
+     {
+         Iterator<Appender<ILoggingEvent>> it = 
logBackLogger.iteratorForAppenders();
+         return it.hasNext();
+     }
+ 
+     /**
+      * The purpose of this class is to prevent logback from checking for 
config file change,
+      * if the current thread is executing a sandboxed thread to avoid {@link 
AccessControlException}s.
++     *
++     * This is obsolete with logback versions that replaced {@link 
ReconfigureOnChangeFilter}
++     * with {@link ch.qos.logback.classic.joran.ReconfigureOnChangeTask} (at 
least logback since 1.2.3).
+      */
+     private static class SMAwareReconfigureOnChangeFilter extends 
ReconfigureOnChangeFilter
+     {
+         SMAwareReconfigureOnChangeFilter(ReconfigureOnChangeFilter 
reconfigureOnChangeFilter)
+         {
+             setRefreshPeriod(reconfigureOnChangeFilter.getRefreshPeriod());
+             setName(reconfigureOnChangeFilter.getName());
+             setContext(reconfigureOnChangeFilter.getContext());
+             if (reconfigureOnChangeFilter.isStarted())
+             {
+                 reconfigureOnChangeFilter.stop();
+                 start();
+             }
+         }
+ 
+         protected boolean changeDetected(long now)
+         {
+             if (ThreadAwareSecurityManager.isSecuredThread())
+                 return false;
+             return super.changeDetected(now);
+         }
+     }
+ }

http://git-wip-us.apache.org/repos/asf/cassandra/blob/2ad06d65/src/java/org/apache/cassandra/utils/logging/LoggingSupportFactory.java
----------------------------------------------------------------------
diff --cc src/java/org/apache/cassandra/utils/logging/LoggingSupportFactory.java
index 0000000,3e7adab..575caca
mode 000000,100644..100644
--- a/src/java/org/apache/cassandra/utils/logging/LoggingSupportFactory.java
+++ b/src/java/org/apache/cassandra/utils/logging/LoggingSupportFactory.java
@@@ -1,0 -1,42 +1,42 @@@
+ package org.apache.cassandra.utils.logging;
+ 
+ import org.slf4j.Logger;
+ import org.slf4j.LoggerFactory;
+ 
+ import org.apache.cassandra.utils.FBUtilities;
+ 
+ /**
+  * Dynamically loads and instantiates an appropriate {@link LoggingSupport} 
implementation according to the used slf4j binding.
+  * For production use, this should always be {@link LogbackLoggingSupport}.
+  */
+ public class LoggingSupportFactory
+ {
+     private static final Logger logger = 
LoggerFactory.getLogger(LoggingSupportFactory.class);
+ 
+     private static volatile LoggingSupport loggingSupport;
+ 
+     private LoggingSupportFactory() {}
+ 
+     /**
+      * @return An appropriate {@link LoggingSupport} implementation according 
to the used slf4j binding.
+      */
+     public static LoggingSupport getLoggingSupport()
+     {
+         if (loggingSupport == null)
+         {
+             // unfortunately, this is the best way to determine if logback is 
being used for logger
+             String loggerFactoryClass = 
LoggerFactory.getILoggerFactory().getClass().getName();
+             if (loggerFactoryClass.contains("logback"))
+             {
+                 loggingSupport = 
FBUtilities.instanceOrConstruct("org.apache.cassandra.utils.logging.LogbackLoggingSupport",
 "LogbackLoggingSupport");
+             }
+             else
+             {
+                 loggingSupport = new NoOpFallbackLoggingSupport();
+                 logger.warn("You are using Cassandra with an unsupported 
deployment. The intended logging implementation library logback is not used by 
slf4j. Detected slf4j logger factory: {}. "
 -                        + "You will not be able to dynamically manage log 
levels via JMX and may have performance or other issues.", loggerFactoryClass);
++                            + "You will not be able to dynamically manage log 
levels via JMX and may have performance or other issues.", loggerFactoryClass);
+             }
+         }
+         return loggingSupport;
+     }
+ }

http://git-wip-us.apache.org/repos/asf/cassandra/blob/2ad06d65/test/unit/org/apache/cassandra/cql3/CQLTester.java
----------------------------------------------------------------------
diff --cc test/unit/org/apache/cassandra/cql3/CQLTester.java
index 69d2fb5,192cbbc..dacb37c
--- a/test/unit/org/apache/cassandra/cql3/CQLTester.java
+++ b/test/unit/org/apache/cassandra/cql3/CQLTester.java
@@@ -46,13 -43,11 +46,12 @@@ import com.datastax.driver.core.ResultS
  
  import org.apache.cassandra.SchemaLoader;
  import org.apache.cassandra.concurrent.ScheduledExecutors;
 -import org.apache.cassandra.config.CFMetaData;
 +import org.apache.cassandra.index.SecondaryIndexManager;
 +import org.apache.cassandra.config.EncryptionOptions;
 +import org.apache.cassandra.locator.InetAddressAndPort;
 +import org.apache.cassandra.schema.*;
  import org.apache.cassandra.config.DatabaseDescriptor;
 -import org.apache.cassandra.config.Schema;
 -import org.apache.cassandra.config.SchemaConstants;
  import org.apache.cassandra.cql3.functions.FunctionName;
- import org.apache.cassandra.cql3.functions.ThreadAwareSecurityManager;
  import org.apache.cassandra.cql3.statements.ParsedStatement;
  import org.apache.cassandra.db.*;
  import org.apache.cassandra.db.commitlog.CommitLog;


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@cassandra.apache.org
For additional commands, e-mail: commits-h...@cassandra.apache.org

Reply via email to