make FieldMetaData thread-safe

Summary:
Every once in a while during startup, our server encountercs a synchronization bug in the static initialization of thrift structs. I debugged this by taking a jstack of the hanging server, a large number of threads were blocked on deserializing the thrift request:
"pool-4-thread-307" prio=10 tid=0x00007eec200b3800 nid=0x1ff6 in Object.wait() [0x000000006f854000]
java.lang.Thread.State: RUNNABLE
at com.facebook.titan.prometheus.app.TitanMessagingService$deliverLogMessage_args.read(TitanMessagingService.java:20642)
at com.facebook.titan.prometheus.app.TitanMessagingService$Processor$deliverLogMessage.process(TitanMessagingService.java:6089)
at com.facebook.titan.prometheus.app.TitanMessagingService$Processor.process(TitanMessagingService.java:5443)
at com.facebook.titan.prometheus.app.TitanServer$TitanProcessor.process(TitanServer.java:64)
at com.facebook.thrift.direct_server.FramedTransportChannelHandler.transition(FramedTransportChannelHandler.java:197)
at com.facebook.thrift.direct_server.DirectServerTask.run(DirectServerTask.java:43)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
at java.lang.Thread.run(Thread.java:722)

Looking at TitanMessagingService.java:20642 I determined the exact line these threads were blocking on is this:
this.req = new MessagingDeliverLogMessageReq();

Thoroughly confused until I found this in the jstack:
"pool-4-thread-306" prio=10 tid=0x00007eec200b2800 nid=0x1ff5 runnable [0x000000006f752000]
java.lang.Thread.State: RUNNABLE
at java.util.HashMap.put(HashMap.java:401)
at com.facebook.thrift.meta_data.FieldMetaData.addStructMetaDataMap(FieldMetaData.java:48)
at com.facebook.titan.prometheus.app.MessagingDeliverLogMessageReq.<clinit>(MessagingDeliverLogMessageReq.java:85)
at com.facebook.titan.prometheus.app.TitanMessagingService$deliverLogMessage_args.read(TitanMessagingService.java:20642)
at com.facebook.titan.prometheus.app.TitanMessagingService$Processor$deliverLogMessage.process(TitanMessagingService.java:6089)
at com.facebook.titan.prometheus.app.TitanMessagingService$Processor.process(TitanMessagingService.java:5443)
at com.facebook.titan.prometheus.app.TitanServer$TitanProcessor.process(TitanServer.java:64)
at com.facebook.thrift.direct_server.FramedTransportChannelHandler.transition(FramedTransportChannelHandler.java:197)
at com.facebook.thrift.direct_server.DirectServerTask.run(DirectServerTask.java:43)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
at java.lang.Thread.run(Thread.java:722)

Test Plan: Review.

Reviewed By: andrewcox@fb.com

FB internal diff: D1186708
Revert "make FieldMetaData thread-safe"

Summary: This reverts commit bc2705f7b3d3507f9b563e88fd826e2bb178dd85. It broke
a bunch of builds.

Test Plan: built hhvm

Reviewed By: ryandm@fb.com

Blame Rev:
make FieldMetaData thread-safe (now for Java 6!)

Summary:
You mean everyone's not on Java 7 yet??

(Sorry ... I should've seen that coming.)

Test Plan: Compiles. Also does not use the Java 7 diamond.

Reviewed By: jsailor@fb.com

FB internal diff: D1187309
migrate Executor to wangle

Summary:
This defines a new (more modern) API in wangle by making `concurrency::Executor` inherit from `wangle::Executor`. So all FB code that is using wangle threadgates etc with a `concurrency::Executor` should continue to work unmodified. Later let's move all the general executors that we think are generally useful (and don't depend on FB code) to folly and leave the rest in concurrency::Executor, eventually reworked to be a direct implementation of the folly Executor instead of the old-style concurrency::Executor

This is under the wangle namespace for now, but with a little more migration/polish/etc will probably eventually deserve to live top-level in folly, like MoveWrapper does.

@override-unit-failures
I verified those failures aren't caused by me.

Test Plan:
wangle still builds and unit tests run.
Make sure contbuild'd tests all pass.

Reviewed By: hannesr@fb.com

FB internal diff: D1185591
Helper to make copying RequestContext easier

Summary:
Hoping that this helper to copy RequestContext will make it easier
and encourage folks to use it

Test Plan: Implemented in Scuba and ued

Reviewed By: davejwatson@fb.com

FB internal diff: D1186462
More constructors!

Summary:
We need more constructors for TDirectServers for an extra
runnable.

Test Plan: Broken down D1175424 into this thrift component and the rest.

Reviewed By: alandau@fb.com

FB internal diff: D1186726
Added packed attribute for frozen structs

Test Plan: fbconfig common/datastruct/counter/time_window/test:distinct_counter_naive_test && fbmake runtests

Reviewed By: davejwatson@fb.com

FB internal diff: D1185791
eliminate warnings in generated java code

Summary:
eliminate most (all?) warnings in generated java code;
specifically, unused/unchecked/serial warnings.

Test Plan:
used this to process all thrift files used by prometheus.
There were no warnings in generated code.

Reviewed By: davejwatson@fb.com

FB internal diff: D1183941
rename TThreadPoolServer.ThreadFactoryImpl to TThreadFactoryImpl

Summary:
TThreadPoolServer is deprecated; ThreadFactoryImpl is useful
(and used) elsewhere. Separate them.

Test Plan:
1. `fbgs ThreadFactoryImpl` to make sure all references were in thrift/lib/java or prometheus

2. `fbconfig -r thrift && fbmake dev && fbmake runtests`

3. Prometheus compiles in eclipse

Reviewed By: andrewcox@fb.com

FB internal diff: D1184082
Move wangle to folly

Summary:
* git mv
* codemod facebook::wangle folly::wangle
* Change 'runnable' to be a base class in wangle instead of thrift

Justification:
* std::future doesn't have then, whenall, etc.
* boost::future doesn't support executors

@override-unit-failures

Test Plan: contbuild and pray

Reviewed By: hans@fb.com

FB internal diff: D1185194
extern template

Summary:
For cpp2 only - instead of including .tcc files in .h files, explicitly instantiate them with all known protocols.
This means they should only be compiled once, instead of multiple times when they are included in .h files.

Test Plan:
fbconfig -r thrift
fbmake dbg

contbuild will probably find some other build breaks we'll have to fix up

Note there is a bunch of dependant diffs that need landing first (D1162477, D1160803, D1162491, D1162484)

Reviewed By: alandau@fb.com

FB internal diff: D1162506
Guarantee structural id is only 63 bits at most

Summary: We ran into structural ids that were too large for hhvm (which is 64 bits signed).

Test Plan: fbmake, regenerate thrift, confirm ids change

Reviewed By: alandau@fb.com

FB internal diff: D1190098
Fix underflow in Neutronium encoder

Summary:
If the field is not fixed, -1 underflows because the ternary expression gets its
type from the uint32_t field.fixedStringSize

Not sure if the preferable fix is to change all those literals to ##-1L##

Test Plan: no longer saw underflow when using Neutronium, see D1190014

Reviewed By: tudorb@fb.com

FB internal diff: D1190024
more logging for taskKilled

Summary: Trying to track down several servers that are showing taskKilled, but it's not clear why.  Adds more logging

@override-unit-failures

Test Plan: it compiles

Reviewed By: haijunz@fb.com

FB internal diff: D1192995
make sure channelClosed is never called with nullptr

Summary: Added more logging in D1192995, but sometimes channelClosed is called with nullptr, and logging crashes.  doh

Test Plan:
fbconfig -r thrift/lib/cpp2; fbmake runtests
fbgs channelClosed(nullptr)

@override-unit-failures

Reviewed By: praveenr@fb.com

FB internal diff: D1194343
Use the credentials cache manager in the SASL implementation

Summary:
This starts using the credentials cache manger. Note that all the inline kInit calls are going away since I'm assuming that the manager will take care of renewing credentials when needed.

Note that I'm also assuming that once we start refreshing credentials, the refresh will finish in time before the currently used in-memory cache expires.

Test Plan: Started up the crypto service, ran loadgen.

Reviewed By: mhorowitz@fb.com

FB internal diff: D1190033
Smooth out cache renewal times

Summary: This essentially randomizes cache renewal times across hosts. The renew interval is between 50% and 75% of the lifetime. I hash the client principal and distribute renewal times uniformly across that interval based on the hash.

Test Plan: cout the values

Reviewed By: mhorowitz@fb.com

FB internal diff: D1190515
Revert build breaks

Summary:
Revert "[ThriftAuth] Smooth out cache renewal times"

This reverts commit 0d1354dbad7efc59a776280472af80820cb1ac80.

Revert "[ThriftAuth] Use the credentials cache manager in the SASL implementation"

This reverts commit 06cff422a392b19e1d304e175ed1444a464a99bb.

Test Plan: None

This is a revert:
@override-unit-failures

Reviewed By: rodrigos@fb.com

FB internal diff: D1195092