From 184d881b21f8bac56e81d9ad0ba4da61de4c0c6f Mon Sep 17 00:00:00 2001 From: Soheil Hassas Yeganeh Date: Sun, 22 Sep 2019 01:36:54 -0400 Subject: [PATCH 01/60] Avoid creating and copying strings when Status is OK in FinishOp. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ``` BM_PumpStreamClientToServer/0 [polls/iter:0 ] 1.22µs ± 1% 1.21µs ± 2% -0.73% (p=0.002 n=19+19) BM_PumpStreamClientToServer/8 [polls/iter:0 ] 1.33µs ± 1% 1.33µs ± 1% -0.71% (p=0.000 n=18+18) BM_PumpStreamClientToServer/134217728 [polls/iter:0 ] 161ms ± 1% 160ms ± 1% -0.67% (p=0.002 n=16+20) BM_PumpStreamServerToClient/0 [polls/iter:0 ] 1.22µs ± 1% 1.21µs ± 1% -1.51% (p=0.000 n=18+18) BM_PumpStreamServerToClient/1 [polls/iter:0 ] 1.32µs ± 1% 1.31µs ± 1% -0.81% (p=0.000 n=16+20) BM_PumpStreamServerToClient/8 [polls/iter:0 ] 1.33µs ± 1% 1.32µs ± 1% -0.97% (p=0.000 n=17+20) BM_PumpStreamServerToClient/64 [polls/iter:0 ] 1.36µs ± 1% 1.36µs ± 1% -0.43% (p=0.020 n=17+20) BM_PumpStreamServerToClient/32768 [polls/iter:0 ] 10.9µs ± 2% 10.8µs ± 2% -0.71% (p=0.022 n=18+20) BM_PumpStreamClientToServer/0 [polls/iter:0 ] 1.21µs ± 1% 1.20µs ± 1% -0.89% (p=0.000 n=18+19) BM_PumpStreamServerToClient/0 [polls/iter:0 ] 1.22µs ± 1% 1.20µs ± 1% -1.40% (p=0.000 n=18+19) BM_UnaryPingPong/0/0 [polls/iter:0 ] 6.48µs ± 5% 6.25µs ± 4% -3.45% (p=0.000 n=20+17) BM_UnaryPingPong/1/0 [polls/iter:0 ] 6.60µs ± 6% 6.36µs ± 2% -3.66% (p=0.000 n=20+18) BM_UnaryPingPong/0/1 [polls/iter:0 ] 6.61µs ± 7% 6.37µs ± 3% -3.59% (p=0.000 n=20+17) BM_UnaryPingPong/1/1 [polls/iter:0 ] 6.65µs ± 6% 6.48µs ± 3% -2.57% (p=0.000 n=20+18) BM_UnaryPingPong/0/8 [polls/iter:0 ] 6.56µs ± 5% 6.35µs ± 3% -3.29% (p=0.000 n=20+18) BM_UnaryPingPong/8/8 [polls/iter:0 ] 6.64µs ± 6% 6.55µs ± 5% -1.43% (p=0.050 n=19+19) BM_UnaryPingPong/0/64 [polls/iter:0 ] 6.64µs ± 6% 6.50µs ± 4% -2.10% (p=0.030 n=20+19) BM_UnaryPingPong/64/64 [polls/iter:0 ] 6.72µs ± 4% 6.56µs ± 1% -2.34% (p=0.000 n=18+16) BM_UnaryPingPong/512/0 [polls/iter:0 ] 6.69µs ± 2% 6.55µs ± 2% -2.12% (p=0.000 n=17+18) BM_UnaryPingPong/0/512 [polls/iter:0 ] 6.71µs ± 2% 6.55µs ± 2% -2.39% (p=0.000 n=17+17) BM_UnaryPingPong/512/512 [polls/iter:0 ] 6.97µs ± 3% 6.82µs ± 1% -2.16% (p=0.000 n=18+16) BM_UnaryPingPong/4096/0 [polls/iter:0 ] 7.74µs ± 1% 7.60µs ± 1% -1.81% (p=0.000 n=20+16) BM_UnaryPingPong/0/4096 [polls/iter:0 ] 7.77µs ± 2% 7.63µs ± 2% -1.74% (p=0.000 n=18+19) BM_UnaryPingPong/4096/4096 [polls/iter:0 ] 8.98µs ± 1% 8.92µs ± 2% -0.61% (p=0.028 n=20+19) BM_UnaryPingPong/32768/0 [polls/iter:0 ] 15.9µs ± 1% 15.8µs ± 0% -0.80% (p=0.000 n=19+15) BM_UnaryPingPong/0/32768 [polls/iter:0 ] 16.3µs ± 1% 16.2µs ± 2% -0.77% (p=0.005 n=20+19) BM_UnaryPingPong/262144/0 [polls/iter:0 ] 86.2µs ± 1% 86.1µs ± 0% -0.18% (p=0.036 n=19+15) BM_UnaryPingPong/0/0 [polls/iter:0 ] 6.44µs ± 6% 6.28µs ± 6% -2.50% (p=0.044 n=20+19) BM_UnaryPingPong/1/0 [polls/iter:0 ] 6.62µs ± 5% 6.39µs ± 5% -3.50% (p=0.008 n=20+19) BM_UnaryPingPong/1/1 [polls/iter:0 ] 6.57µs ± 7% 6.39µs ± 4% -2.71% (p=0.001 n=20+16) BM_UnaryPingPong/64/0 [polls/iter:0 ] 6.41µs ± 2% 6.35µs ± 6% -0.84% (p=0.001 n=18+17) BM_UnaryPingPong/512/0 [polls/iter:0 ] 6.60µs ± 3% 6.51µs ± 4% -1.33% (p=0.002 n=18+18) BM_UnaryPingPong/0/512 [polls/iter:0 ] 6.62µs ± 2% 6.47µs ± 1% -2.25% (p=0.000 n=17+17) BM_UnaryPingPong/512/512 [polls/iter:0 ] 6.87µs ± 1% 6.76µs ± 1% -1.54% (p=0.000 n=18+17) BM_UnaryPingPong/4096/0 [polls/iter:0 ] 7.65µs ± 2% 7.59µs ± 3% -0.82% (p=0.006 n=18+18) BM_UnaryPingPong/0/4096 [polls/iter:0 ] 7.66µs ± 1% 7.54µs ± 2% -1.52% (p=0.000 n=18+19) BM_UnaryPingPong/4096/4096 [polls/iter:0 ] 8.91µs ± 2% 8.80µs ± 1% -1.20% (p=0.000 n=18+18) BM_UnaryPingPong/32768/0 [polls/iter:0 ] 15.8µs ± 0% 15.7µs ± 0% -0.80% (p=0.000 n=17+16) BM_UnaryPingPong/0/32768 [polls/iter:0 ] 16.3µs ± 2% 16.1µs ± 1% -1.21% (p=0.000 n=20+19) BM_UnaryPingPong/32768/32768 [polls/iter:0 ] 25.6µs ± 2% 25.4µs ± 1% -0.66% (p=0.002 n=19+18) BM_UnaryPingPong, 1>, NoOpMutator>/0/0 [polls/iter:0 ] 7.16µs ± 5% 7.05µs ± 2% -1.45% (p=0.012 n=19+19) BM_UnaryPingPong, 1>, NoOpMutator>/0/0 [polls/iter:0 ] 7.29µs ± 5% 7.12µs ± 2% -2.43% (p=0.001 n=20+19) BM_UnaryPingPong, 2>, NoOpMutator>/0/0 [polls/iter:0 ] 7.66µs ± 3% 7.56µs ± 2% -1.28% (p=0.001 n=17+17) BM_UnaryPingPong, 2>, NoOpMutator>/0/0 [polls/iter:0 ] 7.83µs ± 3% 7.70µs ± 2% -1.60% (p=0.000 n=18+19) BM_UnaryPingPong, 2>, NoOpMutator>/0/0 [polls/iter:0 ] 7.96µs ± 2% 7.83µs ± 2% -1.54% (p=0.000 n=17+19) BM_UnaryPingPong, 1>>/0/0 [polls/iter:0 ] 7.13µs ± 5% 6.93µs ± 2% -2.73% (p=0.000 n=20+19) BM_UnaryPingPong, 1>>/0/0 [polls/iter:0 ] 7.14µs ± 2% 7.01µs ± 2% -1.88% (p=0.000 n=17+19) BM_UnaryPingPong, 1>>/0/0 [polls/iter:0 ] 7.24µs ± 2% 7.09µs ± 2% -2.17% (p=0.000 n=18+20) BM_UnaryPingPong, 1>, NoOpMutator>/0/0 [polls/iter:0 ] 6.96µs ± 1% 6.93µs ± 2% -0.53% (p=0.004 n=17+18) BM_UnaryPingPong, 1>, NoOpMutator>/0/0 [polls/iter:0 ] 7.08µs ± 2% 6.99µs ± 1% -1.32% (p=0.000 n=17+19) BM_UnaryPingPong, 1>, NoOpMutator>/0/0 [polls/iter:0 ] 7.26µs ± 3% 7.19µs ± 1% -1.01% (p=0.000 n=17+20) BM_UnaryPingPong, 1>>/0/0 [polls/iter:0 ] 7.09µs ± 4% 6.89µs ± 1% -2.84% (p=0.000 n=19+19) BM_UnaryPingPong, 1>>/0/0 [polls/iter:0 ] 7.14µs ± 2% 7.05µs ± 2% -1.39% (p=0.000 n=16+19) BM_UnaryPingPong, 1>>/0/0 [polls/iter:0 ] 7.37µs ± 4% 7.18µs ± 1% -2.62% (p=0.000 n=18+18) BM_UnaryPingPong/0/0 [polls/iter:3.00009 ] 23.6µs ± 0% 23.5µs ± 0% -0.47% (p=0.024 n=6+3) BM_UnaryPingPong/0/0 [polls/iter:3.00012 ] 20.7µs ± 1% 20.4µs ± 0% -1.50% (p=0.029 n=4+4) BM_UnaryPingPong/0/0 [polls/iter:3.00017 ] 19.9µs ± 1% 19.7µs ± 1% -1.22% (p=0.029 n=4+4) BM_StreamingPingPong/1/2 [polls/iter:12.0001 ] 62.2µs ± 2% 61.2µs ± 1% -1.54% (p=0.029 n=9+5) BM_StreamingPingPong/64/2 [polls/iter:12.0001 ] 64.6µs ± 1% 63.1µs ± 0% -2.28% (p=0.003 n=7+5) BM_StreamingPingPong/0/0 [polls/iter:0 ] 5.71µs ± 1% 5.65µs ± 1% -1.00% (p=0.000 n=19+18) BM_StreamingPingPong/0/1 [polls/iter:0 ] 8.46µs ± 1% 8.39µs ± 1% -0.82% (p=0.000 n=19+19) BM_StreamingPingPong/0/2 [polls/iter:0 ] 11.1µs ± 1% 11.0µs ± 1% -0.42% (p=0.013 n=20+20) BM_StreamingPingPong/1/1 [polls/iter:0 ] 8.72µs ± 1% 8.66µs ± 1% -0.80% (p=0.000 n=20+20) BM_StreamingPingPong/1/2 [polls/iter:0 ] 11.6µs ± 1% 11.5µs ± 1% -0.37% (p=0.012 n=20+20) BM_StreamingPingPong/8/1 [polls/iter:0 ] 8.72µs ± 1% 8.66µs ± 1% -0.64% (p=0.000 n=19+20) BM_StreamingPingPong/64/1 [polls/iter:0 ] 8.86µs ± 1% 8.82µs ± 1% -0.47% (p=0.000 n=20+20) BM_StreamingPingPong/64/2 [polls/iter:0 ] 11.8µs ± 1% 11.7µs ± 1% -0.49% (p=0.000 n=19+20) BM_StreamingPingPong/512/1 [polls/iter:0 ] 9.14µs ± 1% 9.08µs ± 0% -0.65% (p=0.000 n=20+16) BM_StreamingPingPong/512/2 [polls/iter:0 ] 12.3µs ± 0% 12.3µs ± 1% -0.43% (p=0.000 n=19+19) BM_StreamingPingPong/4096/1 [polls/iter:0 ] 11.2µs ± 1% 11.1µs ± 1% -0.60% (p=0.000 n=19+20) BM_StreamingPingPong/262144/1 [polls/iter:0 ] 169µs ± 1% 171µs ± 2% +0.98% (p=0.000 n=20+19) BM_StreamingPingPong/262144/2 [polls/iter:0 ] 329µs ± 1% 331µs ± 2% +0.66% (p=0.007 n=18+19) BM_StreamingPingPong/2097152/1 [polls/iter:0 ] 2.08ms ±10% 2.14ms ± 1% +3.13% (p=0.043 n=20+15) BM_StreamingPingPongMsgs/8 [polls/iter:4.00007 ] 16.4µs ± 2% 16.1µs ± 0% -2.00% (p=0.036 n=5+3) BM_StreamingPingPongMsgs/0 [polls/iter:0 ] 2.45µs ± 1% 2.44µs ± 1% -0.60% (p=0.006 n=20+20) BM_StreamingPingPongMsgs/1 [polls/iter:0 ] 2.65µs ± 1% 2.67µs ± 1% +0.75% (p=0.000 n=20+20) BM_StreamingPingPongMsgs/8 [polls/iter:0 ] 2.65µs ± 1% 2.67µs ± 1% +0.85% (p=0.000 n=20+20) BM_StreamingPingPongMsgs/512 [polls/iter:0 ] 2.96µs ± 1% 2.98µs ± 1% +0.52% (p=0.009 n=20+20) BM_StreamingPingPongMsgs/4096 [polls/iter:0 ] 4.83µs ± 2% 4.88µs ± 4% +1.19% (p=0.005 n=19+20) BM_StreamingPingPong/512/2 [polls/iter:12.0001 ] 64.2µs ± 1% 63.4µs ± 1% -1.36% (p=0.017 n=5+6) BM_StreamingPingPong/0/0 [polls/iter:0 ] 5.71µs ± 1% 5.63µs ± 1% -1.51% (p=0.000 n=18+20) BM_StreamingPingPong/0/1 [polls/iter:0 ] 8.43µs ± 1% 8.34µs ± 1% -1.10% (p=0.000 n=20+20) BM_StreamingPingPong/0/2 [polls/iter:0 ] 11.0µs ± 1% 11.0µs ± 0% -0.57% (p=0.000 n=19+15) BM_StreamingPingPong/1/1 [polls/iter:0 ] 8.68µs ± 1% 8.59µs ± 1% -1.07% (p=0.000 n=17+20) BM_StreamingPingPong/1/2 [polls/iter:0 ] 11.5µs ± 1% 11.4µs ± 1% -0.34% (p=0.002 n=19+19) BM_StreamingPingPong/8/1 [polls/iter:0 ] 8.71µs ± 1% 8.59µs ± 1% -1.47% (p=0.000 n=20+18) BM_StreamingPingPong/64/1 [polls/iter:0 ] 8.82µs ± 1% 8.76µs ± 1% -0.75% (p=0.000 n=20+20) BM_StreamingPingPong/64/2 [polls/iter:0 ] 11.7µs ± 1% 11.7µs ± 1% -0.48% (p=0.000 n=20+20) BM_StreamingPingPong/512/1 [polls/iter:0 ] 9.13µs ± 1% 9.04µs ± 1% -0.96% (p=0.000 n=20+20) BM_StreamingPingPong/4096/1 [polls/iter:0 ] 11.1µs ± 1% 11.0µs ± 1% -0.67% (p=0.002 n=19+20) BM_StreamingPingPong/32768/1 [polls/iter:0 ] 28.1µs ± 1% 28.0µs ± 1% -0.54% (p=0.016 n=19+18) BM_StreamingPingPong/16777216/2 [polls/iter:0 ] 64.1ms ± 5% 65.2ms ± 4% +1.66% (p=0.020 n=19+19) BM_StreamingPingPongMsgs/0 [polls/iter:0 ] 2.43µs ± 1% 2.42µs ± 1% -0.50% (p=0.000 n=19+18) BM_StreamingPingPongMsgs/1 [polls/iter:0 ] 2.62µs ± 1% 2.64µs ± 0% +0.55% (p=0.000 n=20+18) BM_StreamingPingPongMsgs/8 [polls/iter:0 ] 2.62µs ± 1% 2.64µs ± 1% +0.64% (p=0.000 n=20+19) BM_StreamingPingPongMsgs/64 [polls/iter:0 ] 2.71µs ± 1% 2.71µs ± 1% -0.32% (p=0.015 n=19+19) BM_StreamingPingPongMsgs/512 [polls/iter:0 ] 2.94µs ± 1% 2.95µs ± 1% +0.32% (p=0.024 n=20+19) BM_StreamingPingPongWithCoalescingApi/134217728/1/0 [polls/iter:5.75 writes/iter:10 ] 419ms ± 0% 417ms ± 1% -0.55% (p=0.030 n=5+7) BM_StreamingPingPongWithCoalescingApi/0/0/0 [polls/iter:0 ] 5.36µs ± 1% 5.27µs ± 1% -1.80% (p=0.000 n=20+20) BM_StreamingPingPongWithCoalescingApi/0/0/1 [polls/iter:0 ] 5.36µs ± 1% 5.28µs ± 1% -1.51% (p=0.000 n=20+20) BM_StreamingPingPongWithCoalescingApi/0/1/0 [polls/iter:0 ] 7.65µs ± 1% 7.59µs ± 1% -0.76% (p=0.000 n=17+20) BM_StreamingPingPongWithCoalescingApi/0/2/0 [polls/iter:0 ] 10.4µs ± 1% 10.3µs ± 1% -0.44% (p=0.021 n=20+20) BM_StreamingPingPongWithCoalescingApi/0/1/1 [polls/iter:0 ] 7.22µs ± 2% 7.12µs ± 1% -1.36% (p=0.000 n=18+18) BM_StreamingPingPongWithCoalescingApi/1/1/0 [polls/iter:0 ] 7.91µs ± 1% 7.84µs ± 1% -0.96% (p=0.000 n=20+20) BM_StreamingPingPongWithCoalescingApi/1/2/0 [polls/iter:0 ] 10.8µs ± 1% 10.8µs ± 1% -0.44% (p=0.008 n=20+20) BM_StreamingPingPongWithCoalescingApi/1/1/1 [polls/iter:0 ] 7.48µs ± 2% 7.36µs ± 1% -1.65% (p=0.000 n=18+18) BM_StreamingPingPongWithCoalescingApi/1/2/1 [polls/iter:0 ] 10.4µs ± 1% 10.3µs ± 1% -0.50% (p=0.000 n=20+20) BM_StreamingPingPongWithCoalescingApi/8/1/0 [polls/iter:0 ] 7.89µs ± 1% 7.84µs ± 1% -0.58% (p=0.000 n=19+19) BM_StreamingPingPongWithCoalescingApi/8/1/1 [polls/iter:0 ] 7.47µs ± 1% 7.40µs ± 1% -0.94% (p=0.000 n=18+18) BM_StreamingPingPongWithCoalescingApi/64/2/0 [polls/iter:0 ] 11.0µs ± 1% 10.9µs ± 1% -0.31% (p=0.034 n=19+19) BM_StreamingPingPongWithCoalescingApi/64/1/1 [polls/iter:0 ] 7.77µs ± 7% 7.49µs ± 1% -3.67% (p=0.000 n=20+19) BM_StreamingPingPongWithCoalescingApi/64/2/1 [polls/iter:0 ] 10.6µs ± 1% 10.6µs ± 1% -0.45% (p=0.001 n=19+19) BM_StreamingPingPongWithCoalescingApi/512/1/0 [polls/iter:0 ] 8.30µs ± 1% 8.26µs ± 1% -0.50% (p=0.002 n=19+18) BM_StreamingPingPongWithCoalescingApi/512/1/1 [polls/iter:0 ] 7.87µs ± 1% 7.76µs ± 1% -1.36% (p=0.000 n=19+18) BM_StreamingPingPongWithCoalescingApi/512/2/1 [polls/iter:0 ] 11.1µs ± 1% 11.1µs ± 1% -0.38% (p=0.013 n=20+20) BM_StreamingPingPongWithCoalescingApi/4096/1/0 [polls/iter:0 ] 10.4µs ± 2% 10.3µs ± 2% -0.85% (p=0.009 n=20+19) BM_StreamingPingPongWithCoalescingApi/4096/2/0 [polls/iter:0 ] 15.5µs ± 2% 15.4µs ± 2% -0.65% (p=0.033 n=20+20) BM_StreamingPingPongWithCoalescingApi/4096/1/1 [polls/iter:0 ] 10.0µs ± 1% 9.8µs ± 2% -1.54% (p=0.000 n=20+19) BM_StreamingPingPongWithCoalescingApi/4096/2/1 [polls/iter:0 ] 15.1µs ± 2% 15.0µs ± 2% -0.56% (p=0.049 n=20+20) BM_StreamingPingPongWithCoalescingApi/0/0/0 [polls/iter:0 ] 5.27µs ± 1% 5.18µs ± 1% -1.64% (p=0.000 n=20+20) BM_StreamingPingPongWithCoalescingApi/0/0/1 [polls/iter:0 ] 5.27µs ± 1% 5.19µs ± 1% -1.52% (p=0.000 n=20+20) BM_StreamingPingPongWithCoalescingApi/0/1/0 [polls/iter:0 ] 7.58µs ± 1% 7.49µs ± 1% -1.17% (p=0.000 n=20+20) BM_StreamingPingPongWithCoalescingApi/0/2/0 [polls/iter:0 ] 10.2µs ± 1% 10.1µs ± 1% -0.97% (p=0.000 n=20+20) BM_StreamingPingPongWithCoalescingApi/0/1/1 [polls/iter:0 ] 7.16µs ± 1% 7.11µs ± 3% -0.67% (p=0.011 n=19+20) BM_StreamingPingPongWithCoalescingApi/0/2/1 [polls/iter:0 ] 9.81µs ± 1% 9.76µs ± 1% -0.56% (p=0.001 n=20+20) BM_StreamingPingPongWithCoalescingApi/1/1/0 [polls/iter:0 ] 7.82µs ± 1% 7.72µs ± 1% -1.31% (p=0.000 n=20+20) BM_StreamingPingPongWithCoalescingApi/1/2/0 [polls/iter:0 ] 10.7µs ± 1% 10.6µs ± 1% -0.82% (p=0.000 n=19+19) BM_StreamingPingPongWithCoalescingApi/1/1/1 [polls/iter:0 ] 7.38µs ± 1% 7.28µs ± 1% -1.26% (p=0.000 n=18+20) BM_StreamingPingPongWithCoalescingApi/1/2/1 [polls/iter:0 ] 10.3µs ± 1% 10.2µs ± 1% -0.57% (p=0.000 n=19+20) BM_StreamingPingPongWithCoalescingApi/8/1/0 [polls/iter:0 ] 7.81µs ± 1% 7.74µs ± 1% -0.90% (p=0.000 n=20+20) BM_StreamingPingPongWithCoalescingApi/8/2/0 [polls/iter:0 ] 10.6µs ± 1% 10.6µs ± 1% -0.50% (p=0.001 n=18+20) BM_StreamingPingPongWithCoalescingApi/8/1/1 [polls/iter:0 ] 7.42µs ± 1% 7.32µs ± 1% -1.24% (p=0.000 n=20+20) BM_StreamingPingPongWithCoalescingApi/8/2/1 [polls/iter:0 ] 10.3µs ± 1% 10.2µs ± 1% -0.45% (p=0.002 n=20+20) BM_StreamingPingPongWithCoalescingApi/64/1/0 [polls/iter:0 ] 7.93µs ± 1% 7.84µs ± 0% -1.20% (p=0.000 n=19+18) BM_StreamingPingPongWithCoalescingApi/64/2/0 [polls/iter:0 ] 10.9µs ± 1% 10.8µs ± 1% -0.60% (p=0.000 n=18+20) BM_StreamingPingPongWithCoalescingApi/64/1/1 [polls/iter:0 ] 7.56µs ± 3% 7.43µs ± 1% -1.64% (p=0.000 n=19+20) BM_StreamingPingPongWithCoalescingApi/64/2/1 [polls/iter:0 ] 10.5µs ± 1% 10.5µs ± 1% -0.64% (p=0.000 n=20+19) BM_StreamingPingPongWithCoalescingApi/512/1/0 [polls/iter:0 ] 8.24µs ± 1% 8.14µs ± 1% -1.18% (p=0.000 n=19+20) BM_StreamingPingPongWithCoalescingApi/512/2/0 [polls/iter:0 ] 11.4µs ± 2% 11.4µs ± 1% -0.54% (p=0.003 n=20+20) BM_StreamingPingPongWithCoalescingApi/512/1/1 [polls/iter:0 ] 7.84µs ± 2% 7.73µs ± 1% -1.42% (p=0.000 n=19+20) BM_StreamingPingPongWithCoalescingApi/512/2/1 [polls/iter:0 ] 11.0µs ± 1% 11.0µs ± 1% -0.39% (p=0.004 n=19+20) BM_StreamingPingPongWithCoalescingApi/4096/1/0 [polls/iter:0 ] 10.3µs ± 1% 10.2µs ± 2% -0.74% (p=0.002 n=18+20) BM_StreamingPingPongWithCoalescingApi/4096/2/0 [polls/iter:0 ] 15.3µs ± 2% 15.3µs ± 2% -0.59% (p=0.035 n=20+20) BM_StreamingPingPongWithCoalescingApi/4096/1/1 [polls/iter:0 ] 9.92µs ± 2% 9.71µs ± 1% -2.12% (p=0.000 n=20+20) BM_StreamingPingPong/8/2 [polls/iter:12.0001 ] 62.2µs ± 2% 61.2µs ± 0% -1.65% (p=0.002 n=8+5) BM_StreamingPingPong/512/2 [polls/iter:12.0001 ] 65.5µs ± 2% 64.7µs ± 3% -1.13% (p=0.045 n=8+5) BM_StreamingPingPong/262144/1 [polls/iter:8.00022 ] 325µs ± 1% 321µs ± 0% -1.21% (p=0.036 n=5+3) BM_StreamingPingPong/1/2 [polls/iter:12.0001 ] 61.3µs ± 2% 60.1µs ± 1% -2.01% (p=0.008 n=7+6) BM_StreamingPingPong/0/2 [polls/iter:12 ] 61.1µs ± 1% 59.9µs ± 1% -1.95% (p=0.016 n=5+5) BM_StreamingPingPong/64/2 [polls/iter:12.0001 ] 63.5µs ± 1% 62.4µs ± 1% -1.75% (p=0.008 n=6+8) BM_StreamingPingPongWithCoalescingApi/134217728/1/1 [polls/iter:5.75 writes/iter:10.25 ] 414ms ± 1% 419ms ± 0% +1.29% (p=0.033 n=7+3) BM_StreamingPingPong/512/2 [polls/iter:12.0002 ] 65.6µs ± 2% 64.6µs ± 1% -1.52% (p=0.043 n=6+8) BM_StreamingPingPongMsgs/32768 [polls/iter:4.00009 ] 42.8µs ± 1% 42.3µs ± 0% -1.15% (p=0.048 n=6+3) BM_StreamingPingPong/64/2 [polls/iter:12.0002 ] 63.6µs ± 1% 62.4µs ± 1% -1.86% (p=0.032 n=4+5) BM_StreamingPingPong/4096/2 [polls/iter:12.0002 ] 69.1µs ± 1% 68.4µs ± 0% -0.97% (p=0.036 n=5+3) ``` --- include/grpcpp/impl/codegen/call_op_set.h | 30 +++++++++++++---------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/include/grpcpp/impl/codegen/call_op_set.h b/include/grpcpp/impl/codegen/call_op_set.h index abcfba2d225..e46ea05ce19 100644 --- a/include/grpcpp/impl/codegen/call_op_set.h +++ b/include/grpcpp/impl/codegen/call_op_set.h @@ -772,19 +772,23 @@ class CallOpClientRecvStatus { void FinishOp(bool* /*status*/) { if (recv_status_ == nullptr || hijacked_) return; - grpc::string binary_error_details = metadata_map_->GetBinaryErrorDetails(); - *recv_status_ = - Status(static_cast(status_code_), - GRPC_SLICE_IS_EMPTY(error_message_) - ? grpc::string() - : grpc::string(GRPC_SLICE_START_PTR(error_message_), - GRPC_SLICE_END_PTR(error_message_)), - binary_error_details); - client_context_->set_debug_error_string( - debug_error_string_ != nullptr ? debug_error_string_ : ""); - g_core_codegen_interface->grpc_slice_unref(error_message_); - if (debug_error_string_ != nullptr) { - g_core_codegen_interface->gpr_free((void*)debug_error_string_); + if (status_code_ == StatusCode::OK) { + *recv_status_ = Status(); + GPR_CODEGEN_DEBUG_ASSERT(GRPC_SLICE_IS_EMPTY(error_message_)); + GPR_CODEGEN_DEBUG_ASSERT(debug_error_string_ == nullptr); + } else { + *recv_status_ = + Status(static_cast(status_code_), + GRPC_SLICE_IS_EMPTY(error_message_) + ? grpc::string() + : grpc::string(GRPC_SLICE_START_PTR(error_message_), + GRPC_SLICE_END_PTR(error_message_)), + metadata_map_->GetBinaryErrorDetails()); + g_core_codegen_interface->grpc_slice_unref(error_message_); + if (debug_error_string_ != nullptr) { + client_context_->set_debug_error_string(debug_error_string_); + g_core_codegen_interface->gpr_free((void*)debug_error_string_); + } } } From 6822d9a7792c160265f05fd9f497c79bbe850822 Mon Sep 17 00:00:00 2001 From: Jan Tattermusch Date: Mon, 16 Sep 2019 18:14:51 +0200 Subject: [PATCH 02/60] correctly generate tests for bazel tests that dont use polling --- bazel/grpc_build_system.bzl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bazel/grpc_build_system.bzl b/bazel/grpc_build_system.bzl index afff5438808..5bf04f2ff0b 100644 --- a/bazel/grpc_build_system.bzl +++ b/bazel/grpc_build_system.bzl @@ -212,7 +212,7 @@ def grpc_cc_test(name, srcs = [], deps = [], external_deps = [], args = [], data exec_compatible_with = exec_compatible_with, ) else: - native.cc_test(tags = tags, **args) + native.cc_test(name = name, tags = tags, **args) ios_cc_test( name = name, tags = tags, From 6ebc1c616fd06192fff5433d260b8bb4551e1c07 Mon Sep 17 00:00:00 2001 From: Jan Tattermusch Date: Mon, 16 Sep 2019 18:15:45 +0200 Subject: [PATCH 03/60] set uses_polling=False for some bazel tests --- test/core/avl/BUILD | 1 + test/core/backoff/BUILD | 1 + test/core/channel/BUILD | 5 +++++ test/core/client_channel/BUILD | 2 ++ test/core/compression/BUILD | 4 ++++ test/core/debug/BUILD | 1 + test/core/end2end/BUILD | 1 + test/core/gpr/BUILD | 12 ++++++++++++ test/core/gprpp/BUILD | 9 +++++++++ test/core/http/BUILD | 1 + test/core/iomgr/BUILD | 7 +++++++ test/core/json/BUILD | 3 +++ test/core/memory_usage/BUILD | 1 + test/core/security/BUILD | 3 +++ test/core/slice/BUILD | 7 +++++++ test/core/surface/BUILD | 2 ++ test/core/transport/BUILD | 6 ++++++ test/core/transport/chttp2/BUILD | 7 +++++++ test/core/util/BUILD | 2 ++ test/cpp/codegen/BUILD | 3 +++ test/cpp/common/BUILD | 3 +++ test/cpp/qps/BUILD | 1 + test/cpp/util/BUILD | 4 ++++ 23 files changed, 86 insertions(+) diff --git a/test/core/avl/BUILD b/test/core/avl/BUILD index c31abebcbe5..861b96a9a62 100644 --- a/test/core/avl/BUILD +++ b/test/core/avl/BUILD @@ -27,4 +27,5 @@ grpc_cc_test( "//:grpc", "//test/core/util:grpc_test_util", ], + uses_polling = False, ) diff --git a/test/core/backoff/BUILD b/test/core/backoff/BUILD index e4fc2871054..5c62ee8dadf 100644 --- a/test/core/backoff/BUILD +++ b/test/core/backoff/BUILD @@ -35,4 +35,5 @@ grpc_cc_test( "//:grpc", "//test/core/util:grpc_test_util", ], + uses_polling = False, ) diff --git a/test/core/channel/BUILD b/test/core/channel/BUILD index 3249a16edda..e38c4c9c194 100644 --- a/test/core/channel/BUILD +++ b/test/core/channel/BUILD @@ -27,6 +27,7 @@ grpc_cc_test( "//:grpc", "//test/core/util:grpc_test_util", ], + uses_polling = False, ) grpc_cc_test( @@ -38,6 +39,7 @@ grpc_cc_test( "//:grpc", "//test/core/util:grpc_test_util", ], + uses_polling = False, ) grpc_cc_test( @@ -60,6 +62,7 @@ grpc_cc_test( "//:grpc", "//test/core/util:grpc_test_util", ], + uses_polling = False, ) grpc_cc_test( @@ -107,6 +110,7 @@ grpc_cc_test( "//:grpc++", "//test/core/util:grpc_test_util", ], + uses_polling = False, ) grpc_cc_test( @@ -120,4 +124,5 @@ grpc_cc_test( "//:grpc", "//test/core/util:grpc_test_util", ], + uses_polling = False, ) diff --git a/test/core/client_channel/BUILD b/test/core/client_channel/BUILD index a9cfa961ec2..cafd6101ffc 100644 --- a/test/core/client_channel/BUILD +++ b/test/core/client_channel/BUILD @@ -53,6 +53,7 @@ grpc_cc_test( "//test/core/util:grpc_test_util", ], tags = ["no_windows"], + uses_polling = False, ) grpc_cc_test( @@ -78,6 +79,7 @@ grpc_cc_test( "//:grpc", "//test/core/util:grpc_test_util", ], + uses_polling = False, ) grpc_cc_test( diff --git a/test/core/compression/BUILD b/test/core/compression/BUILD index 03c82689a85..9faeeef5078 100644 --- a/test/core/compression/BUILD +++ b/test/core/compression/BUILD @@ -27,6 +27,7 @@ grpc_cc_test( "//:grpc", "//test/core/util:grpc_test_util", ], + uses_polling = False, ) grpc_cc_test( @@ -38,6 +39,7 @@ grpc_cc_test( "//:grpc", "//test/core/util:grpc_test_util", ], + uses_polling = False, ) grpc_cc_test( @@ -49,6 +51,7 @@ grpc_cc_test( "//:grpc", "//test/core/util:grpc_test_util", ], + uses_polling = False, ) grpc_cc_test( @@ -60,4 +63,5 @@ grpc_cc_test( "//:grpc", "//test/core/util:grpc_test_util", ], + uses_polling = False, ) diff --git a/test/core/debug/BUILD b/test/core/debug/BUILD index c4209296702..2038d8d677a 100644 --- a/test/core/debug/BUILD +++ b/test/core/debug/BUILD @@ -30,4 +30,5 @@ grpc_cc_test( "//:grpc", "//test/core/util:grpc_test_util", ], + uses_polling = False, ) diff --git a/test/core/end2end/BUILD b/test/core/end2end/BUILD index 16f987e847d..d13894050ff 100644 --- a/test/core/end2end/BUILD +++ b/test/core/end2end/BUILD @@ -141,6 +141,7 @@ grpc_cc_test( "//:grpc", "//test/core/util:grpc_test_util", ], + uses_polling = False, ) grpc_cc_test( diff --git a/test/core/gpr/BUILD b/test/core/gpr/BUILD index c4ee5e977ad..04fd72ab486 100644 --- a/test/core/gpr/BUILD +++ b/test/core/gpr/BUILD @@ -26,6 +26,7 @@ grpc_cc_test( "//:gpr", "//test/core/util:grpc_test_util", ], + uses_polling = False, ) grpc_cc_test( @@ -36,6 +37,7 @@ grpc_cc_test( "//:gpr", "//test/core/util:grpc_test_util", ], + uses_polling = False, ) grpc_cc_test( @@ -46,6 +48,7 @@ grpc_cc_test( "//:gpr", "//test/core/util:grpc_test_util", ], + uses_polling = False, ) grpc_cc_test( @@ -56,6 +59,7 @@ grpc_cc_test( "//:gpr", "//test/core/util:grpc_test_util", ], + uses_polling = False, ) grpc_cc_test( @@ -66,6 +70,7 @@ grpc_cc_test( "//:gpr", "//test/core/util:grpc_test_util", ], + uses_polling = False, ) grpc_cc_test( @@ -76,6 +81,7 @@ grpc_cc_test( "//:gpr", "//test/core/util:grpc_test_util", ], + uses_polling = False, ) grpc_cc_test( @@ -86,6 +92,7 @@ grpc_cc_test( "//:gpr", "//test/core/util:grpc_test_util", ], + uses_polling = False, ) grpc_cc_test( @@ -96,6 +103,7 @@ grpc_cc_test( "//:gpr", "//test/core/util:grpc_test_util", ], + uses_polling = False, ) grpc_cc_test( @@ -106,6 +114,7 @@ grpc_cc_test( "//:gpr", "//test/core/util:grpc_test_util", ], + uses_polling = False, ) grpc_cc_test( @@ -116,6 +125,7 @@ grpc_cc_test( "//:gpr", "//test/core/util:grpc_test_util", ], + uses_polling = False, ) grpc_cc_test( @@ -126,6 +136,7 @@ grpc_cc_test( "//:gpr", "//test/core/util:grpc_test_util", ], + uses_polling = False, ) grpc_cc_test( @@ -136,4 +147,5 @@ grpc_cc_test( "//:gpr", "//test/core/util:grpc_test_util", ], + uses_polling = False, ) diff --git a/test/core/gprpp/BUILD b/test/core/gprpp/BUILD index 142fcbb571b..0b0236334b2 100644 --- a/test/core/gprpp/BUILD +++ b/test/core/gprpp/BUILD @@ -26,6 +26,7 @@ grpc_cc_test( "//:gpr", "//test/core/util:grpc_test_util", ], + uses_polling = False, ) grpc_cc_test( @@ -39,6 +40,7 @@ grpc_cc_test( "//:gpr", "//test/core/util:grpc_test_util", ], + uses_polling = False, ) grpc_cc_test( @@ -52,6 +54,7 @@ grpc_cc_test( "//:gpr", "//test/core/util:grpc_test_util", ], + uses_polling = False, ) grpc_cc_test( @@ -62,6 +65,7 @@ grpc_cc_test( "//:gpr", "//test/core/util:grpc_test_util", ], + uses_polling = False, ) grpc_cc_test( @@ -72,6 +76,7 @@ grpc_cc_test( "//:gpr", "//test/core/util:grpc_test_util", ], + uses_polling = False, ) grpc_cc_test( @@ -85,6 +90,7 @@ grpc_cc_test( "//:gpr_base", "//test/core/util:grpc_test_util", ], + uses_polling = False, ) grpc_cc_test( @@ -98,6 +104,7 @@ grpc_cc_test( "//:gpr_base", "//test/core/util:grpc_test_util", ], + uses_polling = False, ) grpc_cc_test( @@ -122,6 +129,7 @@ grpc_cc_test( "//:gpr", "//test/core/util:grpc_test_util", ], + uses_polling = False, ) grpc_cc_test( @@ -198,4 +206,5 @@ grpc_cc_test( "//:gpr", "//test/core/util:grpc_test_util", ], + uses_polling = False, ) diff --git a/test/core/http/BUILD b/test/core/http/BUILD index 3e679262555..8951d1aba2e 100644 --- a/test/core/http/BUILD +++ b/test/core/http/BUILD @@ -109,6 +109,7 @@ grpc_cc_test( "//test/core/end2end:ssl_test_data", "//test/core/util:grpc_test_util", ], + uses_polling = False, ) grpc_cc_test( diff --git a/test/core/iomgr/BUILD b/test/core/iomgr/BUILD index 808a635b80a..7e4cdc0d729 100644 --- a/test/core/iomgr/BUILD +++ b/test/core/iomgr/BUILD @@ -70,6 +70,7 @@ grpc_cc_test( "//:grpc", "//test/core/util:grpc_test_util", ], + uses_polling = False, ) grpc_cc_test( @@ -128,6 +129,7 @@ grpc_cc_test( "//:grpc", "//test/core/util:grpc_test_util", ], + uses_polling = False, ) grpc_cc_test( @@ -139,6 +141,7 @@ grpc_cc_test( "//:grpc", "//test/core/util:grpc_test_util", ], + uses_polling = False, ) grpc_cc_test( @@ -290,6 +293,7 @@ grpc_cc_test( "//:grpc", "//test/core/util:grpc_test_util", ], + uses_polling = False, ) grpc_cc_test( @@ -301,6 +305,7 @@ grpc_cc_test( "//:grpc", "//test/core/util:grpc_test_util", ], + uses_polling = False, ) grpc_cc_test( @@ -312,6 +317,7 @@ grpc_cc_test( "//:grpc", "//test/core/util:grpc_test_util", ], + uses_polling = False, ) grpc_cc_test( @@ -323,6 +329,7 @@ grpc_cc_test( "//:grpc", "//test/core/util:grpc_test_util", ], + uses_polling = False, ) grpc_cc_test( diff --git a/test/core/json/BUILD b/test/core/json/BUILD index 5684505cbc9..c9298e5f2c4 100644 --- a/test/core/json/BUILD +++ b/test/core/json/BUILD @@ -59,6 +59,7 @@ grpc_cc_test( "//:grpc", "//test/core/util:grpc_test_util", ], + uses_polling = False, ) grpc_cc_test( @@ -70,6 +71,7 @@ grpc_cc_test( "//:grpc", "//test/core/util:grpc_test_util", ], + uses_polling = False, ) grpc_cc_test( @@ -81,4 +83,5 @@ grpc_cc_test( "//:grpc", "//test/core/util:grpc_test_util", ], + uses_polling = False, ) diff --git a/test/core/memory_usage/BUILD b/test/core/memory_usage/BUILD index 38b088c75c7..c9da6b4241b 100644 --- a/test/core/memory_usage/BUILD +++ b/test/core/memory_usage/BUILD @@ -54,4 +54,5 @@ grpc_cc_test( "//:grpc", "//test/core/util:grpc_test_util", ], + uses_polling = False, ) diff --git a/test/core/security/BUILD b/test/core/security/BUILD index b6d43c62722..c6dbc5fbed8 100644 --- a/test/core/security/BUILD +++ b/test/core/security/BUILD @@ -63,6 +63,7 @@ grpc_cc_test( "//:grpc", "//test/core/util:grpc_test_util", ], + uses_polling = False, ) grpc_cc_test( @@ -98,6 +99,7 @@ grpc_cc_test( "//:grpc", "//test/core/util:grpc_test_util", ], + uses_polling = False, ) grpc_cc_test( @@ -109,6 +111,7 @@ grpc_cc_test( "//:grpc", "//test/core/util:grpc_test_util", ], + uses_polling = False, ) grpc_cc_test( diff --git a/test/core/slice/BUILD b/test/core/slice/BUILD index 12ee42ba9c3..dbca3477131 100644 --- a/test/core/slice/BUILD +++ b/test/core/slice/BUILD @@ -53,6 +53,7 @@ grpc_cc_test( "//:grpc", "//test/core/util:grpc_test_util", ], + uses_polling = False, ) grpc_cc_test( @@ -64,6 +65,7 @@ grpc_cc_test( "//:grpc", "//test/core/util:grpc_test_util", ], + uses_polling = False, ) grpc_cc_test( @@ -75,6 +77,7 @@ grpc_cc_test( "//:grpc", "//test/core/util:grpc_test_util", ], + uses_polling = False, ) grpc_cc_test( @@ -86,6 +89,7 @@ grpc_cc_test( "//:grpc", "//test/core/util:grpc_test_util", ], + uses_polling = False, ) grpc_cc_test( @@ -100,6 +104,7 @@ grpc_cc_test( "//:grpc", "//test/core/util:grpc_test_util", ], + uses_polling = False, ) grpc_cc_test( @@ -114,6 +119,7 @@ grpc_cc_test( "//:grpc", "//test/core/util:grpc_test_util", ], + uses_polling = False, ) grpc_cc_test( @@ -125,4 +131,5 @@ grpc_cc_test( "//:grpc", "//test/core/util:grpc_test_util", ], + uses_polling = False, ) diff --git a/test/core/surface/BUILD b/test/core/surface/BUILD index 34777806cf2..fe6320babcf 100644 --- a/test/core/surface/BUILD +++ b/test/core/surface/BUILD @@ -27,6 +27,7 @@ grpc_cc_test( "//:grpc", "//test/core/util:grpc_test_util", ], + uses_polling = False, ) grpc_cc_test( @@ -82,6 +83,7 @@ grpc_cc_test( "//:grpc", "//test/core/util:grpc_test_util", ], + uses_polling = False, ) grpc_cc_test( diff --git a/test/core/transport/BUILD b/test/core/transport/BUILD index 44e4fcb978e..94ebb602d80 100644 --- a/test/core/transport/BUILD +++ b/test/core/transport/BUILD @@ -30,6 +30,7 @@ grpc_cc_test( "//:grpc", "//test/core/util:grpc_test_util", ], + uses_polling = False, ) grpc_cc_test( @@ -44,6 +45,7 @@ grpc_cc_test( "//:grpc", "//test/core/util:grpc_test_util", ], + uses_polling = False, ) grpc_cc_test( @@ -105,6 +107,7 @@ grpc_cc_test( "//:grpc", "//test/core/util:grpc_test_util", ], + uses_polling = False, ) grpc_cc_test( @@ -116,6 +119,7 @@ grpc_cc_test( "//:grpc", "//test/core/util:grpc_test_util", ], + uses_polling = False, ) grpc_cc_test( @@ -127,6 +131,7 @@ grpc_cc_test( "//:grpc", "//test/core/util:grpc_test_util", ], + uses_polling = False, ) grpc_cc_test( @@ -140,4 +145,5 @@ grpc_cc_test( "//:grpc", "//test/core/util:grpc_test_util", ], + uses_polling = False, ) diff --git a/test/core/transport/chttp2/BUILD b/test/core/transport/chttp2/BUILD index e5c1a7cff70..f31ba248d19 100644 --- a/test/core/transport/chttp2/BUILD +++ b/test/core/transport/chttp2/BUILD @@ -50,6 +50,7 @@ grpc_cc_test( "//:grpc", "//test/core/util:grpc_test_util", ], + uses_polling = False, ) grpc_cc_test( @@ -61,6 +62,7 @@ grpc_cc_test( "//:grpc", "//test/core/util:grpc_test_util", ], + uses_polling = False, ) grpc_cc_test( @@ -75,6 +77,7 @@ grpc_cc_test( "//:grpc", "//test/core/util:grpc_test_util", ], + uses_polling = False, ) grpc_cc_test( @@ -86,6 +89,7 @@ grpc_cc_test( "//:grpc", "//test/core/util:grpc_test_util", ], + uses_polling = False, ) grpc_cc_test( @@ -97,6 +101,7 @@ grpc_cc_test( "//:grpc", "//test/core/util:grpc_test_util", ], + uses_polling = False, ) grpc_cc_test( @@ -108,6 +113,7 @@ grpc_cc_test( "//:grpc", "//test/core/util:grpc_test_util", ], + uses_polling = False, ) grpc_cc_test( @@ -144,4 +150,5 @@ grpc_cc_test( "//:grpc", "//test/core/util:grpc_test_util", ], + uses_polling = False, ) diff --git a/test/core/util/BUILD b/test/core/util/BUILD index 47f814a7ad3..3cf1fa3ecff 100644 --- a/test/core/util/BUILD +++ b/test/core/util/BUILD @@ -119,6 +119,7 @@ grpc_cc_test( ":grpc_test_util", "//:gpr", ], + uses_polling = False, ) grpc_cc_library( @@ -145,6 +146,7 @@ grpc_cc_test( ":grpc_test_util", "//:gpr", ], + uses_polling = False, ) sh_library( diff --git a/test/cpp/codegen/BUILD b/test/cpp/codegen/BUILD index 90af67bd858..69d5859489f 100644 --- a/test/cpp/codegen/BUILD +++ b/test/cpp/codegen/BUILD @@ -28,6 +28,7 @@ grpc_cc_test( "//:grpc++", "//test/core/util:grpc_test_util", ], + uses_polling = False, ) grpc_cc_test( @@ -40,6 +41,7 @@ grpc_cc_test( "//:grpc++", "//test/core/util:grpc_test_util", ], + uses_polling = False, ) grpc_cc_test( @@ -53,6 +55,7 @@ grpc_cc_test( "//:grpc++", "//test/core/util:grpc_test_util", ], + uses_polling = False, ) grpc_cc_binary( diff --git a/test/cpp/common/BUILD b/test/cpp/common/BUILD index c31eb10344e..ac82acc073e 100644 --- a/test/cpp/common/BUILD +++ b/test/cpp/common/BUILD @@ -66,6 +66,7 @@ grpc_cc_test( "//test/core/util:grpc_test_util", "//test/cpp/util:test_util", ], + uses_polling = False, ) grpc_cc_test( @@ -78,6 +79,7 @@ grpc_cc_test( "//:grpc++", "//test/core/util:grpc_test_util", ], + uses_polling = False, ) grpc_cc_test( @@ -90,6 +92,7 @@ grpc_cc_test( "//:grpc++", "//test/core/util:grpc_test_util", ], + uses_polling = False, ) grpc_cc_test( diff --git a/test/cpp/qps/BUILD b/test/cpp/qps/BUILD index 8855a1c155d..5c84d75dc5f 100644 --- a/test/cpp/qps/BUILD +++ b/test/cpp/qps/BUILD @@ -163,6 +163,7 @@ grpc_cc_test( ":interarrival", "//test/cpp/util:test_config", ], + uses_polling = False, ) grpc_cc_test( diff --git a/test/cpp/util/BUILD b/test/cpp/util/BUILD index 858b88eb01b..2e9d1cc8bba 100644 --- a/test/cpp/util/BUILD +++ b/test/cpp/util/BUILD @@ -213,6 +213,7 @@ grpc_cc_test( deps = [ ":test_util", ], + uses_polling = False, ) grpc_cc_test( @@ -226,6 +227,7 @@ grpc_cc_test( deps = [ ":test_util", ], + uses_polling = False, ) grpc_cc_test( @@ -240,6 +242,7 @@ grpc_cc_test( "//:grpc++", "//test/core/util:grpc_test_util", ], + uses_polling = False, ) grpc_cc_test( @@ -253,6 +256,7 @@ grpc_cc_test( deps = [ ":test_util", ], + uses_polling = False, ) grpc_cc_test( From 05b3eeff772f6c6cd0b2764d5a8d015a29b9aa7d Mon Sep 17 00:00:00 2001 From: chentanjun <2799194073@qq.com> Date: Wed, 25 Sep 2019 23:29:47 +0800 Subject: [PATCH 04/60] fix-up some spelling mistakes --- src/ruby/ext/grpc/rb_channel.c | 2 +- tools/debug/core/error_ref_leak.py | 2 +- tools/http2_interop/http2interop_test.go | 2 +- tools/http2_interop/s6.5.go | 2 +- tools/run_tests/artifacts/distribtest_targets.py | 4 ++-- tools/run_tests/python_utils/report_utils.py | 2 +- tools/run_tests/python_utils/upload_rbe_results.py | 2 +- tools/run_tests/run_interop_tests.py | 2 +- 8 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/ruby/ext/grpc/rb_channel.c b/src/ruby/ext/grpc/rb_channel.c index d789e5a4362..73d8b20a312 100644 --- a/src/ruby/ext/grpc/rb_channel.c +++ b/src/ruby/ext/grpc/rb_channel.c @@ -119,7 +119,7 @@ static void grpc_rb_channel_watch_connection_state_op_complete( GPR_ASSERT(!op->op.api_callback_args.called_back); op->op.api_callback_args.called_back = 1; op->op.api_callback_args.success = success; - // wake up the watch API call thats waiting on this op + // wake up the watch API call that's waiting on this op gpr_cv_broadcast(&global_connection_polling_cv); } diff --git a/tools/debug/core/error_ref_leak.py b/tools/debug/core/error_ref_leak.py index 7e206c26b26..125ec90aaef 100644 --- a/tools/debug/core/error_ref_leak.py +++ b/tools/debug/core/error_ref_leak.py @@ -17,7 +17,7 @@ # Reads stdin to find error_refcount log lines, and prints reference leaks # to stdout -# usege: python error_ref_leak < logfile.txt +# usage: python error_ref_leak < logfile.txt import sys import re diff --git a/tools/http2_interop/http2interop_test.go b/tools/http2_interop/http2interop_test.go index 989b60590c3..ce00b873d6e 100644 --- a/tools/http2_interop/http2interop_test.go +++ b/tools/http2_interop/http2interop_test.go @@ -145,7 +145,7 @@ func TestSoonTLSMaxVersion(t *testing.T) { ctx := InteropCtx(t) err := testTLSMaxVersion(ctx, tls.VersionTLS11) // TODO(carl-mastrangelo): maybe this should be some other error. If the server picks - // the wrong protocol version, thats bad too. + // the wrong protocol version, that's bad too. matchError(t, err, "EOF", "server selected unsupported protocol") } diff --git a/tools/http2_interop/s6.5.go b/tools/http2_interop/s6.5.go index 89ca57f221a..1a5777767cf 100644 --- a/tools/http2_interop/s6.5.go +++ b/tools/http2_interop/s6.5.go @@ -72,7 +72,7 @@ func testAllSettingsFramesAcked(ctx *HTTP2InteropCtx) error { var settingsFramesReceived = 0 // The server by default sends a settings frame as part of the handshake, and another - // after the receipt of the initial settings frame as part of our conneection preface. + // after the receipt of the initial settings frame as part of our connection preface. // This means we expected 1 + 1 + 10 = 12 settings frames in return, with all but the // first having the ack bit. for settingsFramesReceived < 12 { diff --git a/tools/run_tests/artifacts/distribtest_targets.py b/tools/run_tests/artifacts/distribtest_targets.py index 0674fc4c689..d65ce934a58 100644 --- a/tools/run_tests/artifacts/distribtest_targets.py +++ b/tools/run_tests/artifacts/distribtest_targets.py @@ -121,7 +121,7 @@ class CSharpDistribTest(object): use_workspace=True) elif self.platform == 'windows': if self.arch == 'x64': - # Use double leading / as the first occurence gets removed by msys bash + # Use double leading / as the first occurrence gets removed by msys bash # when invoking the .bat file (side-effect of posix path conversion) environ = { 'MSBUILD_EXTRA_ARGS': '//p:Platform=x64', @@ -255,7 +255,7 @@ class PHPDistribTest(object): class CppDistribTest(object): - """Tests Cpp make intall by building examples.""" + """Tests Cpp make install by building examples.""" def __init__(self, platform, arch, docker_suffix=None, testcase=None): if platform == 'linux': diff --git a/tools/run_tests/python_utils/report_utils.py b/tools/run_tests/python_utils/report_utils.py index 0ab346b6139..9f84d50c849 100644 --- a/tools/run_tests/python_utils/report_utils.py +++ b/tools/run_tests/python_utils/report_utils.py @@ -30,7 +30,7 @@ def _filter_msg(msg, output_format): """Filters out nonprintable and illegal characters from the message.""" if output_format in ['XML', 'HTML']: # keep whitespaces but remove formfeed and vertical tab characters - # that make XML report unparseable. + # that make XML report unparsable. filtered_msg = filter( lambda x: x in string.printable and x != '\f' and x != '\v', msg.decode('UTF-8', 'ignore')) diff --git a/tools/run_tests/python_utils/upload_rbe_results.py b/tools/run_tests/python_utils/upload_rbe_results.py index e6504799d66..660febcc6c3 100755 --- a/tools/run_tests/python_utils/upload_rbe_results.py +++ b/tools/run_tests/python_utils/upload_rbe_results.py @@ -51,7 +51,7 @@ def _get_api_key(): api_key_directory = os.getenv('KOKORO_GFILE_DIR') api_key_file = os.path.join(api_key_directory, 'resultstore_api_key') assert os.path.isfile(api_key_file), 'Must add --api_key arg if not on ' \ - 'Kokoro or Kokoro envrionment is not set up properly.' + 'Kokoro or Kokoro environment is not set up properly.' with open(api_key_file, 'r') as f: return f.read().replace('\n', '') diff --git a/tools/run_tests/run_interop_tests.py b/tools/run_tests/run_interop_tests.py index 099b8c7b1a5..28ca7f852d1 100755 --- a/tools/run_tests/run_interop_tests.py +++ b/tools/run_tests/run_interop_tests.py @@ -1590,7 +1590,7 @@ try: # HTTP_SERVER_TEST_CASES, in which clients use their gRPC interop clients rather # than specialized http2 clients, reusing existing test implementations. # For example, in the "data_frame_padding" test, use language's gRPC - # interop clients and make them think that theyre running "large_unary" + # interop clients and make them think that they're running "large_unary" # test case. This avoids implementing a new test case in each language. for test_case in _HTTP2_SERVER_TEST_CASES_THAT_USE_GRPC_CLIENTS: if test_case not in language.unimplemented_test_cases(): From 1b9254802dff53a4e32590f73812273373dd827c Mon Sep 17 00:00:00 2001 From: Na-Na Pang Date: Wed, 25 Sep 2019 11:00:13 -0700 Subject: [PATCH 05/60] Make public header files in include/grpcpp/test installed --- CMakeLists.txt | 60 +++++++++++++++++++++++++++++++++ Makefile | 91 ++++++++++++++++++++++++++++++++++++++++++++++++-- build.yaml | 20 ++++++----- grpc.gyp | 10 ++++++ 4 files changed, 170 insertions(+), 11 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 08a49697750..3a3ebfe7384 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3773,6 +3773,66 @@ if (gRPC_INSTALL) endif() endif (gRPC_BUILD_CODEGEN) + +add_library(grpc++_test +) + +if(WIN32 AND MSVC) + set_target_properties(grpc++_test PROPERTIES COMPILE_PDB_NAME "grpc++_test" + COMPILE_PDB_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}" + ) + if (gRPC_INSTALL) + install(FILES ${CMAKE_CURRENT_BINARY_DIR}/grpc++_test.pdb + DESTINATION ${gRPC_INSTALL_LIBDIR} OPTIONAL + ) + endif() +endif() + + +target_include_directories(grpc++_test + PUBLIC $ $ + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${_gRPC_ADDRESS_SORTING_INCLUDE_DIR} + PRIVATE ${_gRPC_BENCHMARK_INCLUDE_DIR} + PRIVATE ${_gRPC_CARES_INCLUDE_DIR} + PRIVATE ${_gRPC_GFLAGS_INCLUDE_DIR} + PRIVATE ${_gRPC_PROTOBUF_INCLUDE_DIR} + PRIVATE ${_gRPC_SSL_INCLUDE_DIR} + PRIVATE ${_gRPC_UPB_GENERATED_DIR} + PRIVATE ${_gRPC_UPB_GRPC_GENERATED_DIR} + PRIVATE ${_gRPC_UPB_INCLUDE_DIR} + PRIVATE ${_gRPC_ZLIB_INCLUDE_DIR} + PRIVATE ${_gRPC_PROTO_GENS_DIR} +) +target_link_libraries(grpc++_test + ${_gRPC_PROTOBUF_LIBRARIES} + ${_gRPC_ALLTARGETS_LIBRARIES} + grpc++ + grpc +) + +foreach(_hdr + include/grpc++/test/mock_stream.h + include/grpc++/test/server_context_test_spouse.h + include/grpcpp/test/mock_stream.h + include/grpcpp/test/server_context_test_spouse.h +) + string(REPLACE "include/" "" _path ${_hdr}) + get_filename_component(_path ${_path} PATH) + install(FILES ${_hdr} + DESTINATION "${gRPC_INSTALL_INCLUDEDIR}/${_path}" + ) +endforeach() + + +if (gRPC_INSTALL) + install(TARGETS grpc++_test EXPORT gRPCTargets + RUNTIME DESTINATION ${gRPC_INSTALL_BINDIR} + LIBRARY DESTINATION ${gRPC_INSTALL_LIBDIR} + ARCHIVE DESTINATION ${gRPC_INSTALL_LIBDIR} + ) +endif() + if (gRPC_BUILD_TESTS) add_library(grpc++_test_config diff --git a/Makefile b/Makefile index b24a27acfe6..21de33157b3 100644 --- a/Makefile +++ b/Makefile @@ -1401,14 +1401,14 @@ static: static_c static_cxx static_c: pc_c pc_c_unsecure cache.mk $(LIBDIR)/$(CONFIG)/libaddress_sorting.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgrpc_cronet.a $(LIBDIR)/$(CONFIG)/libgrpc_unsecure.a -static_cxx: pc_cxx pc_cxx_unsecure cache.mk $(LIBDIR)/$(CONFIG)/libgrpc++.a $(LIBDIR)/$(CONFIG)/libgrpc++_error_details.a $(LIBDIR)/$(CONFIG)/libgrpc++_reflection.a $(LIBDIR)/$(CONFIG)/libgrpc++_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpcpp_channelz.a +static_cxx: pc_cxx pc_cxx_unsecure cache.mk $(LIBDIR)/$(CONFIG)/libgrpc++.a $(LIBDIR)/$(CONFIG)/libgrpc++_error_details.a $(LIBDIR)/$(CONFIG)/libgrpc++_reflection.a $(LIBDIR)/$(CONFIG)/libgrpc++_test.a $(LIBDIR)/$(CONFIG)/libgrpc++_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpcpp_channelz.a static_csharp: static_c $(LIBDIR)/$(CONFIG)/libgrpc_csharp_ext.a shared: shared_c shared_cxx shared_c: pc_c pc_c_unsecure cache.mk $(LIBDIR)/$(CONFIG)/$(SHARED_PREFIX)address_sorting$(SHARED_VERSION_CORE).$(SHARED_EXT_CORE) $(LIBDIR)/$(CONFIG)/$(SHARED_PREFIX)gpr$(SHARED_VERSION_CORE).$(SHARED_EXT_CORE) $(LIBDIR)/$(CONFIG)/$(SHARED_PREFIX)grpc$(SHARED_VERSION_CORE).$(SHARED_EXT_CORE) $(LIBDIR)/$(CONFIG)/$(SHARED_PREFIX)grpc_cronet$(SHARED_VERSION_CORE).$(SHARED_EXT_CORE) $(LIBDIR)/$(CONFIG)/$(SHARED_PREFIX)grpc_unsecure$(SHARED_VERSION_CORE).$(SHARED_EXT_CORE) -shared_cxx: pc_cxx pc_cxx_unsecure cache.mk $(LIBDIR)/$(CONFIG)/$(SHARED_PREFIX)grpc++$(SHARED_VERSION_CPP).$(SHARED_EXT_CPP) $(LIBDIR)/$(CONFIG)/$(SHARED_PREFIX)grpc++_error_details$(SHARED_VERSION_CPP).$(SHARED_EXT_CPP) $(LIBDIR)/$(CONFIG)/$(SHARED_PREFIX)grpc++_reflection$(SHARED_VERSION_CPP).$(SHARED_EXT_CPP) $(LIBDIR)/$(CONFIG)/$(SHARED_PREFIX)grpc++_unsecure$(SHARED_VERSION_CPP).$(SHARED_EXT_CPP) $(LIBDIR)/$(CONFIG)/$(SHARED_PREFIX)grpcpp_channelz$(SHARED_VERSION_CPP).$(SHARED_EXT_CPP) +shared_cxx: pc_cxx pc_cxx_unsecure cache.mk $(LIBDIR)/$(CONFIG)/$(SHARED_PREFIX)grpc++$(SHARED_VERSION_CPP).$(SHARED_EXT_CPP) $(LIBDIR)/$(CONFIG)/$(SHARED_PREFIX)grpc++_error_details$(SHARED_VERSION_CPP).$(SHARED_EXT_CPP) $(LIBDIR)/$(CONFIG)/$(SHARED_PREFIX)grpc++_reflection$(SHARED_VERSION_CPP).$(SHARED_EXT_CPP) $(LIBDIR)/$(CONFIG)/$(SHARED_PREFIX)grpc++_test$(SHARED_VERSION_CPP).$(SHARED_EXT_CPP) $(LIBDIR)/$(CONFIG)/$(SHARED_PREFIX)grpc++_unsecure$(SHARED_VERSION_CPP).$(SHARED_EXT_CPP) $(LIBDIR)/$(CONFIG)/$(SHARED_PREFIX)grpcpp_channelz$(SHARED_VERSION_CPP).$(SHARED_EXT_CPP) shared_csharp: shared_c $(LIBDIR)/$(CONFIG)/$(SHARED_PREFIX)grpc_csharp_ext$(SHARED_VERSION_CSHARP).$(SHARED_EXT_CSHARP) grpc_csharp_ext: shared_csharp @@ -2580,6 +2580,8 @@ ifeq ($(CONFIG),opt) $(Q) $(STRIP) $(LIBDIR)/$(CONFIG)/libgrpc++_error_details.a $(E) "[STRIP] Stripping libgrpc++_reflection.a" $(Q) $(STRIP) $(LIBDIR)/$(CONFIG)/libgrpc++_reflection.a + $(E) "[STRIP] Stripping libgrpc++_test.a" + $(Q) $(STRIP) $(LIBDIR)/$(CONFIG)/libgrpc++_test.a $(E) "[STRIP] Stripping libgrpc++_unsecure.a" $(Q) $(STRIP) $(LIBDIR)/$(CONFIG)/libgrpc++_unsecure.a $(E) "[STRIP] Stripping libgrpcpp_channelz.a" @@ -2608,6 +2610,8 @@ ifeq ($(CONFIG),opt) $(Q) $(STRIP) $(LIBDIR)/$(CONFIG)/$(SHARED_PREFIX)grpc++_error_details$(SHARED_VERSION_CPP).$(SHARED_EXT_CPP) $(E) "[STRIP] Stripping $(SHARED_PREFIX)grpc++_reflection$(SHARED_VERSION_CPP).$(SHARED_EXT_CPP)" $(Q) $(STRIP) $(LIBDIR)/$(CONFIG)/$(SHARED_PREFIX)grpc++_reflection$(SHARED_VERSION_CPP).$(SHARED_EXT_CPP) + $(E) "[STRIP] Stripping $(SHARED_PREFIX)grpc++_test$(SHARED_VERSION_CPP).$(SHARED_EXT_CPP)" + $(Q) $(STRIP) $(LIBDIR)/$(CONFIG)/$(SHARED_PREFIX)grpc++_test$(SHARED_VERSION_CPP).$(SHARED_EXT_CPP) $(E) "[STRIP] Stripping $(SHARED_PREFIX)grpc++_unsecure$(SHARED_VERSION_CPP).$(SHARED_EXT_CPP)" $(Q) $(STRIP) $(LIBDIR)/$(CONFIG)/$(SHARED_PREFIX)grpc++_unsecure$(SHARED_VERSION_CPP).$(SHARED_EXT_CPP) $(E) "[STRIP] Stripping $(SHARED_PREFIX)grpcpp_channelz$(SHARED_VERSION_CPP).$(SHARED_EXT_CPP)" @@ -3134,6 +3138,9 @@ install-static_cxx: static_cxx strip-static_cxx install-pkg-config_cxx $(E) "[INSTALL] Installing libgrpc++_reflection.a" $(Q) $(INSTALL) -d $(prefix)/lib $(Q) $(INSTALL) $(LIBDIR)/$(CONFIG)/libgrpc++_reflection.a $(prefix)/lib/libgrpc++_reflection.a + $(E) "[INSTALL] Installing libgrpc++_test.a" + $(Q) $(INSTALL) -d $(prefix)/lib + $(Q) $(INSTALL) $(LIBDIR)/$(CONFIG)/libgrpc++_test.a $(prefix)/lib/libgrpc++_test.a $(E) "[INSTALL] Installing libgrpc++_unsecure.a" $(Q) $(INSTALL) -d $(prefix)/lib $(Q) $(INSTALL) $(LIBDIR)/$(CONFIG)/libgrpc++_unsecure.a $(prefix)/lib/libgrpc++_unsecure.a @@ -3223,6 +3230,15 @@ ifeq ($(SYSTEM),MINGW32) else ifneq ($(SYSTEM),Darwin) $(Q) ln -sf $(SHARED_PREFIX)grpc++_reflection$(SHARED_VERSION_CPP).$(SHARED_EXT_CPP) $(prefix)/lib/libgrpc++_reflection.so.1 $(Q) ln -sf $(SHARED_PREFIX)grpc++_reflection$(SHARED_VERSION_CPP).$(SHARED_EXT_CPP) $(prefix)/lib/libgrpc++_reflection.so +endif + $(E) "[INSTALL] Installing $(SHARED_PREFIX)grpc++_test$(SHARED_VERSION_CPP).$(SHARED_EXT_CPP)" + $(Q) $(INSTALL) -d $(prefix)/lib + $(Q) $(INSTALL) $(LIBDIR)/$(CONFIG)/$(SHARED_PREFIX)grpc++_test$(SHARED_VERSION_CPP).$(SHARED_EXT_CPP) $(prefix)/lib/$(SHARED_PREFIX)grpc++_test$(SHARED_VERSION_CPP).$(SHARED_EXT_CPP) +ifeq ($(SYSTEM),MINGW32) + $(Q) $(INSTALL) $(LIBDIR)/$(CONFIG)/libgrpc++_test$(SHARED_VERSION_CPP)-dll.a $(prefix)/lib/libgrpc++_test.a +else ifneq ($(SYSTEM),Darwin) + $(Q) ln -sf $(SHARED_PREFIX)grpc++_test$(SHARED_VERSION_CPP).$(SHARED_EXT_CPP) $(prefix)/lib/libgrpc++_test.so.1 + $(Q) ln -sf $(SHARED_PREFIX)grpc++_test$(SHARED_VERSION_CPP).$(SHARED_EXT_CPP) $(prefix)/lib/libgrpc++_test.so endif $(E) "[INSTALL] Installing $(SHARED_PREFIX)grpc++_unsecure$(SHARED_VERSION_CPP).$(SHARED_EXT_CPP)" $(Q) $(INSTALL) -d $(prefix)/lib @@ -6268,6 +6284,77 @@ $(OBJDIR)/$(CONFIG)/src/cpp/ext/proto_server_reflection.o: $(GENDIR)/src/proto/g $(OBJDIR)/$(CONFIG)/src/cpp/ext/proto_server_reflection_plugin.o: $(GENDIR)/src/proto/grpc/reflection/v1alpha/reflection.pb.cc $(GENDIR)/src/proto/grpc/reflection/v1alpha/reflection.grpc.pb.cc +LIBGRPC++_TEST_SRC = \ + +PUBLIC_HEADERS_CXX += \ + include/grpc++/test/mock_stream.h \ + include/grpc++/test/server_context_test_spouse.h \ + include/grpcpp/test/mock_stream.h \ + include/grpcpp/test/server_context_test_spouse.h \ + +LIBGRPC++_TEST_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(LIBGRPC++_TEST_SRC)))) + + +ifeq ($(NO_SECURE),true) + +# You can't build secure libraries if you don't have OpenSSL. + +$(LIBDIR)/$(CONFIG)/libgrpc++_test.a: openssl_dep_error + +$(LIBDIR)/$(CONFIG)/$(SHARED_PREFIX)grpc++_test$(SHARED_VERSION_CPP).$(SHARED_EXT_CPP): openssl_dep_error + +else + +ifeq ($(NO_PROTOBUF),true) + +# You can't build a C++ library if you don't have protobuf - a bit overreached, but still okay. + +$(LIBDIR)/$(CONFIG)/libgrpc++_test.a: protobuf_dep_error + +$(LIBDIR)/$(CONFIG)/$(SHARED_PREFIX)grpc++_test$(SHARED_VERSION_CPP).$(SHARED_EXT_CPP): protobuf_dep_error + +else + +$(LIBDIR)/$(CONFIG)/libgrpc++_test.a: $(ZLIB_DEP) $(OPENSSL_DEP) $(CARES_DEP) $(ADDRESS_SORTING_DEP) $(PROTOBUF_DEP) $(LIBGRPC++_TEST_OBJS) + $(E) "[AR] Creating $@" + $(Q) mkdir -p `dirname $@` + $(Q) rm -f $(LIBDIR)/$(CONFIG)/libgrpc++_test.a + $(Q) $(AR) $(AROPTS) $(LIBDIR)/$(CONFIG)/libgrpc++_test.a $(LIBGRPC++_TEST_OBJS) +ifeq ($(SYSTEM),Darwin) + $(Q) ranlib -no_warning_for_no_symbols $(LIBDIR)/$(CONFIG)/libgrpc++_test.a +endif + + + +ifeq ($(SYSTEM),MINGW32) +$(LIBDIR)/$(CONFIG)/grpc++_test$(SHARED_VERSION_CPP).$(SHARED_EXT_CPP): $(LIBGRPC++_TEST_OBJS) $(ZLIB_DEP) $(CARES_DEP) $(ADDRESS_SORTING_DEP) $(PROTOBUF_DEP) $(LIBDIR)/$(CONFIG)/grpc++$(SHARED_VERSION_CPP).$(SHARED_EXT_CPP) $(LIBDIR)/$(CONFIG)/grpc$(SHARED_VERSION_CORE).$(SHARED_EXT_CORE) $(OPENSSL_DEP) + $(E) "[LD] Linking $@" + $(Q) mkdir -p `dirname $@` + $(Q) $(LDXX) $(LDFLAGS) -L$(LIBDIR)/$(CONFIG) -shared -Wl,--output-def=$(LIBDIR)/$(CONFIG)/grpc++_test$(SHARED_VERSION_CPP).def -Wl,--out-implib=$(LIBDIR)/$(CONFIG)/libgrpc++_test$(SHARED_VERSION_CPP)-dll.a -o $(LIBDIR)/$(CONFIG)/grpc++_test$(SHARED_VERSION_CPP).$(SHARED_EXT_CPP) $(LIBGRPC++_TEST_OBJS) $(ZLIB_MERGE_LIBS) $(CARES_MERGE_LIBS) $(ADDRESS_SORTING_MERGE_LIBS) $(LDLIBSXX) $(LDLIBS_PROTOBUF) $(LDLIBS) -lgrpc++$(SHARED_VERSION_CPP)-dll -lgrpc$(SHARED_VERSION_CORE)-dll +else +$(LIBDIR)/$(CONFIG)/libgrpc++_test$(SHARED_VERSION_CPP).$(SHARED_EXT_CPP): $(LIBGRPC++_TEST_OBJS) $(ZLIB_DEP) $(CARES_DEP) $(ADDRESS_SORTING_DEP) $(PROTOBUF_DEP) $(LIBDIR)/$(CONFIG)/libgrpc++.$(SHARED_EXT_CPP) $(LIBDIR)/$(CONFIG)/libgrpc.$(SHARED_EXT_CORE) $(OPENSSL_DEP) + $(E) "[LD] Linking $@" + $(Q) mkdir -p `dirname $@` +ifeq ($(SYSTEM),Darwin) + $(Q) $(LDXX) $(LDFLAGS) -L$(LIBDIR)/$(CONFIG) -install_name $(SHARED_PREFIX)grpc++_test$(SHARED_VERSION_CPP).$(SHARED_EXT_CPP) -dynamiclib -o $(LIBDIR)/$(CONFIG)/libgrpc++_test$(SHARED_VERSION_CPP).$(SHARED_EXT_CPP) $(LIBGRPC++_TEST_OBJS) $(ZLIB_MERGE_LIBS) $(CARES_MERGE_LIBS) $(ADDRESS_SORTING_MERGE_LIBS) $(LDLIBSXX) $(LDLIBS_PROTOBUF) $(LDLIBS) -lgrpc++ -lgrpc +else + $(Q) $(LDXX) $(LDFLAGS) -L$(LIBDIR)/$(CONFIG) -shared -Wl,-soname,libgrpc++_test.so.1 -o $(LIBDIR)/$(CONFIG)/libgrpc++_test$(SHARED_VERSION_CPP).$(SHARED_EXT_CPP) $(LIBGRPC++_TEST_OBJS) $(ZLIB_MERGE_LIBS) $(CARES_MERGE_LIBS) $(ADDRESS_SORTING_MERGE_LIBS) $(LDLIBSXX) $(LDLIBS_PROTOBUF) $(LDLIBS) -lgrpc++ -lgrpc + $(Q) ln -sf $(SHARED_PREFIX)grpc++_test$(SHARED_VERSION_CPP).$(SHARED_EXT_CPP) $(LIBDIR)/$(CONFIG)/libgrpc++_test$(SHARED_VERSION_CPP).so.1 + $(Q) ln -sf $(SHARED_PREFIX)grpc++_test$(SHARED_VERSION_CPP).$(SHARED_EXT_CPP) $(LIBDIR)/$(CONFIG)/libgrpc++_test$(SHARED_VERSION_CPP).so +endif +endif + +endif + +endif + +ifneq ($(NO_SECURE),true) +ifneq ($(NO_DEPS),true) +-include $(LIBGRPC++_TEST_OBJS:.o=.dep) +endif +endif + + LIBGRPC++_TEST_CONFIG_SRC = \ test/cpp/util/test_config_cc.cc \ diff --git a/build.yaml b/build.yaml index dc5fd4236da..f1610d4711d 100644 --- a/build.yaml +++ b/build.yaml @@ -610,15 +610,6 @@ filegroups: - name: grpc++_reflection_proto src: - src/proto/grpc/reflection/v1alpha/reflection.proto -- name: grpc++_test - public_headers: - - include/grpc++/test/mock_stream.h - - include/grpc++/test/server_context_test_spouse.h - - include/grpcpp/test/mock_stream.h - - include/grpcpp/test/server_context_test_spouse.h - deps: - - grpc++ - - grpc - name: grpc_base src: - src/core/lib/avl/avl.cc @@ -1897,6 +1888,17 @@ libs: - grpc filegroups: - grpc++_reflection_proto +- name: grpc++_test + build: all + language: c++ + public_headers: + - include/grpc++/test/mock_stream.h + - include/grpc++/test/server_context_test_spouse.h + - include/grpcpp/test/mock_stream.h + - include/grpcpp/test/server_context_test_spouse.h + deps: + - grpc++ + - grpc - name: grpc++_test_config build: private language: c++ diff --git a/grpc.gyp b/grpc.gyp index b0168dc15df..56ae8d21fa8 100644 --- a/grpc.gyp +++ b/grpc.gyp @@ -1678,6 +1678,16 @@ 'src/proto/grpc/reflection/v1alpha/reflection.proto', ], }, + { + 'target_name': 'grpc++_test', + 'type': 'static_library', + 'dependencies': [ + 'grpc++', + 'grpc', + ], + 'sources': [ + ], + }, { 'target_name': 'grpc++_test_config', 'type': 'static_library', From e2464b8eba3fcd6a8958e1271a50e04b1a03b77f Mon Sep 17 00:00:00 2001 From: Pau Freixes Date: Wed, 25 Sep 2019 23:17:42 +0200 Subject: [PATCH 06/60] Rename gevent_util file Since functions implemented by `gevent_util.h` are used also by the new experimental `Aio` module, the file holding these functions needs to be renamed to something more meaningful. --- BUILD | 2 +- src/core/lib/iomgr/{gevent_util.h => python_util.h} | 8 ++++---- src/python/grpcio/grpc/_cython/_cygrpc/iomgr.pxd.pxi | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) rename src/core/lib/iomgr/{gevent_util.h => python_util.h} (85%) diff --git a/BUILD b/BUILD index 080f5331e87..c94bebcbb13 100644 --- a/BUILD +++ b/BUILD @@ -855,7 +855,7 @@ grpc_cc_library( "src/core/lib/iomgr/executor/mpmcqueue.h", "src/core/lib/iomgr/executor/threadpool.h", "src/core/lib/iomgr/gethostname.h", - "src/core/lib/iomgr/gevent_util.h", + "src/core/lib/iomgr/python_util.h", "src/core/lib/iomgr/grpc_if_nametoindex.h", "src/core/lib/iomgr/internal_errqueue.h", "src/core/lib/iomgr/iocp_windows.h", diff --git a/src/core/lib/iomgr/gevent_util.h b/src/core/lib/iomgr/python_util.h similarity index 85% rename from src/core/lib/iomgr/gevent_util.h rename to src/core/lib/iomgr/python_util.h index de30543e3a3..42174ab8d86 100644 --- a/src/core/lib/iomgr/gevent_util.h +++ b/src/core/lib/iomgr/python_util.h @@ -16,8 +16,8 @@ * */ -#ifndef GRPC_CORE_LIB_IOMGR_GEVENT_UTIL_H -#define GRPC_CORE_LIB_IOMGR_GEVENT_UTIL_H +#ifndef GRPC_CORE_LIB_IOMGR_PYTHON_UTIL_H +#define GRPC_CORE_LIB_IOMGR_PYTHON_UTIL_H #include @@ -25,8 +25,8 @@ #include #include "src/core/lib/iomgr/error.h" -// These are only used by the gRPC Python extension for gevent -// support. They are easier to define here (rather than in Cython) +// These are only used by the gRPC Python extensions. +// They are easier to define here (rather than in Cython) // because Cython doesn't handle #defines well. grpc_error* grpc_socket_error(char* error) { diff --git a/src/python/grpcio/grpc/_cython/_cygrpc/iomgr.pxd.pxi b/src/python/grpcio/grpc/_cython/_cygrpc/iomgr.pxd.pxi index 2f00bab3c0a..11ac401bfe4 100644 --- a/src/python/grpcio/grpc/_cython/_cygrpc/iomgr.pxd.pxi +++ b/src/python/grpcio/grpc/_cython/_cygrpc/iomgr.pxd.pxi @@ -23,7 +23,7 @@ cdef extern from "src/core/lib/iomgr/error.h": # TODO(https://github.com/grpc/grpc/issues/20135) Change the filename # for something more meaningful. -cdef extern from "src/core/lib/iomgr/gevent_util.h": +cdef extern from "src/core/lib/iomgr/python_util.h": grpc_error* grpc_socket_error(char* error) char* grpc_slice_buffer_start(grpc_slice_buffer* buffer, int i) int grpc_slice_buffer_length(grpc_slice_buffer* buffer, int i) From c8cc5a324f1d26130b78b932d4bd74814b79c654 Mon Sep 17 00:00:00 2001 From: jeffreyqw <49655798+jeffreyqw@users.noreply.github.com> Date: Thu, 26 Sep 2019 15:51:03 -0700 Subject: [PATCH 07/60] Update README.md The php56-grpc extension has been removed from Homebrew --- src/php/README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/src/php/README.md b/src/php/README.md index 0b8727ca864..be7bf47603f 100644 --- a/src/php/README.md +++ b/src/php/README.md @@ -43,7 +43,6 @@ $ sudo yum install php56w php56w-devel php-pear phpunit gcc zlib-devel **Install PHP and PECL on Mac:** ```sh -$ brew install homebrew/php/php56-grpc $ curl -O http://pear.php.net/go-pear.phar $ sudo php -d detect_unicode=0 go-pear.phar ``` From 8de5245282d2f7ca530d85f305c9160461b6ee77 Mon Sep 17 00:00:00 2001 From: Esun Kim Date: Fri, 27 Sep 2019 14:56:49 -0700 Subject: [PATCH 08/60] Add v1.24.0 to interop_matrix --- tools/interop_matrix/client_matrix.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tools/interop_matrix/client_matrix.py b/tools/interop_matrix/client_matrix.py index 9a4b8cb76c6..aef372f0513 100644 --- a/tools/interop_matrix/client_matrix.py +++ b/tools/interop_matrix/client_matrix.py @@ -101,6 +101,7 @@ LANG_RELEASE_MATRIX = { ('v1.22.0', ReleaseInfo()), ('v1.22.1', ReleaseInfo()), ('v1.23.0', ReleaseInfo()), + ('v1.24.0', ReleaseInfo()), ]), 'go': OrderedDict( @@ -218,6 +219,7 @@ LANG_RELEASE_MATRIX = { ('v1.22.0', ReleaseInfo()), ('v1.22.1', ReleaseInfo()), ('v1.23.0', ReleaseInfo()), + ('v1.24.0', ReleaseInfo()), ]), 'node': OrderedDict([ @@ -270,6 +272,7 @@ LANG_RELEASE_MATRIX = { ('v1.22.0', ReleaseInfo()), ('v1.22.1', ReleaseInfo()), ('v1.23.0', ReleaseInfo()), + ('v1.24.0', ReleaseInfo()), # TODO: https://github.com/grpc/grpc/issues/18262. # If you are not encountering the error in above issue # go ahead and upload the docker image for new releases. @@ -300,6 +303,7 @@ LANG_RELEASE_MATRIX = { ('v1.22.0', ReleaseInfo()), ('v1.22.1', ReleaseInfo()), ('v1.23.0', ReleaseInfo()), + ('v1.24.0', ReleaseInfo()), ]), 'csharp': OrderedDict([ @@ -333,5 +337,6 @@ LANG_RELEASE_MATRIX = { ('v1.22.0', ReleaseInfo()), ('v1.22.1', ReleaseInfo()), ('v1.23.0', ReleaseInfo()), + ('v1.24.0', ReleaseInfo()), ]), } From d970489db285ff7a728dc0f14f889eecdc04de91 Mon Sep 17 00:00:00 2001 From: Jan Tattermusch Date: Mon, 16 Sep 2019 18:16:07 +0200 Subject: [PATCH 09/60] use no_windows for some C++ tests --- test/cpp/interop/BUILD | 1 + 1 file changed, 1 insertion(+) diff --git a/test/cpp/interop/BUILD b/test/cpp/interop/BUILD index e575ef88c5d..1b72a1a6dd7 100644 --- a/test/cpp/interop/BUILD +++ b/test/cpp/interop/BUILD @@ -44,6 +44,7 @@ grpc_cc_binary( "grpclb_fallback_test.cc", ], language = "C++", + tags = ["no_windows"], deps = [ "//src/proto/grpc/testing:empty_proto", "//src/proto/grpc/testing:messages_proto", From 068340381f80514b2eaac369bf816e5eca107d1c Mon Sep 17 00:00:00 2001 From: Jan Tattermusch Date: Tue, 17 Sep 2019 09:16:30 +0200 Subject: [PATCH 10/60] add uses_polling=False to selected core tests --- test/core/security/BUILD | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/core/security/BUILD b/test/core/security/BUILD index c6dbc5fbed8..06ded9fdbd8 100644 --- a/test/core/security/BUILD +++ b/test/core/security/BUILD @@ -177,6 +177,7 @@ grpc_cc_binary( "//:grpc", "//test/core/util:grpc_test_util", ], + uses_polling = False, ) grpc_cc_binary( @@ -201,6 +202,7 @@ grpc_cc_binary( "//:grpc", "//test/core/util:grpc_test_util", ], + uses_polling = False, ) grpc_cc_test( From 85117cbf6168d8266a19b2cc241802dabee14ef6 Mon Sep 17 00:00:00 2001 From: Jan Tattermusch Date: Tue, 17 Sep 2019 09:16:57 +0200 Subject: [PATCH 11/60] add uses_polling=False to selected c++ tests --- test/cpp/codegen/BUILD | 1 + 1 file changed, 1 insertion(+) diff --git a/test/cpp/codegen/BUILD b/test/cpp/codegen/BUILD index 69d5859489f..c8208ec0851 100644 --- a/test/cpp/codegen/BUILD +++ b/test/cpp/codegen/BUILD @@ -71,6 +71,7 @@ grpc_cc_binary( "//test/core/util:grpc_test_util", "//test/cpp/util:test_config", ], + uses_polling = False, ) genrule( From e682b323403466ba6f31f435b0055ea53861ea1b Mon Sep 17 00:00:00 2001 From: Jan Tattermusch Date: Tue, 17 Sep 2019 09:26:54 +0200 Subject: [PATCH 12/60] fixup core uses-polling --- test/core/security/BUILD | 2 -- 1 file changed, 2 deletions(-) diff --git a/test/core/security/BUILD b/test/core/security/BUILD index 06ded9fdbd8..c6dbc5fbed8 100644 --- a/test/core/security/BUILD +++ b/test/core/security/BUILD @@ -177,7 +177,6 @@ grpc_cc_binary( "//:grpc", "//test/core/util:grpc_test_util", ], - uses_polling = False, ) grpc_cc_binary( @@ -202,7 +201,6 @@ grpc_cc_binary( "//:grpc", "//test/core/util:grpc_test_util", ], - uses_polling = False, ) grpc_cc_test( From 93d2cf299fc19c92b60e0b9037718747ea9f9001 Mon Sep 17 00:00:00 2001 From: Jan Tattermusch Date: Tue, 17 Sep 2019 09:27:34 +0200 Subject: [PATCH 13/60] fixup cpp uses-polling --- test/cpp/codegen/BUILD | 1 - 1 file changed, 1 deletion(-) diff --git a/test/cpp/codegen/BUILD b/test/cpp/codegen/BUILD index c8208ec0851..69d5859489f 100644 --- a/test/cpp/codegen/BUILD +++ b/test/cpp/codegen/BUILD @@ -71,7 +71,6 @@ grpc_cc_binary( "//test/core/util:grpc_test_util", "//test/cpp/util:test_config", ], - uses_polling = False, ) genrule( From 6f6fe451be700d9f1c526b54f89d96be2923e48c Mon Sep 17 00:00:00 2001 From: Jan Tattermusch Date: Tue, 17 Sep 2019 10:02:14 +0200 Subject: [PATCH 14/60] run tests on win RBE --- tools/internal_ci/windows/bazel_rbe.bat | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/internal_ci/windows/bazel_rbe.bat b/tools/internal_ci/windows/bazel_rbe.bat index 86dcc74c429..7ce197d9b3c 100644 --- a/tools/internal_ci/windows/bazel_rbe.bat +++ b/tools/internal_ci/windows/bazel_rbe.bat @@ -24,7 +24,7 @@ powershell -Command "[guid]::NewGuid().ToString()" >%KOKORO_ARTIFACTS_DIR%/bazel set /p BAZEL_INVOCATION_ID=<%KOKORO_ARTIFACTS_DIR%/bazel_invocation_ids @rem TODO(jtattermusch): windows RBE should be able to use the same credentials as Linux RBE. -bazel --bazelrc=tools/remote_build/windows.bazelrc build --invocation_id="%BAZEL_INVOCATION_ID%" --workspace_status_command=tools/remote_build/workspace_status_kokoro.sh :all --google_credentials=%KOKORO_GFILE_DIR%/rbe-windows-credentials.json +bazel --bazelrc=tools/remote_build/windows.bazelrc test --invocation_id="%BAZEL_INVOCATION_ID%" --workspace_status_command=tools/remote_build/workspace_status_kokoro.sh --google_credentials=%KOKORO_GFILE_DIR%/rbe-windows-credentials.json //test/... set BAZEL_EXITCODE=%errorlevel% @rem TODO(jtattermusch): upload results to bigquery From 16f4103269878601926bdcb64ebdb2c19ce20ca8 Mon Sep 17 00:00:00 2001 From: Jan Tattermusch Date: Tue, 17 Sep 2019 10:30:29 +0200 Subject: [PATCH 15/60] try running only one test --- tools/internal_ci/windows/bazel_rbe.bat | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/internal_ci/windows/bazel_rbe.bat b/tools/internal_ci/windows/bazel_rbe.bat index 7ce197d9b3c..818ad8cb1c9 100644 --- a/tools/internal_ci/windows/bazel_rbe.bat +++ b/tools/internal_ci/windows/bazel_rbe.bat @@ -24,7 +24,7 @@ powershell -Command "[guid]::NewGuid().ToString()" >%KOKORO_ARTIFACTS_DIR%/bazel set /p BAZEL_INVOCATION_ID=<%KOKORO_ARTIFACTS_DIR%/bazel_invocation_ids @rem TODO(jtattermusch): windows RBE should be able to use the same credentials as Linux RBE. -bazel --bazelrc=tools/remote_build/windows.bazelrc test --invocation_id="%BAZEL_INVOCATION_ID%" --workspace_status_command=tools/remote_build/workspace_status_kokoro.sh --google_credentials=%KOKORO_GFILE_DIR%/rbe-windows-credentials.json //test/... +bazel --bazelrc=tools/remote_build/windows.bazelrc test --invocation_id="%BAZEL_INVOCATION_ID%" --workspace_status_command=tools/remote_build/workspace_status_kokoro.sh --google_credentials=%KOKORO_GFILE_DIR%/rbe-windows-credentials.json //test/core/gpr:log_test set BAZEL_EXITCODE=%errorlevel% @rem TODO(jtattermusch): upload results to bigquery From c6f18ce6c57c245bb48dd2b3dc014e2bb3e0cb6a Mon Sep 17 00:00:00 2001 From: Jan Tattermusch Date: Tue, 17 Sep 2019 11:21:09 +0200 Subject: [PATCH 16/60] make Win RBE test pass --- tools/remote_build/windows.bazelrc | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tools/remote_build/windows.bazelrc b/tools/remote_build/windows.bazelrc index e9b418f9837..daf58072ecc 100644 --- a/tools/remote_build/windows.bazelrc +++ b/tools/remote_build/windows.bazelrc @@ -34,6 +34,9 @@ build --define GRPC_PORT_ISOLATED_RUNTIME=1 build --test_tag_filters=-no_windows build --build_tag_filters=-no_windows +# required for the tests to pass on Windows RBE +build --incompatible_windows_native_test_wrapper + # without verbose gRPC logs the test outputs are not very useful test --test_env=GRPC_VERBOSITY=debug From f35678e3b42c1fbc0e363257b4f6e0a6e4edd01a Mon Sep 17 00:00:00 2001 From: Jan Tattermusch Date: Tue, 17 Sep 2019 11:38:30 +0200 Subject: [PATCH 17/60] run at least core tests --- tools/internal_ci/windows/bazel_rbe.bat | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/internal_ci/windows/bazel_rbe.bat b/tools/internal_ci/windows/bazel_rbe.bat index 818ad8cb1c9..a975402e992 100644 --- a/tools/internal_ci/windows/bazel_rbe.bat +++ b/tools/internal_ci/windows/bazel_rbe.bat @@ -24,7 +24,7 @@ powershell -Command "[guid]::NewGuid().ToString()" >%KOKORO_ARTIFACTS_DIR%/bazel set /p BAZEL_INVOCATION_ID=<%KOKORO_ARTIFACTS_DIR%/bazel_invocation_ids @rem TODO(jtattermusch): windows RBE should be able to use the same credentials as Linux RBE. -bazel --bazelrc=tools/remote_build/windows.bazelrc test --invocation_id="%BAZEL_INVOCATION_ID%" --workspace_status_command=tools/remote_build/workspace_status_kokoro.sh --google_credentials=%KOKORO_GFILE_DIR%/rbe-windows-credentials.json //test/core/gpr:log_test +bazel --bazelrc=tools/remote_build/windows.bazelrc test --invocation_id="%BAZEL_INVOCATION_ID%" --workspace_status_command=tools/remote_build/workspace_status_kokoro.sh --google_credentials=%KOKORO_GFILE_DIR%/rbe-windows-credentials.json //test/core/... set BAZEL_EXITCODE=%errorlevel% @rem TODO(jtattermusch): upload results to bigquery From 5b9e08d9a33a6db024377491c389b1d5ca6fe75a Mon Sep 17 00:00:00 2001 From: Jan Tattermusch Date: Mon, 23 Sep 2019 09:24:58 +0200 Subject: [PATCH 18/60] try updating bazel toolchains --- bazel/grpc_deps.bzl | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/bazel/grpc_deps.bzl b/bazel/grpc_deps.bzl index 01b9ffc9a0e..fcc8077c035 100644 --- a/bazel/grpc_deps.bzl +++ b/bazel/grpc_deps.bzl @@ -174,13 +174,14 @@ def grpc_deps(): ) if "bazel_toolchains" not in native.existing_rules(): + # list of releases is at https://releases.bazel.build/bazel-toolchains.html http_archive( name = "bazel_toolchains", - sha256 = "872955b658113924eb1a3594b04d43238da47f4f90c17b76e8785709490dc041", - strip_prefix = "bazel-toolchains-1083686fde6032378d52b4c98044922cebde364e", + sha256 = "22ca5b8115c8673ecb627a02b606529e813961e447933863fccdf325cc5f999f", + strip_prefix = "bazel-toolchains-0.29.5", urls = [ - "https://mirror.bazel.build/github.com/bazelbuild/bazel-toolchains/archive/1083686fde6032378d52b4c98044922cebde364e.tar.gz", - "https://github.com/bazelbuild/bazel-toolchains/archive/1083686fde6032378d52b4c98044922cebde364e.tar.gz", + "https://github.com/bazelbuild/bazel-toolchains/releases/download/0.29.5/bazel-toolchains-0.29.5.tar.gz", + "https://mirror.bazel.build/github.com/bazelbuild/bazel-toolchains/archive/0.29.5.tar.gz", ], ) From 0f78b92e876db22a3ed8912597729c6f32ebc457 Mon Sep 17 00:00:00 2001 From: Jan Tattermusch Date: Fri, 27 Sep 2019 11:22:58 +0200 Subject: [PATCH 19/60] avoid machine_size:large tests on windows --- test/core/gprpp/BUILD | 1 + test/core/iomgr/BUILD | 1 + test/cpp/qps/BUILD | 1 + 3 files changed, 3 insertions(+) diff --git a/test/core/gprpp/BUILD b/test/core/gprpp/BUILD index 0b0236334b2..5be49b77518 100644 --- a/test/core/gprpp/BUILD +++ b/test/core/gprpp/BUILD @@ -125,6 +125,7 @@ grpc_cc_test( srcs = ["mpscq_test.cc"], exec_compatible_with = ["//third_party/toolchains/machine_size:large"], language = "C++", + tags = ["no_windows"], # machine_size:large is not configured for windows RBE deps = [ "//:gpr", "//test/core/util:grpc_test_util", diff --git a/test/core/iomgr/BUILD b/test/core/iomgr/BUILD index 7e4cdc0d729..0025ef334bd 100644 --- a/test/core/iomgr/BUILD +++ b/test/core/iomgr/BUILD @@ -41,6 +41,7 @@ grpc_cc_test( srcs = ["combiner_test.cc"], exec_compatible_with = ["//third_party/toolchains/machine_size:large"], language = "C++", + tags = ["no_windows"], # machine_size:large is not configured for windows RBE deps = [ "//:gpr", "//:grpc", diff --git a/test/cpp/qps/BUILD b/test/cpp/qps/BUILD index 5c84d75dc5f..433b0b32c75 100644 --- a/test/cpp/qps/BUILD +++ b/test/cpp/qps/BUILD @@ -170,6 +170,7 @@ grpc_cc_test( name = "qps_openloop_test", srcs = ["qps_openloop_test.cc"], exec_compatible_with = ["//third_party/toolchains/machine_size:large"], + tags = ["no_windows"], # machine_size:large is not configured for windows RBE deps = [ ":benchmark_config", ":driver_impl", From 0f50bf015036028eafea4e0523b97d9efdc9d0d3 Mon Sep 17 00:00:00 2001 From: Jan Tattermusch Date: Fri, 27 Sep 2019 11:56:44 +0200 Subject: [PATCH 20/60] temporarily disable memory usage test on windows --- test/core/memory_usage/BUILD | 1 + 1 file changed, 1 insertion(+) diff --git a/test/core/memory_usage/BUILD b/test/core/memory_usage/BUILD index c9da6b4241b..0949c89ed9e 100644 --- a/test/core/memory_usage/BUILD +++ b/test/core/memory_usage/BUILD @@ -49,6 +49,7 @@ grpc_cc_test( ":memory_usage_server", ], language = "C++", + tags = ["no_windows"], # TODO(jtattermusch): breaks windows RBE build if enabled deps = [ "//:gpr", "//:grpc", From 14a2b7b05c08bb19d3185eefdc88020b8f32bdba Mon Sep 17 00:00:00 2001 From: Jan Tattermusch Date: Fri, 27 Sep 2019 12:04:12 +0200 Subject: [PATCH 21/60] disable fork bazel test on windows --- test/core/gprpp/BUILD | 1 + 1 file changed, 1 insertion(+) diff --git a/test/core/gprpp/BUILD b/test/core/gprpp/BUILD index 5be49b77518..2144b276c5a 100644 --- a/test/core/gprpp/BUILD +++ b/test/core/gprpp/BUILD @@ -22,6 +22,7 @@ grpc_cc_test( name = "fork_test", srcs = ["fork_test.cc"], language = "C++", + tags = ["no_windows"], deps = [ "//:gpr", "//test/core/util:grpc_test_util", From 8d81a934cad7dbd598cab0321bff84bcaa7ebfcb Mon Sep 17 00:00:00 2001 From: Jan Tattermusch Date: Fri, 27 Sep 2019 12:25:55 +0200 Subject: [PATCH 22/60] run both C and C++ tests on win RBE --- tools/internal_ci/windows/bazel_rbe.bat | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/internal_ci/windows/bazel_rbe.bat b/tools/internal_ci/windows/bazel_rbe.bat index a975402e992..7ce197d9b3c 100644 --- a/tools/internal_ci/windows/bazel_rbe.bat +++ b/tools/internal_ci/windows/bazel_rbe.bat @@ -24,7 +24,7 @@ powershell -Command "[guid]::NewGuid().ToString()" >%KOKORO_ARTIFACTS_DIR%/bazel set /p BAZEL_INVOCATION_ID=<%KOKORO_ARTIFACTS_DIR%/bazel_invocation_ids @rem TODO(jtattermusch): windows RBE should be able to use the same credentials as Linux RBE. -bazel --bazelrc=tools/remote_build/windows.bazelrc test --invocation_id="%BAZEL_INVOCATION_ID%" --workspace_status_command=tools/remote_build/workspace_status_kokoro.sh --google_credentials=%KOKORO_GFILE_DIR%/rbe-windows-credentials.json //test/core/... +bazel --bazelrc=tools/remote_build/windows.bazelrc test --invocation_id="%BAZEL_INVOCATION_ID%" --workspace_status_command=tools/remote_build/workspace_status_kokoro.sh --google_credentials=%KOKORO_GFILE_DIR%/rbe-windows-credentials.json //test/... set BAZEL_EXITCODE=%errorlevel% @rem TODO(jtattermusch): upload results to bigquery From b8a32c0cffba8a42099e5ff99140ac1b8e176172 Mon Sep 17 00:00:00 2001 From: Jan Tattermusch Date: Fri, 27 Sep 2019 12:32:16 +0200 Subject: [PATCH 23/60] temporarily disable failing tests on windows --- test/core/gprpp/BUILD | 1 + test/core/transport/BUILD | 1 + 2 files changed, 2 insertions(+) diff --git a/test/core/gprpp/BUILD b/test/core/gprpp/BUILD index 2144b276c5a..193ef5e410a 100644 --- a/test/core/gprpp/BUILD +++ b/test/core/gprpp/BUILD @@ -51,6 +51,7 @@ grpc_cc_test( "gtest", ], language = "C++", + tags = ["no_windows"], # TODO(jtattermusch): fix the failure on windows deps = [ "//:gpr", "//test/core/util:grpc_test_util", diff --git a/test/core/transport/BUILD b/test/core/transport/BUILD index 12e748f7d10..078d573b86d 100644 --- a/test/core/transport/BUILD +++ b/test/core/transport/BUILD @@ -25,6 +25,7 @@ grpc_cc_test( "gtest", ], language = "C++", + tags = ["no_windows"], # TODO(jtattermusch): investigate the timeout on windows deps = [ "//:gpr", "//:grpc", From 1ba59b879e90765b239639c2c87059fe5c2a19dc Mon Sep 17 00:00:00 2001 From: Jan Tattermusch Date: Fri, 27 Sep 2019 12:36:15 +0200 Subject: [PATCH 24/60] update windows RBE instructions --- tools/remote_build/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/remote_build/README.md b/tools/remote_build/README.md index 68d68400577..edf771dd184 100644 --- a/tools/remote_build/README.md +++ b/tools/remote_build/README.md @@ -31,8 +31,8 @@ bazel --bazelrc=tools/remote_build/manual.bazelrc test --config=asan //test/... Run on Windows MSVC: ``` -# RBE manual run only for c-core (must be run on a Windows host machine) -bazel --bazelrc=tools/remote_build/windows.bazelrc build :all +# manual run of bazel tests remotely on RBE Windows (must be run from Windows machine) +bazel --bazelrc=tools/remote_build/windows.bazelrc test //test/... ``` Available command line options can be found in From 8e79705d29c62ed0d658929042b0874039df755c Mon Sep 17 00:00:00 2001 From: Jan Tattermusch Date: Fri, 27 Sep 2019 16:52:27 +0200 Subject: [PATCH 25/60] disable fuzzers on windows --- test/core/client_channel/BUILD | 1 + test/core/end2end/fuzzers/BUILD | 3 +++ test/core/http/BUILD | 2 ++ test/core/json/BUILD | 1 + test/core/nanopb/BUILD | 2 ++ test/core/security/BUILD | 2 ++ test/core/slice/BUILD | 2 ++ test/core/transport/chttp2/BUILD | 1 + 8 files changed, 14 insertions(+) diff --git a/test/core/client_channel/BUILD b/test/core/client_channel/BUILD index cafd6101ffc..4740f3cca7c 100644 --- a/test/core/client_channel/BUILD +++ b/test/core/client_channel/BUILD @@ -30,6 +30,7 @@ grpc_fuzzer( "//:grpc", "//test/core/util:grpc_test_util", ], + tags = ["no_windows"], ) grpc_cc_test( diff --git a/test/core/end2end/fuzzers/BUILD b/test/core/end2end/fuzzers/BUILD index c12cfc6983f..70aec59b10a 100644 --- a/test/core/end2end/fuzzers/BUILD +++ b/test/core/end2end/fuzzers/BUILD @@ -33,6 +33,7 @@ grpc_fuzzer( "//test/core/end2end:ssl_test_data", "//test/core/util:grpc_test_util", ], + tags = ["no_windows"], ) grpc_fuzzer( @@ -45,6 +46,7 @@ grpc_fuzzer( "//:grpc", "//test/core/util:grpc_test_util", ], + tags = ["no_windows"], ) grpc_fuzzer( @@ -57,4 +59,5 @@ grpc_fuzzer( "//:grpc", "//test/core/util:grpc_test_util", ], + tags = ["no_windows"], ) diff --git a/test/core/http/BUILD b/test/core/http/BUILD index 8951d1aba2e..7e3f57d82df 100644 --- a/test/core/http/BUILD +++ b/test/core/http/BUILD @@ -30,6 +30,7 @@ grpc_fuzzer( "//:grpc", "//test/core/util:grpc_test_util", ], + tags = ["no_windows"], ) grpc_fuzzer( @@ -42,6 +43,7 @@ grpc_fuzzer( "//:grpc", "//test/core/util:grpc_test_util", ], + tags = ["no_windows"], ) # Copyright 2017 gRPC authors. diff --git a/test/core/json/BUILD b/test/core/json/BUILD index c9298e5f2c4..198a24c6301 100644 --- a/test/core/json/BUILD +++ b/test/core/json/BUILD @@ -30,6 +30,7 @@ grpc_fuzzer( "//:grpc", "//test/core/util:grpc_test_util", ], + tags = ["no_windows"], ) grpc_cc_binary( diff --git a/test/core/nanopb/BUILD b/test/core/nanopb/BUILD index 1497f829ab6..6836e56ce31 100644 --- a/test/core/nanopb/BUILD +++ b/test/core/nanopb/BUILD @@ -30,6 +30,7 @@ grpc_fuzzer( "//:grpc", "//test/core/util:grpc_test_util", ], + tags = ["no_windows"], ) grpc_fuzzer( @@ -42,4 +43,5 @@ grpc_fuzzer( "//:grpc", "//test/core/util:grpc_test_util", ], + tags = ["no_windows"], ) diff --git a/test/core/security/BUILD b/test/core/security/BUILD index c6dbc5fbed8..f755cde9407 100644 --- a/test/core/security/BUILD +++ b/test/core/security/BUILD @@ -30,6 +30,7 @@ grpc_fuzzer( "//:grpc", "//test/core/util:grpc_test_util", ], + tags = ["no_windows"], ) grpc_fuzzer( @@ -43,6 +44,7 @@ grpc_fuzzer( "//test/core/end2end:ssl_test_data", "//test/core/util:grpc_test_util", ], + tags = ["no_windows"], ) grpc_cc_library( diff --git a/test/core/slice/BUILD b/test/core/slice/BUILD index dbca3477131..e02267276d1 100644 --- a/test/core/slice/BUILD +++ b/test/core/slice/BUILD @@ -30,6 +30,7 @@ grpc_fuzzer( "//:grpc", "//test/core/util:grpc_test_util", ], + tags = ["no_windows"], ) grpc_fuzzer( @@ -42,6 +43,7 @@ grpc_fuzzer( "//:grpc", "//test/core/util:grpc_test_util", ], + tags = ["no_windows"], ) grpc_cc_test( diff --git a/test/core/transport/chttp2/BUILD b/test/core/transport/chttp2/BUILD index f31ba248d19..c80aadb6ed6 100644 --- a/test/core/transport/chttp2/BUILD +++ b/test/core/transport/chttp2/BUILD @@ -28,6 +28,7 @@ grpc_fuzzer( "//:grpc", "//test/core/util:grpc_test_util", ], + tags = ["no_windows"], ) grpc_cc_test( From 3080419c9046c24e666edd99d8eb80c4c1fae352 Mon Sep 17 00:00:00 2001 From: Jan Tattermusch Date: Mon, 30 Sep 2019 08:29:37 +0200 Subject: [PATCH 26/60] temporarily disable alarm_test --- test/cpp/common/BUILD | 1 + 1 file changed, 1 insertion(+) diff --git a/test/cpp/common/BUILD b/test/cpp/common/BUILD index ac82acc073e..d8128d76173 100644 --- a/test/cpp/common/BUILD +++ b/test/cpp/common/BUILD @@ -24,6 +24,7 @@ grpc_cc_test( external_deps = [ "gtest", ], + tags = ["no_windows"], # TODO(jtattermusch): fix test on windows RBE deps = [ "//:grpc++_unsecure", "//test/core/util:grpc_test_util_unsecure", From 3ce50ae7545050fe890120caf08409a4c6812b86 Mon Sep 17 00:00:00 2001 From: Jan Tattermusch Date: Mon, 30 Sep 2019 12:45:18 +0200 Subject: [PATCH 27/60] disable some test on windows based on build.yaml --- test/core/bad_ssl/generate_tests.bzl | 1 + test/core/end2end/BUILD | 1 + test/core/fling/BUILD | 2 ++ test/core/handshake/BUILD | 1 + test/core/http/BUILD | 2 ++ test/core/tsi/BUILD | 1 + test/cpp/end2end/BUILD | 4 ++-- 7 files changed, 10 insertions(+), 2 deletions(-) diff --git a/test/core/bad_ssl/generate_tests.bzl b/test/core/bad_ssl/generate_tests.bzl index 22e7d3a692e..f2060125326 100755 --- a/test/core/bad_ssl/generate_tests.bzl +++ b/test/core/bad_ssl/generate_tests.bzl @@ -46,4 +46,5 @@ def grpc_bad_ssl_tests(): deps = ['//test/core/util:grpc_test_util', '//:gpr', '//test/core/end2end:cq_verifier'], + tags = ["no_windows"], ) diff --git a/test/core/end2end/BUILD b/test/core/end2end/BUILD index d13894050ff..a810f35cd20 100644 --- a/test/core/end2end/BUILD +++ b/test/core/end2end/BUILD @@ -117,6 +117,7 @@ grpc_cc_test( "//:grpc", "//test/core/util:grpc_test_util", ], + tags = ["no_windows"], ) grpc_cc_test( diff --git a/test/core/fling/BUILD b/test/core/fling/BUILD index 0c16b2a8799..078eed59aed 100644 --- a/test/core/fling/BUILD +++ b/test/core/fling/BUILD @@ -59,6 +59,7 @@ grpc_cc_test( "//test/core/end2end:ssl_test_data", "//test/core/util:grpc_test_util", ], + tags = ["no_windows], ) grpc_cc_test( @@ -74,4 +75,5 @@ grpc_cc_test( "//test/core/end2end:ssl_test_data", "//test/core/util:grpc_test_util", ], + tags = ["no_windows], ) diff --git a/test/core/handshake/BUILD b/test/core/handshake/BUILD index 0824efb980f..96a71ca6440 100644 --- a/test/core/handshake/BUILD +++ b/test/core/handshake/BUILD @@ -97,4 +97,5 @@ grpc_cc_test( "//:grpc", "//test/core/util:grpc_test_util", ], + tags = ["no_windows"], ) diff --git a/test/core/http/BUILD b/test/core/http/BUILD index 7e3f57d82df..73b9ff0573e 100644 --- a/test/core/http/BUILD +++ b/test/core/http/BUILD @@ -80,6 +80,7 @@ grpc_cc_test( "//test/core/end2end:ssl_test_data", "//test/core/util:grpc_test_util", ], + tags = ["no_windows"], ) grpc_cc_test( @@ -99,6 +100,7 @@ grpc_cc_test( "//test/core/end2end:ssl_test_data", "//test/core/util:grpc_test_util", ], + tags = ["no_windows"], ) grpc_cc_test( diff --git a/test/core/tsi/BUILD b/test/core/tsi/BUILD index e9faf5c99f3..223452df1ed 100644 --- a/test/core/tsi/BUILD +++ b/test/core/tsi/BUILD @@ -85,6 +85,7 @@ grpc_cc_test( "//:tsi", "//test/core/util:grpc_test_util", ], + tags = ["no_windows"], ) grpc_cc_test( diff --git a/test/cpp/end2end/BUILD b/test/cpp/end2end/BUILD index 3a0786b8d15..06395f2654f 100644 --- a/test/cpp/end2end/BUILD +++ b/test/cpp/end2end/BUILD @@ -122,7 +122,7 @@ grpc_cc_test( "//test/core/util:grpc_test_util", "//test/cpp/util:test_util", ], - tags = ["no_test_ios"], + tags = ["no_test_ios", "no_windows"], ) grpc_cc_binary( @@ -567,7 +567,7 @@ grpc_cc_test( "//test/core/util:grpc_test_util", "//test/cpp/util:test_util", ], - tags = ["no_test_ios"], + tags = ["no_test_ios", "no_windows"], ) grpc_cc_binary( From 5cc45de44388b920b362c4c3f505cff83fecf2ba Mon Sep 17 00:00:00 2001 From: Jan Tattermusch Date: Mon, 30 Sep 2019 13:22:11 +0200 Subject: [PATCH 28/60] disable some broken test on windows RBE --- test/cpp/end2end/BUILD | 6 +++++- test/cpp/ext/filters/census/BUILD | 1 + test/cpp/util/BUILD | 3 ++- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/test/cpp/end2end/BUILD b/test/cpp/end2end/BUILD index 06395f2654f..7139548f803 100644 --- a/test/cpp/end2end/BUILD +++ b/test/cpp/end2end/BUILD @@ -442,6 +442,7 @@ grpc_cc_test( "//test/core/util:test_lb_policies", "//test/cpp/util:test_util", ], + tags = ["no_windows"], # TODO(jtattermusch): fix test on windows ) grpc_cc_test( @@ -482,6 +483,7 @@ grpc_cc_test( "//test/core/util:grpc_test_util", "//test/cpp/util:test_util", ], + tags = ["no_windows"], # TODO(jtattermusch): fix test on windows ) grpc_cc_test( @@ -505,6 +507,7 @@ grpc_cc_test( "//test/core/util:grpc_test_util", "//test/cpp/util:test_util", ], + tags = ["no_windows"], # TODO(jtattermusch): fix test on windows ) grpc_cc_test( @@ -621,7 +624,7 @@ grpc_cc_test( "//src/proto/grpc/testing:echo_proto", "//test/cpp/util:test_util", ], - tags = ["no_test_ios"], + tags = ["no_test_ios", "no_windows"], ) grpc_cc_test( @@ -687,6 +690,7 @@ grpc_cc_test( external_deps = [ "gtest", ], + tags = ["no_windows"], # TODO(jtattermusch): fix test on windows deps = [ "//:gpr", "//:grpc", diff --git a/test/cpp/ext/filters/census/BUILD b/test/cpp/ext/filters/census/BUILD index 452a84b2a7a..08f702fa502 100644 --- a/test/cpp/ext/filters/census/BUILD +++ b/test/cpp/ext/filters/census/BUILD @@ -37,4 +37,5 @@ grpc_cc_test( "//test/cpp/util:test_config", "//test/cpp/util:test_util", ], + tags = ["no_windows"], # TODO(jtattermusch): fix test on windows ) diff --git a/test/cpp/util/BUILD b/test/cpp/util/BUILD index 2e9d1cc8bba..a3074c42e5c 100644 --- a/test/cpp/util/BUILD +++ b/test/cpp/util/BUILD @@ -188,7 +188,8 @@ grpc_cc_test( "gtest", ], tags = ["nomsan", # death tests seem to be incompatible with msan - "no_test_ios" + "no_test_ios", + "no_windows", ], deps = [ ":grpc_cli_libs", From 6c3ba9a3a8492cefe79ace0e81d795dcb725fb5d Mon Sep 17 00:00:00 2001 From: Jan Tattermusch Date: Mon, 30 Sep 2019 13:24:34 +0200 Subject: [PATCH 29/60] fixup fling BUILD --- test/core/fling/BUILD | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/core/fling/BUILD b/test/core/fling/BUILD index 078eed59aed..816a9091787 100644 --- a/test/core/fling/BUILD +++ b/test/core/fling/BUILD @@ -59,7 +59,7 @@ grpc_cc_test( "//test/core/end2end:ssl_test_data", "//test/core/util:grpc_test_util", ], - tags = ["no_windows], + tags = ["no_windows"], ) grpc_cc_test( @@ -75,5 +75,5 @@ grpc_cc_test( "//test/core/end2end:ssl_test_data", "//test/core/util:grpc_test_util", ], - tags = ["no_windows], + tags = ["no_windows"], ) From 3ece58172061ce13b4d722d5ab82b00f15817dd6 Mon Sep 17 00:00:00 2001 From: Jan Tattermusch Date: Mon, 30 Sep 2019 13:26:33 +0200 Subject: [PATCH 30/60] win RBE tests with uses_polling=True need to run as well --- bazel/grpc_build_system.bzl | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/bazel/grpc_build_system.bzl b/bazel/grpc_build_system.bzl index 5bf04f2ff0b..ed137285334 100644 --- a/bazel/grpc_build_system.bzl +++ b/bazel/grpc_build_system.bzl @@ -184,17 +184,17 @@ def grpc_cc_test(name, srcs = [], deps = [], external_deps = [], args = [], data "exec_compatible_with": exec_compatible_with, } if uses_polling: - # Only run targets with pollers for non-MSVC - # TODO(yfen): Enable MSVC for poller-enabled targets without pollers + # the vanilla version of the test should run on platforms that only + # support a single poller native.cc_test( name = name, testonly = True, - tags = [ - "manual", - "no_windows", - ], + tags = (tags + [ + "no_linux", # linux supports multiple pollers + ]), **args ) + # on linux we run the same test multiple times, once for each poller for poller in POLLERS: native.sh_test( name = name + "@poller=" + poller, @@ -208,10 +208,11 @@ def grpc_cc_test(name, srcs = [], deps = [], external_deps = [], args = [], data poller, "$(location %s)" % name, ] + args["args"], - tags = (tags + ["no_windows"]), + tags = (tags + ["no_windows", "no_mac"]), exec_compatible_with = exec_compatible_with, ) else: + # the test behavior doesn't depend on polling, just generate the test native.cc_test(name = name, tags = tags, **args) ios_cc_test( name = name, From dffece9657aa0008efa49674688615091e2dd9a1 Mon Sep 17 00:00:00 2001 From: Jan Tattermusch Date: Mon, 30 Sep 2019 17:37:37 +0200 Subject: [PATCH 31/60] make end2end bazel test generator work on non-linux as well --- test/core/end2end/generate_tests.bzl | 51 +++++++++++++++++++++++----- 1 file changed, 42 insertions(+), 9 deletions(-) diff --git a/test/core/end2end/generate_tests.bzl b/test/core/end2end/generate_tests.bzl index 85faca16364..218689343f9 100755 --- a/test/core/end2end/generate_tests.bzl +++ b/test/core/end2end/generate_tests.bzl @@ -46,7 +46,7 @@ def _fixture_options( supports_write_buffering = supports_write_buffering, client_channel = client_channel, supports_msvc = supports_msvc, - #_platforms=_platforms, + _platforms=_platforms, ) # maps fixture name to whether it requires the security library @@ -368,6 +368,16 @@ def _compatible(fopt, topt): return False return True +def _platform_support_tags(fopt): + result = [] + if not "windows" in fopt._platforms: + result += ["no_windows"] + if not "mac" in fopt._platforms: + result += ["no_mac"] + if not "linux" in fopt._platforms: + result += ["no_linux"] + return result + def grpc_end2end_tests(): grpc_cc_library( name = "end2end_tests", @@ -386,8 +396,7 @@ def grpc_end2end_tests(): ":http_proxy", ":proxy", ":local_util", - ], - tags = ["no_windows"], + ] ) for f, fopt in END2END_FIXTURES.items(): @@ -401,12 +410,25 @@ def grpc_end2end_tests(): "//:grpc", "//:gpr", ], - tags = ["no_windows"], + tags = _platform_support_tags(fopt), ) + for t, topt in END2END_TESTS.items(): #print(_compatible(fopt, topt), f, t, fopt, topt) if not _compatible(fopt, topt): continue + + native.sh_test( + name = "%s_test@%s" % (f, t), + data = [":%s_test" % f], + srcs = ["end2end_test.sh"], + args = [ + "$(location %s_test)" % f, + t + ], + tags = ["no_linux"] + _platform_support_tags(fopt), + ) + for poller in POLLERS: native.sh_test( name = "%s_test@%s@poller=%s" % (f, t, poller), @@ -417,7 +439,7 @@ def grpc_end2end_tests(): t, poller, ], - tags = ["no_windows"], + tags = ["no_mac", "no_windows"], ) def grpc_end2end_nosec_tests(): @@ -439,8 +461,7 @@ def grpc_end2end_nosec_tests(): ":http_proxy", ":proxy", ":local_util", - ], - tags = ["no_windows"], + ] ) for f, fopt in END2END_NOSEC_FIXTURES.items(): @@ -456,7 +477,7 @@ def grpc_end2end_nosec_tests(): "//:grpc_unsecure", "//:gpr", ], - tags = ["no_windows"], + tags = _platform_support_tags(fopt), ) for t, topt in END2END_TESTS.items(): #print(_compatible(fopt, topt), f, t, fopt, topt) @@ -464,6 +485,18 @@ def grpc_end2end_nosec_tests(): continue if topt.secure: continue + + native.sh_test( + name = "%s_nosec_test@%s" % (f, t), + data = [":%s_nosec_test" % f], + srcs = ["end2end_test.sh"], + args = [ + "$(location %s_nosec_test)" % f, + t + ], + tags = ["no_linux"] + _platform_support_tags(fopt), + ) + for poller in POLLERS: native.sh_test( name = "%s_nosec_test@%s@poller=%s" % (f, t, poller), @@ -474,5 +507,5 @@ def grpc_end2end_nosec_tests(): t, poller, ], - tags = ["no_windows"], + tags = ["no_mac", "no_windows"], ) From f81ef767d395be8172140c0fab9db2a3ee21ae37 Mon Sep 17 00:00:00 2001 From: Jan Tattermusch Date: Mon, 30 Sep 2019 17:41:13 +0200 Subject: [PATCH 32/60] filter out non-linux tests --- tools/remote_build/rbe_common.bazelrc | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/tools/remote_build/rbe_common.bazelrc b/tools/remote_build/rbe_common.bazelrc index 6236003fe17..568e7aec5fa 100644 --- a/tools/remote_build/rbe_common.bazelrc +++ b/tools/remote_build/rbe_common.bazelrc @@ -44,6 +44,11 @@ build --define GRPC_PORT_ISOLATED_RUNTIME=1 # without verbose gRPC logs the test outputs are not very useful test --test_env=GRPC_VERBOSITY=debug +# we assume the default bazel RBE build is on linux, +# so filter out stuff that should not be built or run there. +build --test_tag_filters=-no_linux +build --build_tag_filters=-no_linux + # Default test timeouts for all RBE tests (sanitizers override these values) # TODO(jtattermusch): revisit the non-standard test timeout values build --test_timeout=300,450,1200,3600 @@ -53,7 +58,7 @@ build --test_timeout=300,450,1200,3600 build:asan --copt=-gmlt # TODO(jtattermusch): use more reasonable test timeout build:asan --test_timeout=3600 -build:asan --test_tag_filters=-qps_json_driver +build:asan --test_tag_filters=-no_linux,-qps_json_driver # memory sanitizer: most settings are already in %workspace%/.bazelrc # we only need a few additional ones that are Foundry specific @@ -61,7 +66,7 @@ build:msan --copt=-gmlt # TODO(jtattermusch): use more reasonable test timeout build:msan --test_timeout=3600 # TODO(jtattermusch): revisit the disabled tests -build:msan --test_tag_filters=-nomsan,-json_run_localhost +build:msan --test_tag_filters=-no_linux,-nomsan,-json_run_localhost build:msan --cxxopt=--stdlib=libc++ # setting LD_LIBRARY_PATH is necessary # to avoid "libc++.so.1: cannot open shared object file" @@ -75,7 +80,7 @@ build:msan --crosstool_top=@rbe_msan//cc:toolchain build:tsan --copt=-gmlt # TODO(jtattermusch): use more reasonable test timeout build:tsan --test_timeout=3600 -build:tsan --test_tag_filters=-qps_json_driver +build:tsan --test_tag_filters=-no_linux,-qps_json_driver build:tsan --extra_execution_platforms=//third_party/toolchains:rbe_ubuntu1604,//third_party/toolchains:rbe_ubuntu1604_large # undefined behavior sanitizer: most settings are already in %workspace%/.bazelrc From 33f139b6e6446dec1f24723ffe7095bd68bec67a Mon Sep 17 00:00:00 2001 From: "Mark D. Roth" Date: Mon, 30 Sep 2019 09:32:32 -0700 Subject: [PATCH 33/60] Revert "Merge pull request #20255 from markdroth/transport_connectivity_state_watcher" This reverts commit 0f5a111aad5ec939c65428403924c0dfc692ea42, reversing changes made to 1276a8f628ae7609e1816f970ece233ac4b66e69. --- CMakeLists.txt | 73 +++--- Makefile | 84 +++---- build.yaml | 19 +- .../filters/client_channel/client_channel.cc | 235 ++++++++++-------- .../filters/client_channel/client_channel.h | 6 - .../client_channel/client_channel_channelz.cc | 5 +- .../client_channel/lb_policy/grpclb/grpclb.cc | 8 +- .../lb_policy/pick_first/pick_first.cc | 2 +- .../lb_policy/round_robin/round_robin.cc | 4 +- .../lb_policy/subchannel_list.h | 6 +- .../client_channel/lb_policy/xds/xds.cc | 6 +- .../client_channel/resolving_lb_policy.cc | 3 +- .../ext/filters/client_channel/subchannel.cc | 97 +++++--- .../ext/filters/client_channel/subchannel.h | 6 +- .../ext/filters/max_age/max_age_filter.cc | 82 +++--- .../chttp2/transport/chttp2_transport.cc | 31 +-- .../ext/transport/chttp2/transport/internal.h | 16 +- .../ext/transport/inproc/inproc_transport.cc | 23 +- src/core/lib/channel/channelz.cc | 3 +- src/core/lib/surface/lame_client.cc | 29 +-- src/core/lib/surface/server.cc | 63 ++--- src/core/lib/transport/connectivity_state.cc | 203 ++++++++------- src/core/lib/transport/connectivity_state.h | 140 ++++------- src/core/lib/transport/transport.h | 9 +- src/core/lib/transport/transport_op_string.cc | 25 +- test/core/surface/lame_client_test.cc | 32 +-- test/core/transport/BUILD | 3 - .../core/transport/connectivity_state_test.cc | 206 +++++++-------- tools/run_tests/generated/tests.json | 48 ++-- 29 files changed, 696 insertions(+), 771 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 518ca81c664..6ce00ecacdf 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -427,6 +427,7 @@ add_dependencies(buildtests_c time_averaged_stats_test) add_dependencies(buildtests_c timeout_encoding_test) add_dependencies(buildtests_c timer_heap_test) add_dependencies(buildtests_c timer_list_test) +add_dependencies(buildtests_c transport_connectivity_state_test) add_dependencies(buildtests_c transport_metadata_test) if(_gRPC_PLATFORM_LINUX OR _gRPC_PLATFORM_MAC OR _gRPC_PLATFORM_POSIX) add_dependencies(buildtests_c transport_security_test) @@ -725,7 +726,6 @@ if(_gRPC_PLATFORM_LINUX OR _gRPC_PLATFORM_MAC OR _gRPC_PLATFORM_POSIX) add_dependencies(buildtests_cxx time_change_test) endif() add_dependencies(buildtests_cxx timer_test) -add_dependencies(buildtests_cxx transport_connectivity_state_test) add_dependencies(buildtests_cxx transport_pid_controller_test) add_dependencies(buildtests_cxx transport_security_common_api_test) if(_gRPC_PLATFORM_LINUX OR _gRPC_PLATFORM_MAC OR _gRPC_PLATFORM_POSIX) @@ -9847,6 +9847,37 @@ target_link_libraries(timer_list_test ) +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(transport_connectivity_state_test + test/core/transport/connectivity_state_test.cc +) + + +target_include_directories(transport_connectivity_state_test + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${_gRPC_ADDRESS_SORTING_INCLUDE_DIR} + PRIVATE ${_gRPC_BENCHMARK_INCLUDE_DIR} + PRIVATE ${_gRPC_CARES_INCLUDE_DIR} + PRIVATE ${_gRPC_GFLAGS_INCLUDE_DIR} + PRIVATE ${_gRPC_PROTOBUF_INCLUDE_DIR} + PRIVATE ${_gRPC_SSL_INCLUDE_DIR} + PRIVATE ${_gRPC_UPB_GENERATED_DIR} + PRIVATE ${_gRPC_UPB_GRPC_GENERATED_DIR} + PRIVATE ${_gRPC_UPB_INCLUDE_DIR} + PRIVATE ${_gRPC_ZLIB_INCLUDE_DIR} +) + +target_link_libraries(transport_connectivity_state_test + ${_gRPC_ALLTARGETS_LIBRARIES} + grpc_test_util + grpc + gpr +) + + endif (gRPC_BUILD_TESTS) if (gRPC_BUILD_TESTS) @@ -16661,46 +16692,6 @@ target_link_libraries(timer_test ) -endif (gRPC_BUILD_TESTS) -if (gRPC_BUILD_TESTS) - -add_executable(transport_connectivity_state_test - test/core/transport/connectivity_state_test.cc - third_party/googletest/googletest/src/gtest-all.cc - third_party/googletest/googlemock/src/gmock-all.cc -) - - -target_include_directories(transport_connectivity_state_test - PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} - PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include - PRIVATE ${_gRPC_ADDRESS_SORTING_INCLUDE_DIR} - PRIVATE ${_gRPC_BENCHMARK_INCLUDE_DIR} - PRIVATE ${_gRPC_CARES_INCLUDE_DIR} - PRIVATE ${_gRPC_GFLAGS_INCLUDE_DIR} - PRIVATE ${_gRPC_PROTOBUF_INCLUDE_DIR} - PRIVATE ${_gRPC_SSL_INCLUDE_DIR} - PRIVATE ${_gRPC_UPB_GENERATED_DIR} - PRIVATE ${_gRPC_UPB_GRPC_GENERATED_DIR} - PRIVATE ${_gRPC_UPB_INCLUDE_DIR} - PRIVATE ${_gRPC_ZLIB_INCLUDE_DIR} - PRIVATE third_party/googletest/googletest/include - PRIVATE third_party/googletest/googletest - PRIVATE third_party/googletest/googlemock/include - PRIVATE third_party/googletest/googlemock - PRIVATE ${_gRPC_PROTO_GENS_DIR} -) - -target_link_libraries(transport_connectivity_state_test - ${_gRPC_PROTOBUF_LIBRARIES} - ${_gRPC_ALLTARGETS_LIBRARIES} - grpc_test_util - grpc - gpr - ${_gRPC_GFLAGS_LIBRARIES} -) - - endif (gRPC_BUILD_TESTS) if (gRPC_BUILD_TESTS) diff --git a/Makefile b/Makefile index 20e01d6c10c..728402c8bc0 100644 --- a/Makefile +++ b/Makefile @@ -1137,6 +1137,7 @@ time_averaged_stats_test: $(BINDIR)/$(CONFIG)/time_averaged_stats_test timeout_encoding_test: $(BINDIR)/$(CONFIG)/timeout_encoding_test timer_heap_test: $(BINDIR)/$(CONFIG)/timer_heap_test timer_list_test: $(BINDIR)/$(CONFIG)/timer_list_test +transport_connectivity_state_test: $(BINDIR)/$(CONFIG)/transport_connectivity_state_test transport_metadata_test: $(BINDIR)/$(CONFIG)/transport_metadata_test transport_security_test: $(BINDIR)/$(CONFIG)/transport_security_test udp_server_test: $(BINDIR)/$(CONFIG)/udp_server_test @@ -1293,7 +1294,6 @@ thread_manager_test: $(BINDIR)/$(CONFIG)/thread_manager_test thread_stress_test: $(BINDIR)/$(CONFIG)/thread_stress_test time_change_test: $(BINDIR)/$(CONFIG)/time_change_test timer_test: $(BINDIR)/$(CONFIG)/timer_test -transport_connectivity_state_test: $(BINDIR)/$(CONFIG)/transport_connectivity_state_test transport_pid_controller_test: $(BINDIR)/$(CONFIG)/transport_pid_controller_test transport_security_common_api_test: $(BINDIR)/$(CONFIG)/transport_security_common_api_test writes_per_rpc_test: $(BINDIR)/$(CONFIG)/writes_per_rpc_test @@ -1563,6 +1563,7 @@ buildtests_c: privatelibs_c \ $(BINDIR)/$(CONFIG)/timeout_encoding_test \ $(BINDIR)/$(CONFIG)/timer_heap_test \ $(BINDIR)/$(CONFIG)/timer_list_test \ + $(BINDIR)/$(CONFIG)/transport_connectivity_state_test \ $(BINDIR)/$(CONFIG)/transport_metadata_test \ $(BINDIR)/$(CONFIG)/transport_security_test \ $(BINDIR)/$(CONFIG)/udp_server_test \ @@ -1765,7 +1766,6 @@ buildtests_cxx: privatelibs_cxx \ $(BINDIR)/$(CONFIG)/thread_stress_test \ $(BINDIR)/$(CONFIG)/time_change_test \ $(BINDIR)/$(CONFIG)/timer_test \ - $(BINDIR)/$(CONFIG)/transport_connectivity_state_test \ $(BINDIR)/$(CONFIG)/transport_pid_controller_test \ $(BINDIR)/$(CONFIG)/transport_security_common_api_test \ $(BINDIR)/$(CONFIG)/writes_per_rpc_test \ @@ -1936,7 +1936,6 @@ buildtests_cxx: privatelibs_cxx \ $(BINDIR)/$(CONFIG)/thread_stress_test \ $(BINDIR)/$(CONFIG)/time_change_test \ $(BINDIR)/$(CONFIG)/timer_test \ - $(BINDIR)/$(CONFIG)/transport_connectivity_state_test \ $(BINDIR)/$(CONFIG)/transport_pid_controller_test \ $(BINDIR)/$(CONFIG)/transport_security_common_api_test \ $(BINDIR)/$(CONFIG)/writes_per_rpc_test \ @@ -2214,6 +2213,8 @@ test_c: buildtests_c $(Q) $(BINDIR)/$(CONFIG)/timer_heap_test || ( echo test timer_heap_test failed ; exit 1 ) $(E) "[RUN] Testing timer_list_test" $(Q) $(BINDIR)/$(CONFIG)/timer_list_test || ( echo test timer_list_test failed ; exit 1 ) + $(E) "[RUN] Testing transport_connectivity_state_test" + $(Q) $(BINDIR)/$(CONFIG)/transport_connectivity_state_test || ( echo test transport_connectivity_state_test failed ; exit 1 ) $(E) "[RUN] Testing transport_metadata_test" $(Q) $(BINDIR)/$(CONFIG)/transport_metadata_test || ( echo test transport_metadata_test failed ; exit 1 ) $(E) "[RUN] Testing transport_security_test" @@ -2480,8 +2481,6 @@ test_cxx: buildtests_cxx $(Q) $(BINDIR)/$(CONFIG)/time_change_test || ( echo test time_change_test failed ; exit 1 ) $(E) "[RUN] Testing timer_test" $(Q) $(BINDIR)/$(CONFIG)/timer_test || ( echo test timer_test failed ; exit 1 ) - $(E) "[RUN] Testing transport_connectivity_state_test" - $(Q) $(BINDIR)/$(CONFIG)/transport_connectivity_state_test || ( echo test transport_connectivity_state_test failed ; exit 1 ) $(E) "[RUN] Testing transport_pid_controller_test" $(Q) $(BINDIR)/$(CONFIG)/transport_pid_controller_test || ( echo test transport_pid_controller_test failed ; exit 1 ) $(E) "[RUN] Testing transport_security_common_api_test" @@ -13180,6 +13179,38 @@ endif endif +TRANSPORT_CONNECTIVITY_STATE_TEST_SRC = \ + test/core/transport/connectivity_state_test.cc \ + +TRANSPORT_CONNECTIVITY_STATE_TEST_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(TRANSPORT_CONNECTIVITY_STATE_TEST_SRC)))) +ifeq ($(NO_SECURE),true) + +# You can't build secure targets if you don't have OpenSSL. + +$(BINDIR)/$(CONFIG)/transport_connectivity_state_test: openssl_dep_error + +else + + + +$(BINDIR)/$(CONFIG)/transport_connectivity_state_test: $(TRANSPORT_CONNECTIVITY_STATE_TEST_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr.a + $(E) "[LD] Linking $@" + $(Q) mkdir -p `dirname $@` + $(Q) $(LDXX) $(LDFLAGS) $(TRANSPORT_CONNECTIVITY_STATE_TEST_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LDLIBS) $(LDLIBS_SECURE) -o $(BINDIR)/$(CONFIG)/transport_connectivity_state_test + +endif + +$(OBJDIR)/$(CONFIG)/test/core/transport/connectivity_state_test.o: $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr.a + +deps_transport_connectivity_state_test: $(TRANSPORT_CONNECTIVITY_STATE_TEST_OBJS:.o=.dep) + +ifneq ($(NO_SECURE),true) +ifneq ($(NO_DEPS),true) +-include $(TRANSPORT_CONNECTIVITY_STATE_TEST_OBJS:.o=.dep) +endif +endif + + TRANSPORT_METADATA_TEST_SRC = \ test/core/transport/metadata_test.cc \ @@ -19921,49 +19952,6 @@ endif endif -TRANSPORT_CONNECTIVITY_STATE_TEST_SRC = \ - test/core/transport/connectivity_state_test.cc \ - -TRANSPORT_CONNECTIVITY_STATE_TEST_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(TRANSPORT_CONNECTIVITY_STATE_TEST_SRC)))) -ifeq ($(NO_SECURE),true) - -# You can't build secure targets if you don't have OpenSSL. - -$(BINDIR)/$(CONFIG)/transport_connectivity_state_test: openssl_dep_error - -else - - - - -ifeq ($(NO_PROTOBUF),true) - -# You can't build the protoc plugins or protobuf-enabled targets if you don't have protobuf 3.5.0+. - -$(BINDIR)/$(CONFIG)/transport_connectivity_state_test: protobuf_dep_error - -else - -$(BINDIR)/$(CONFIG)/transport_connectivity_state_test: $(PROTOBUF_DEP) $(TRANSPORT_CONNECTIVITY_STATE_TEST_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr.a - $(E) "[LD] Linking $@" - $(Q) mkdir -p `dirname $@` - $(Q) $(LDXX) $(LDFLAGS) $(TRANSPORT_CONNECTIVITY_STATE_TEST_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LDLIBSXX) $(LDLIBS_PROTOBUF) $(LDLIBS) $(LDLIBS_SECURE) $(GTEST_LIB) -o $(BINDIR)/$(CONFIG)/transport_connectivity_state_test - -endif - -endif - -$(OBJDIR)/$(CONFIG)/test/core/transport/connectivity_state_test.o: $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr.a - -deps_transport_connectivity_state_test: $(TRANSPORT_CONNECTIVITY_STATE_TEST_OBJS:.o=.dep) - -ifneq ($(NO_SECURE),true) -ifneq ($(NO_DEPS),true) --include $(TRANSPORT_CONNECTIVITY_STATE_TEST_OBJS:.o=.dep) -endif -endif - - TRANSPORT_PID_CONTROLLER_TEST_SRC = \ test/core/transport/pid_controller_test.cc \ diff --git a/build.yaml b/build.yaml index 81058a6d1c9..f37c59d7ccf 100644 --- a/build.yaml +++ b/build.yaml @@ -3847,6 +3847,15 @@ targets: exclude_iomgrs: - uv uses_polling: false +- name: transport_connectivity_state_test + build: test + language: c + src: + - test/core/transport/connectivity_state_test.cc + deps: + - grpc_test_util + - grpc + - gpr - name: transport_metadata_test build: test language: c @@ -5980,16 +5989,6 @@ targets: - grpc++ - grpc - gpr -- name: transport_connectivity_state_test - gtest: true - build: test - language: c++ - src: - - test/core/transport/connectivity_state_test.cc - deps: - - grpc_test_util - - grpc - - gpr - name: transport_pid_controller_test build: test language: c++ diff --git a/src/core/ext/filters/client_channel/client_channel.cc b/src/core/ext/filters/client_channel/client_channel.cc index 5aed2e113e0..0a9b5ac43fb 100644 --- a/src/core/ext/filters/client_channel/client_channel.cc +++ b/src/core/ext/filters/client_channel/client_channel.cc @@ -152,41 +152,43 @@ class ChannelData { SubchannelInterface* subchannel) const; grpc_connectivity_state CheckConnectivityState(bool try_to_connect); - void AddExternalConnectivityWatcher(grpc_polling_entity pollent, grpc_connectivity_state* state, grpc_closure* on_complete, grpc_closure* watcher_timer_init) { - MutexLock lock(&external_watchers_mu_); - // Will be deleted when the watch is complete. - GPR_ASSERT(external_watchers_[on_complete] == nullptr); - external_watchers_[on_complete] = New( - this, pollent, state, on_complete, watcher_timer_init); - } - - void RemoveExternalConnectivityWatcher(grpc_closure* on_complete, - bool cancel) { - MutexLock lock(&external_watchers_mu_); - auto it = external_watchers_.find(on_complete); - if (it != external_watchers_.end()) { - if (cancel) it->second->Cancel(); - external_watchers_.erase(it); - } + // Will delete itself. + New(this, pollent, state, on_complete, + watcher_timer_init); } - int NumExternalConnectivityWatchers() const { - MutexLock lock(&external_watchers_mu_); - return static_cast(external_watchers_.size()); + return external_connectivity_watcher_list_.size(); } private: class SubchannelWrapper; class ClientChannelControlHelper; - // Represents a pending connectivity callback from an external caller - // via grpc_client_channel_watch_connectivity_state(). - class ExternalConnectivityWatcher : public ConnectivityStateWatcherInterface { + class ExternalConnectivityWatcher { public: + class WatcherList { + public: + WatcherList() { gpr_mu_init(&mu_); } + ~WatcherList() { gpr_mu_destroy(&mu_); } + + int size() const; + ExternalConnectivityWatcher* Lookup(grpc_closure* on_complete) const; + void Add(ExternalConnectivityWatcher* watcher); + void Remove(const ExternalConnectivityWatcher* watcher); + + private: + // head_ is guarded by a mutex, since the size() method needs to + // iterate over the list, and it's called from the C-core API + // function grpc_channel_num_external_connectivity_watchers(), which + // is synchronous and therefore cannot run in the combiner. + mutable gpr_mu mu_; + ExternalConnectivityWatcher* head_ = nullptr; + }; + ExternalConnectivityWatcher(ChannelData* chand, grpc_polling_entity pollent, grpc_connectivity_state* state, grpc_closure* on_complete, @@ -194,23 +196,17 @@ class ChannelData { ~ExternalConnectivityWatcher(); - void Notify(grpc_connectivity_state state) override; - - void Cancel(); - private: - static void AddWatcherLocked(void* arg, grpc_error* ignored); - static void RemoveWatcherLocked(void* arg, grpc_error* ignored); + static void OnWatchCompleteLocked(void* arg, grpc_error* error); + static void WatchConnectivityStateLocked(void* arg, grpc_error* ignored); ChannelData* chand_; grpc_polling_entity pollent_; - grpc_connectivity_state initial_state_; grpc_connectivity_state* state_; grpc_closure* on_complete_; grpc_closure* watcher_timer_init_; - grpc_closure add_closure_; - grpc_closure remove_closure_; - Atomic done_{false}; + grpc_closure my_closure_; + ExternalConnectivityWatcher* next_ = nullptr; }; ChannelData(grpc_channel_element_args* args, grpc_error** error); @@ -277,7 +273,8 @@ class ChannelData { grpc_pollset_set* interested_parties_; RefCountedPtr subchannel_pool_; OrphanablePtr resolving_lb_policy_; - ConnectivityStateTracker state_tracker_; + grpc_connectivity_state_tracker state_tracker_; + ExternalConnectivityWatcher::WatcherList external_connectivity_watcher_list_; UniquePtr health_check_service_name_; RefCountedPtr saved_service_config_; bool received_first_resolver_result_ = false; @@ -308,13 +305,6 @@ class ChannelData { gpr_mu info_mu_; UniquePtr info_lb_policy_name_; UniquePtr info_service_config_json_; - - // - // Fields guarded by a mutex, since they need to be accessed - // synchronously via grpc_channel_num_external_connectivity_watchers(). - // - mutable Mutex external_watchers_mu_; - Map external_watchers_; }; // @@ -1004,7 +994,8 @@ class ChannelData::SubchannelWrapper : public SubchannelInterface { "subchannel %p (connected_subchannel=%p state=%s); " "hopping into combiner", parent_->chand_, parent_.get(), parent_->subchannel_, - connected_subchannel.get(), ConnectivityStateName(new_state)); + connected_subchannel.get(), + grpc_connectivity_state_name(new_state)); } // Will delete itself. New(Ref(), new_state, std::move(connected_subchannel)); @@ -1053,7 +1044,7 @@ class ChannelData::SubchannelWrapper : public SubchannelInterface { self->parent_->parent_->chand_, self->parent_->parent_.get(), self->parent_->parent_->subchannel_, self->connected_subchannel_.get(), - ConnectivityStateName(self->state_), + grpc_connectivity_state_name(self->state_), self->parent_->watcher_.get()); } // Ignore update if the parent WatcherWrapper has been replaced @@ -1114,6 +1105,55 @@ class ChannelData::SubchannelWrapper : public SubchannelInterface { RefCountedPtr connected_subchannel_in_data_plane_; }; +// +// ChannelData::ExternalConnectivityWatcher::WatcherList +// + +int ChannelData::ExternalConnectivityWatcher::WatcherList::size() const { + MutexLock lock(&mu_); + int count = 0; + for (ExternalConnectivityWatcher* w = head_; w != nullptr; w = w->next_) { + ++count; + } + return count; +} + +ChannelData::ExternalConnectivityWatcher* +ChannelData::ExternalConnectivityWatcher::WatcherList::Lookup( + grpc_closure* on_complete) const { + MutexLock lock(&mu_); + ExternalConnectivityWatcher* w = head_; + while (w != nullptr && w->on_complete_ != on_complete) { + w = w->next_; + } + return w; +} + +void ChannelData::ExternalConnectivityWatcher::WatcherList::Add( + ExternalConnectivityWatcher* watcher) { + GPR_ASSERT(Lookup(watcher->on_complete_) == nullptr); + MutexLock lock(&mu_); + GPR_ASSERT(watcher->next_ == nullptr); + watcher->next_ = head_; + head_ = watcher; +} + +void ChannelData::ExternalConnectivityWatcher::WatcherList::Remove( + const ExternalConnectivityWatcher* watcher) { + MutexLock lock(&mu_); + if (watcher == head_) { + head_ = watcher->next_; + return; + } + for (ExternalConnectivityWatcher* w = head_; w != nullptr; w = w->next_) { + if (w->next_ == watcher) { + w->next_ = w->next_->next_; + return; + } + } + GPR_UNREACHABLE_CODE(return ); +} + // // ChannelData::ExternalConnectivityWatcher // @@ -1124,7 +1164,6 @@ ChannelData::ExternalConnectivityWatcher::ExternalConnectivityWatcher( grpc_closure* watcher_timer_init) : chand_(chand), pollent_(pollent), - initial_state_(*state), state_(state), on_complete_(on_complete), watcher_timer_init_(watcher_timer_init) { @@ -1132,7 +1171,7 @@ ChannelData::ExternalConnectivityWatcher::ExternalConnectivityWatcher( chand_->interested_parties_); GRPC_CHANNEL_STACK_REF(chand_->owning_stack_, "ExternalConnectivityWatcher"); GRPC_CLOSURE_SCHED( - GRPC_CLOSURE_INIT(&add_closure_, AddWatcherLocked, this, + GRPC_CLOSURE_INIT(&my_closure_, WatchConnectivityStateLocked, this, grpc_combiner_scheduler(chand_->combiner_)), GRPC_ERROR_NONE); } @@ -1144,61 +1183,42 @@ ChannelData::ExternalConnectivityWatcher::~ExternalConnectivityWatcher() { "ExternalConnectivityWatcher"); } -void ChannelData::ExternalConnectivityWatcher::Notify( - grpc_connectivity_state state) { - bool done = false; - if (!done_.CompareExchangeStrong(&done, true, MemoryOrder::RELAXED, - MemoryOrder::RELAXED)) { - return; // Already done. - } - // Report new state to the user. - *state_ = state; - GRPC_CLOSURE_SCHED(on_complete_, GRPC_ERROR_NONE); - // Remove external watcher. - chand_->RemoveExternalConnectivityWatcher(on_complete_, /*cancel=*/false); - // Hop back into the combiner to clean up. - // Not needed in state SHUTDOWN, because the tracker will - // automatically remove all watchers in that case. - if (state != GRPC_CHANNEL_SHUTDOWN) { - GRPC_CLOSURE_SCHED( - GRPC_CLOSURE_INIT(&remove_closure_, RemoveWatcherLocked, this, - grpc_combiner_scheduler(chand_->combiner_)), - GRPC_ERROR_NONE); - } -} - -void ChannelData::ExternalConnectivityWatcher::Cancel() { - bool done = false; - if (!done_.CompareExchangeStrong(&done, true, MemoryOrder::RELAXED, - MemoryOrder::RELAXED)) { - return; // Already done. - } - GRPC_CLOSURE_SCHED(on_complete_, GRPC_ERROR_CANCELLED); - // Hop back into the combiner to clean up. - GRPC_CLOSURE_SCHED( - GRPC_CLOSURE_INIT(&remove_closure_, RemoveWatcherLocked, this, - grpc_combiner_scheduler(chand_->combiner_)), - GRPC_ERROR_NONE); -} - -void ChannelData::ExternalConnectivityWatcher::AddWatcherLocked( - void* arg, grpc_error* ignored) { +void ChannelData::ExternalConnectivityWatcher::OnWatchCompleteLocked( + void* arg, grpc_error* error) { ExternalConnectivityWatcher* self = static_cast(arg); - // This assumes that the closure is scheduled on the ExecCtx scheduler - // and that GRPC_CLOSURE_RUN() will run the closure immediately. - GRPC_CLOSURE_RUN(self->watcher_timer_init_, GRPC_ERROR_NONE); - // Add new watcher. - self->chand_->state_tracker_.AddWatcher( - self->initial_state_, - OrphanablePtr(self)); + grpc_closure* on_complete = self->on_complete_; + self->chand_->external_connectivity_watcher_list_.Remove(self); + Delete(self); + GRPC_CLOSURE_SCHED(on_complete, GRPC_ERROR_REF(error)); } -void ChannelData::ExternalConnectivityWatcher::RemoveWatcherLocked( +void ChannelData::ExternalConnectivityWatcher::WatchConnectivityStateLocked( void* arg, grpc_error* ignored) { ExternalConnectivityWatcher* self = static_cast(arg); - self->chand_->state_tracker_.RemoveWatcher(self); + if (self->state_ == nullptr) { + // Handle cancellation. + GPR_ASSERT(self->watcher_timer_init_ == nullptr); + ExternalConnectivityWatcher* found = + self->chand_->external_connectivity_watcher_list_.Lookup( + self->on_complete_); + if (found != nullptr) { + grpc_connectivity_state_notify_on_state_change( + &found->chand_->state_tracker_, nullptr, &found->my_closure_); + } + Delete(self); + return; + } + // New watcher. + self->chand_->external_connectivity_watcher_list_.Add(self); + // This assumes that the closure is scheduled on the ExecCtx scheduler + // and that GRPC_CLOSURE_RUN would run the closure immediately. + GRPC_CLOSURE_RUN(self->watcher_timer_init_, GRPC_ERROR_NONE); + GRPC_CLOSURE_INIT(&self->my_closure_, OnWatchCompleteLocked, self, + grpc_combiner_scheduler(self->chand_->combiner_)); + grpc_connectivity_state_notify_on_state_change( + &self->chand_->state_tracker_, self->state_, &self->my_closure_); } // @@ -1251,7 +1271,7 @@ class ChannelData::ClientChannelControlHelper ? "" : " (ignoring -- channel shutting down)"; gpr_log(GPR_INFO, "chand=%p: update: state=%s picker=%p%s", chand_, - ConnectivityStateName(state), picker.get(), extra); + grpc_connectivity_state_name(state), picker.get(), extra); } // Do update only if not shutting down. if (disconnect_error == GRPC_ERROR_NONE) { @@ -1342,13 +1362,14 @@ ChannelData::ChannelData(grpc_channel_element_args* args, grpc_error** error) combiner_(grpc_combiner_create()), interested_parties_(grpc_pollset_set_create()), subchannel_pool_(GetSubchannelPool(args->channel_args)), - state_tracker_("client_channel", GRPC_CHANNEL_IDLE), disconnect_error_(GRPC_ERROR_NONE) { if (GRPC_TRACE_FLAG_ENABLED(grpc_client_channel_routing_trace)) { gpr_log(GPR_INFO, "chand=%p: creating client_channel for channel stack %p", this, owning_stack_); } // Initialize data members. + grpc_connectivity_state_init(&state_tracker_, GRPC_CHANNEL_IDLE, + "client_channel"); gpr_mu_init(&info_mu_); // Start backup polling. grpc_client_channel_start_backup_polling(interested_parties_); @@ -1412,6 +1433,7 @@ ChannelData::~ChannelData() { grpc_pollset_set_destroy(interested_parties_); GRPC_COMBINER_UNREF(combiner_, "client_channel"); GRPC_ERROR_UNREF(disconnect_error_.Load(MemoryOrder::RELAXED)); + grpc_connectivity_state_destroy(&state_tracker_); gpr_mu_destroy(&info_mu_); } @@ -1425,7 +1447,7 @@ void ChannelData::UpdateStateAndPickerLocked( received_first_resolver_result_ = false; } // Update connectivity state. - state_tracker_.SetState(state, reason); + grpc_connectivity_state_set(&state_tracker_, state, reason); if (channelz_node_ != nullptr) { channelz_node_->SetConnectivityState(state); channelz_node_->AddTraceEvent( @@ -1714,7 +1736,7 @@ bool ChannelData::ProcessResolverResultLocked( } grpc_error* ChannelData::DoPingLocked(grpc_transport_op* op) { - if (state_tracker_.state() != GRPC_CHANNEL_READY) { + if (grpc_connectivity_state_check(&state_tracker_) != GRPC_CHANNEL_READY) { return GRPC_ERROR_CREATE_FROM_STATIC_STRING("channel not connected"); } LoadBalancingPolicy::PickResult result = @@ -1742,12 +1764,12 @@ void ChannelData::StartTransportOpLocked(void* arg, grpc_error* ignored) { static_cast(op->handler_private.extra_arg); ChannelData* chand = static_cast(elem->channel_data); // Connectivity watch. - if (op->start_connectivity_watch != nullptr) { - chand->state_tracker_.AddWatcher(op->start_connectivity_watch_state, - std::move(op->start_connectivity_watch)); - } - if (op->stop_connectivity_watch != nullptr) { - chand->state_tracker_.RemoveWatcher(op->stop_connectivity_watch); + if (op->on_connectivity_state_change != nullptr) { + grpc_connectivity_state_notify_on_state_change( + &chand->state_tracker_, op->connectivity_state, + op->on_connectivity_state_change); + op->on_connectivity_state_change = nullptr; + op->connectivity_state = nullptr; } // Ping. if (op->send_ping.on_initiate != nullptr || op->send_ping.on_ack != nullptr) { @@ -1878,7 +1900,7 @@ void ChannelData::TryToConnectLocked(void* arg, grpc_error* error_ignored) { grpc_connectivity_state ChannelData::CheckConnectivityState( bool try_to_connect) { - grpc_connectivity_state out = state_tracker_.state(); + grpc_connectivity_state out = grpc_connectivity_state_check(&state_tracker_); if (out == GRPC_CHANNEL_IDLE && try_to_connect) { GRPC_CHANNEL_STACK_REF(owning_stack_, "TryToConnect"); GRPC_CLOSURE_SCHED(GRPC_CLOSURE_CREATE(TryToConnectLocked, this, @@ -3928,13 +3950,6 @@ void grpc_client_channel_watch_connectivity_state( grpc_connectivity_state* state, grpc_closure* closure, grpc_closure* watcher_timer_init) { auto* chand = static_cast(elem->channel_data); - if (state == nullptr) { - // Handle cancellation. - GPR_ASSERT(watcher_timer_init == nullptr); - chand->RemoveExternalConnectivityWatcher(closure, /*cancel=*/true); - return; - } - // Handle addition. return chand->AddExternalConnectivityWatcher(pollent, state, closure, watcher_timer_init); } diff --git a/src/core/ext/filters/client_channel/client_channel.h b/src/core/ext/filters/client_channel/client_channel.h index 72bcb404ce0..caaa079dd9b 100644 --- a/src/core/ext/filters/client_channel/client_channel.h +++ b/src/core/ext/filters/client_channel/client_channel.h @@ -46,12 +46,6 @@ grpc_connectivity_state grpc_client_channel_check_connectivity_state( int grpc_client_channel_num_external_connectivity_watchers( grpc_channel_element* elem); -// TODO(roth): This function is used both when handling external -// connectivity watchers and for LB policies like grpclb and xds that -// contain nested channels. In the latter case, we ideally want -// something closer to the normal connectivity state tracker API. -// When we have time, consider refactoring this somehow to allow each -// use-case to be handled more cleanly. void grpc_client_channel_watch_connectivity_state( grpc_channel_element* elem, grpc_polling_entity pollent, grpc_connectivity_state* state, grpc_closure* on_complete, diff --git a/src/core/ext/filters/client_channel/client_channel_channelz.cc b/src/core/ext/filters/client_channel/client_channel_channelz.cc index a47766031a3..87a76601f02 100644 --- a/src/core/ext/filters/client_channel/client_channel_channelz.cc +++ b/src/core/ext/filters/client_channel/client_channel_channelz.cc @@ -53,8 +53,9 @@ void SubchannelNode::PopulateConnectivityState(grpc_json* json) { connectivity_state_.Load(MemoryOrder::RELAXED); json = grpc_json_create_child(nullptr, json, "state", nullptr, GRPC_JSON_OBJECT, false); - grpc_json_create_child(nullptr, json, "state", ConnectivityStateName(state), - GRPC_JSON_STRING, false); + grpc_json_create_child(nullptr, json, "state", + grpc_connectivity_state_name(state), GRPC_JSON_STRING, + false); } grpc_json* SubchannelNode::RenderJson() { diff --git a/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc b/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc index af7632c1728..7f3c2b20f21 100644 --- a/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc +++ b/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc @@ -660,7 +660,7 @@ void GrpcLb::Helper::UpdateState(grpc_connectivity_state state, gpr_log(GPR_INFO, "[grpclb %p helper %p] pending child policy %p reports state=%s", parent_.get(), this, parent_->pending_child_policy_.get(), - ConnectivityStateName(state)); + grpc_connectivity_state_name(state)); } if (state != GRPC_CHANNEL_READY) return; grpc_pollset_set_del_pollset_set( @@ -700,7 +700,8 @@ void GrpcLb::Helper::UpdateState(grpc_connectivity_state state, if (GRPC_TRACE_FLAG_ENABLED(grpc_lb_glb_trace)) { gpr_log(GPR_INFO, "[grpclb %p helper %p] state=%s passing child picker %p as-is", - parent_.get(), this, ConnectivityStateName(state), picker.get()); + parent_.get(), this, grpc_connectivity_state_name(state), + picker.get()); } parent_->channel_control_helper()->UpdateState(state, std::move(picker)); return; @@ -708,7 +709,8 @@ void GrpcLb::Helper::UpdateState(grpc_connectivity_state state, // Cases 2 and 3a: wrap picker from the child in our own picker. if (GRPC_TRACE_FLAG_ENABLED(grpc_lb_glb_trace)) { gpr_log(GPR_INFO, "[grpclb %p helper %p] state=%s wrapping child picker %p", - parent_.get(), this, ConnectivityStateName(state), picker.get()); + parent_.get(), this, grpc_connectivity_state_name(state), + picker.get()); } RefCountedPtr client_stats; if (parent_->lb_calld_ != nullptr && diff --git a/src/core/ext/filters/client_channel/lb_policy/pick_first/pick_first.cc b/src/core/ext/filters/client_channel/lb_policy/pick_first/pick_first.cc index 000462092ac..b40b0325421 100644 --- a/src/core/ext/filters/client_channel/lb_policy/pick_first/pick_first.cc +++ b/src/core/ext/filters/client_channel/lb_policy/pick_first/pick_first.cc @@ -294,7 +294,7 @@ void PickFirst::PickFirstSubchannelData::ProcessConnectivityChangeLocked( if (GRPC_TRACE_FLAG_ENABLED(grpc_lb_pick_first_trace)) { gpr_log(GPR_INFO, "Pick First %p selected subchannel connectivity changed to %s", p, - ConnectivityStateName(connectivity_state)); + grpc_connectivity_state_name(connectivity_state)); } // If the new state is anything other than READY and there is a // pending update, switch to the pending update. diff --git a/src/core/ext/filters/client_channel/lb_policy/round_robin/round_robin.cc b/src/core/ext/filters/client_channel/lb_policy/round_robin/round_robin.cc index 69b3d6746e0..5f69a657b61 100644 --- a/src/core/ext/filters/client_channel/lb_policy/round_robin/round_robin.cc +++ b/src/core/ext/filters/client_channel/lb_policy/round_robin/round_robin.cc @@ -379,8 +379,8 @@ void RoundRobin::RoundRobinSubchannelData::UpdateConnectivityStateLocked( "(index %" PRIuPTR " of %" PRIuPTR "): prev_state=%s new_state=%s", p, subchannel(), subchannel_list(), Index(), subchannel_list()->num_subchannels(), - ConnectivityStateName(last_connectivity_state_), - ConnectivityStateName(connectivity_state)); + grpc_connectivity_state_name(last_connectivity_state_), + grpc_connectivity_state_name(connectivity_state)); } // Decide what state to report for aggregation purposes. // If we haven't seen a failure since the last time we were in state diff --git a/src/core/ext/filters/client_channel/lb_policy/subchannel_list.h b/src/core/ext/filters/client_channel/lb_policy/subchannel_list.h index b4d3fab91be..34cd0f549fe 100644 --- a/src/core/ext/filters/client_channel/lb_policy/subchannel_list.h +++ b/src/core/ext/filters/client_channel/lb_policy/subchannel_list.h @@ -254,7 +254,8 @@ void SubchannelData::Watcher:: subchannel_list_.get(), subchannel_data_->Index(), subchannel_list_->num_subchannels(), subchannel_data_->subchannel_.get(), - ConnectivityStateName(new_state), subchannel_list_->shutting_down(), + grpc_connectivity_state_name(new_state), + subchannel_list_->shutting_down(), subchannel_data_->pending_watcher_); } if (!subchannel_list_->shutting_down() && @@ -317,7 +318,8 @@ void SubchannelDatatracer()->name(), subchannel_list_->policy(), subchannel_list_, Index(), subchannel_list_->num_subchannels(), - subchannel_.get(), ConnectivityStateName(connectivity_state_)); + subchannel_.get(), + grpc_connectivity_state_name(connectivity_state_)); } GPR_ASSERT(pending_watcher_ == nullptr); pending_watcher_ = diff --git a/src/core/ext/filters/client_channel/lb_policy/xds/xds.cc b/src/core/ext/filters/client_channel/lb_policy/xds/xds.cc index c5b9b3dc437..7c4b1faffe2 100644 --- a/src/core/ext/filters/client_channel/lb_policy/xds/xds.cc +++ b/src/core/ext/filters/client_channel/lb_policy/xds/xds.cc @@ -823,7 +823,7 @@ void XdsLb::FallbackHelper::UpdateState(grpc_connectivity_state state, GPR_INFO, "[xdslb %p helper %p] pending fallback policy %p reports state=%s", parent_.get(), this, parent_->pending_fallback_policy_.get(), - ConnectivityStateName(state)); + grpc_connectivity_state_name(state)); } if (state != GRPC_CHANNEL_READY) return; grpc_pollset_set_del_pollset_set( @@ -2502,7 +2502,7 @@ void XdsLb::PriorityList::LocalityMap::UpdateConnectivityStateLocked() { gpr_log(GPR_INFO, "[xdslb %p] Priority %" PRIu32 " (%p) connectivity changed to %s", xds_policy(), priority_, this, - ConnectivityStateName(connectivity_state_)); + grpc_connectivity_state_name(connectivity_state_)); } } @@ -2834,7 +2834,7 @@ void XdsLb::PriorityList::LocalityMap::Locality::Helper::UpdateState( "[xdslb %p helper %p] pending child policy %p reports state=%s", locality_->xds_policy(), this, locality_->pending_child_policy_.get(), - ConnectivityStateName(state)); + grpc_connectivity_state_name(state)); } if (state != GRPC_CHANNEL_READY) return; grpc_pollset_set_del_pollset_set( diff --git a/src/core/ext/filters/client_channel/resolving_lb_policy.cc b/src/core/ext/filters/client_channel/resolving_lb_policy.cc index d997e26f979..f4c0f92b7b6 100644 --- a/src/core/ext/filters/client_channel/resolving_lb_policy.cc +++ b/src/core/ext/filters/client_channel/resolving_lb_policy.cc @@ -123,7 +123,8 @@ class ResolvingLoadBalancingPolicy::ResolvingControlHelper gpr_log(GPR_INFO, "resolving_lb=%p helper=%p: pending child policy %p reports " "state=%s", - parent_.get(), this, child_, ConnectivityStateName(state)); + parent_.get(), this, child_, + grpc_connectivity_state_name(state)); } if (state != GRPC_CHANNEL_READY) return; grpc_pollset_set_del_pollset_set( diff --git a/src/core/ext/filters/client_channel/subchannel.cc b/src/core/ext/filters/client_channel/subchannel.cc index 2c3f899d2a7..e30d915d03c 100644 --- a/src/core/ext/filters/client_channel/subchannel.cc +++ b/src/core/ext/filters/client_channel/subchannel.cc @@ -95,14 +95,15 @@ ConnectedSubchannel::~ConnectedSubchannel() { GRPC_CHANNEL_STACK_UNREF(channel_stack_, "connected_subchannel_dtor"); } -void ConnectedSubchannel::StartWatch( - grpc_pollset_set* interested_parties, - OrphanablePtr watcher) { +void ConnectedSubchannel::NotifyOnStateChange( + grpc_pollset_set* interested_parties, grpc_connectivity_state* state, + grpc_closure* closure) { grpc_transport_op* op = grpc_make_transport_op(nullptr); - op->start_connectivity_watch = std::move(watcher); - op->start_connectivity_watch_state = GRPC_CHANNEL_READY; + grpc_channel_element* elem; + op->connectivity_state = state; + op->on_connectivity_state_change = closure; op->bind_pollset_set = interested_parties; - grpc_channel_element* elem = grpc_channel_stack_element(channel_stack_, 0); + elem = grpc_channel_stack_element(channel_stack_, 0); elem->filter->start_transport_op(elem, op); } @@ -309,14 +310,19 @@ void SubchannelCall::IncrementRefCount(const grpc_core::DebugLocation& location, // Subchannel::ConnectedSubchannelStateWatcher // -class Subchannel::ConnectedSubchannelStateWatcher - : public AsyncConnectivityStateWatcherInterface { +class Subchannel::ConnectedSubchannelStateWatcher { public: // Must be instantiated while holding c->mu. explicit ConnectedSubchannelStateWatcher(Subchannel* c) : subchannel_(c) { // Steal subchannel ref for connecting. GRPC_SUBCHANNEL_WEAK_REF(subchannel_, "state_watcher"); GRPC_SUBCHANNEL_WEAK_UNREF(subchannel_, "connecting"); + // Start watching for connectivity state changes. + GRPC_CLOSURE_INIT(&on_connectivity_changed_, OnConnectivityChanged, this, + grpc_schedule_on_exec_ctx); + c->connected_subchannel_->NotifyOnStateChange(c->pollset_set_, + &pending_connectivity_state_, + &on_connectivity_changed_); } ~ConnectedSubchannelStateWatcher() { @@ -324,41 +330,54 @@ class Subchannel::ConnectedSubchannelStateWatcher } private: - void OnConnectivityStateChange(grpc_connectivity_state new_state) override { - Subchannel* c = subchannel_; - MutexLock lock(&c->mu_); - switch (new_state) { - case GRPC_CHANNEL_TRANSIENT_FAILURE: - case GRPC_CHANNEL_SHUTDOWN: { - if (!c->disconnected_ && c->connected_subchannel_ != nullptr) { - if (grpc_trace_subchannel.enabled()) { - gpr_log(GPR_INFO, - "Connected subchannel %p of subchannel %p has gone into " - "%s. Attempting to reconnect.", - c->connected_subchannel_.get(), c, - ConnectivityStateName(new_state)); - } - c->connected_subchannel_.reset(); - if (c->channelz_node() != nullptr) { - c->channelz_node()->SetChildSocket(nullptr); + static void OnConnectivityChanged(void* arg, grpc_error* error) { + auto* self = static_cast(arg); + Subchannel* c = self->subchannel_; + { + MutexLock lock(&c->mu_); + switch (self->pending_connectivity_state_) { + case GRPC_CHANNEL_TRANSIENT_FAILURE: + case GRPC_CHANNEL_SHUTDOWN: { + if (!c->disconnected_ && c->connected_subchannel_ != nullptr) { + if (grpc_trace_subchannel.enabled()) { + gpr_log(GPR_INFO, + "Connected subchannel %p of subchannel %p has gone into " + "%s. Attempting to reconnect.", + c->connected_subchannel_.get(), c, + grpc_connectivity_state_name( + self->pending_connectivity_state_)); + } + c->connected_subchannel_.reset(); + if (c->channelz_node() != nullptr) { + c->channelz_node()->SetChildSocket(nullptr); + } + c->SetConnectivityStateLocked(GRPC_CHANNEL_TRANSIENT_FAILURE); + c->backoff_begun_ = false; + c->backoff_.Reset(); } - c->SetConnectivityStateLocked(GRPC_CHANNEL_TRANSIENT_FAILURE); - c->backoff_begun_ = false; - c->backoff_.Reset(); + break; + } + default: { + // In principle, this should never happen. We should not get + // a callback for READY, because that was the state we started + // this watch from. And a connected subchannel should never go + // from READY to CONNECTING or IDLE. + c->SetConnectivityStateLocked(self->pending_connectivity_state_); + c->connected_subchannel_->NotifyOnStateChange( + nullptr, &self->pending_connectivity_state_, + &self->on_connectivity_changed_); + return; // So we don't delete ourself below. } - break; - } - default: { - // In principle, this should never happen. We should not get - // a callback for READY, because that was the state we started - // this watch from. And a connected subchannel should never go - // from READY to CONNECTING or IDLE. - c->SetConnectivityStateLocked(new_state); } } + // Don't delete until we've released the lock, because this might + // cause the subchannel (which contains the lock) to be destroyed. + Delete(self); } Subchannel* subchannel_; + grpc_closure on_connectivity_changed_; + grpc_connectivity_state pending_connectivity_state_ = GRPC_CHANNEL_READY; }; // @@ -1069,10 +1088,8 @@ bool Subchannel::PublishTransportLocked() { if (channelz_node_ != nullptr) { channelz_node_->SetChildSocket(std::move(socket)); } - // Start watching connected subchannel. - connected_subchannel_->StartWatch( - pollset_set_, OrphanablePtr( - New(this))); + // Instantiate state watcher. Will clean itself up. + New(this); // Report initial state. SetConnectivityStateLocked(GRPC_CHANNEL_READY); return true; diff --git a/src/core/ext/filters/client_channel/subchannel.h b/src/core/ext/filters/client_channel/subchannel.h index d6fb65814b7..c178401ca8a 100644 --- a/src/core/ext/filters/client_channel/subchannel.h +++ b/src/core/ext/filters/client_channel/subchannel.h @@ -77,9 +77,9 @@ class ConnectedSubchannel : public RefCounted { RefCountedPtr channelz_subchannel); ~ConnectedSubchannel(); - void StartWatch(grpc_pollset_set* interested_parties, - OrphanablePtr watcher); - + void NotifyOnStateChange(grpc_pollset_set* interested_parties, + grpc_connectivity_state* state, + grpc_closure* closure); void Ping(grpc_closure* on_initiate, grpc_closure* on_ack); grpc_channel_stack* channel_stack() const { return channel_stack_; } diff --git a/src/core/ext/filters/max_age/max_age_filter.cc b/src/core/ext/filters/max_age/max_age_filter.cc index 982fabca833..7ab506429af 100644 --- a/src/core/ext/filters/max_age/max_age_filter.cc +++ b/src/core/ext/filters/max_age/max_age_filter.cc @@ -90,6 +90,10 @@ struct channel_data { grpc_closure start_max_age_timer_after_init; /* Closure to run when the goaway op is finished and the max_age_timer */ grpc_closure start_max_age_grace_timer_after_goaway_op; + /* Closure to run when the channel connectivity state changes */ + grpc_closure channel_connectivity_changed; + /* Records the current connectivity state */ + grpc_connectivity_state connectivity_state; /* Number of active calls */ gpr_atm call_count; /* TODO(zyc): C++lize this state machine */ @@ -216,47 +220,6 @@ static void start_max_idle_timer_after_init(void* arg, grpc_error* error) { "max_age start_max_idle_timer_after_init"); } -namespace grpc_core { - -class ConnectivityWatcher : public AsyncConnectivityStateWatcherInterface { - public: - explicit ConnectivityWatcher(channel_data* chand) : chand_(chand) { - GRPC_CHANNEL_STACK_REF(chand_->channel_stack, "max_age conn_watch"); - } - - ~ConnectivityWatcher() { - GRPC_CHANNEL_STACK_UNREF(chand_->channel_stack, "max_age conn_watch"); - } - - private: - void OnConnectivityStateChange(grpc_connectivity_state new_state) override { - if (new_state != GRPC_CHANNEL_SHUTDOWN) return; - { - MutexLock lock(&chand_->max_age_timer_mu); - if (chand_->max_age_timer_pending) { - grpc_timer_cancel(&chand_->max_age_timer); - chand_->max_age_timer_pending = false; - } - if (chand_->max_age_grace_timer_pending) { - grpc_timer_cancel(&chand_->max_age_grace_timer); - chand_->max_age_grace_timer_pending = false; - } - } - /* If there are no active calls, this increasement will cancel - max_idle_timer, and prevent max_idle_timer from being started in the - future. */ - increase_call_count(chand_); - if (gpr_atm_acq_load(&chand_->idle_state) == - MAX_IDLE_STATE_SEEN_EXIT_IDLE) { - grpc_timer_cancel(&chand_->max_idle_timer); - } - } - - channel_data* chand_; -}; - -} // namespace grpc_core - static void start_max_age_timer_after_init(void* arg, grpc_error* error) { channel_data* chand = static_cast(arg); gpr_mu_lock(&chand->max_age_timer_mu); @@ -267,9 +230,8 @@ static void start_max_age_timer_after_init(void* arg, grpc_error* error) { &chand->close_max_age_channel); gpr_mu_unlock(&chand->max_age_timer_mu); grpc_transport_op* op = grpc_make_transport_op(nullptr); - op->start_connectivity_watch.reset( - grpc_core::New(chand)); - op->start_connectivity_watch_state = GRPC_CHANNEL_IDLE; + op->on_connectivity_state_change = &chand->channel_connectivity_changed; + op->connectivity_state = &chand->connectivity_state; grpc_channel_next_op(grpc_channel_stack_element(chand->channel_stack, 0), op); GRPC_CHANNEL_STACK_UNREF(chand->channel_stack, "max_age start_max_age_timer_after_init"); @@ -388,6 +350,35 @@ static void force_close_max_age_channel(void* arg, grpc_error* error) { GRPC_CHANNEL_STACK_UNREF(chand->channel_stack, "max_age max_age_grace_timer"); } +static void channel_connectivity_changed(void* arg, grpc_error* error) { + channel_data* chand = static_cast(arg); + if (chand->connectivity_state != GRPC_CHANNEL_SHUTDOWN) { + grpc_transport_op* op = grpc_make_transport_op(nullptr); + op->on_connectivity_state_change = &chand->channel_connectivity_changed; + op->connectivity_state = &chand->connectivity_state; + grpc_channel_next_op(grpc_channel_stack_element(chand->channel_stack, 0), + op); + } else { + gpr_mu_lock(&chand->max_age_timer_mu); + if (chand->max_age_timer_pending) { + grpc_timer_cancel(&chand->max_age_timer); + chand->max_age_timer_pending = false; + } + if (chand->max_age_grace_timer_pending) { + grpc_timer_cancel(&chand->max_age_grace_timer); + chand->max_age_grace_timer_pending = false; + } + gpr_mu_unlock(&chand->max_age_timer_mu); + /* If there are no active calls, this increasement will cancel + max_idle_timer, and prevent max_idle_timer from being started in the + future. */ + increase_call_count(chand); + if (gpr_atm_acq_load(&chand->idle_state) == MAX_IDLE_STATE_SEEN_EXIT_IDLE) { + grpc_timer_cancel(&chand->max_idle_timer); + } + } +} + /* A random jitter of +/-10% will be added to MAX_CONNECTION_AGE to spread out connection storms. Note that the MAX_CONNECTION_AGE option without jitter would not create connection storms by itself, but if there happened to be a @@ -481,6 +472,9 @@ static grpc_error* max_age_init_channel_elem(grpc_channel_element* elem, GRPC_CLOSURE_INIT(&chand->start_max_age_grace_timer_after_goaway_op, start_max_age_grace_timer_after_goaway_op, chand, grpc_schedule_on_exec_ctx); + GRPC_CLOSURE_INIT(&chand->channel_connectivity_changed, + channel_connectivity_changed, chand, + grpc_schedule_on_exec_ctx); if (chand->max_connection_age != GRPC_MILLIS_INF_FUTURE) { /* When the channel reaches its max age, we send down an op with diff --git a/src/core/ext/transport/chttp2/transport/chttp2_transport.cc b/src/core/ext/transport/chttp2/transport/chttp2_transport.cc index acb3b4c2ddd..647442eb290 100644 --- a/src/core/ext/transport/chttp2/transport/chttp2_transport.cc +++ b/src/core/ext/transport/chttp2/transport/chttp2_transport.cc @@ -196,6 +196,7 @@ grpc_chttp2_transport::~grpc_chttp2_transport() { GPR_ASSERT(grpc_chttp2_stream_map_size(&stream_map) == 0); grpc_chttp2_stream_map_destroy(&stream_map); + grpc_connectivity_state_destroy(&channel_callback.state_tracker); cancel_pings(this, GRPC_ERROR_CREATE_FROM_STATIC_STRING("Transport destroyed")); @@ -465,8 +466,6 @@ grpc_chttp2_transport::grpc_chttp2_transport( ep(ep), peer_string(grpc_endpoint_get_peer(ep)), resource_user(resource_user), - state_tracker(is_client ? "client_transport" : "server_transport", - GRPC_CHANNEL_READY), is_client(is_client), next_stream_id(is_client ? 1 : 2), deframe_state(is_client ? GRPC_DTS_FH_0 : GRPC_DTS_CLIENT_PREFIX_0) { @@ -481,6 +480,9 @@ grpc_chttp2_transport::grpc_chttp2_transport( grpc_chttp2_stream_map_init(&stream_map, 8); grpc_slice_buffer_init(&read_buffer); + grpc_connectivity_state_init( + &channel_callback.state_tracker, GRPC_CHANNEL_READY, + is_client ? "client_transport" : "server_transport"); grpc_slice_buffer_init(&outbuf); if (is_client) { grpc_slice_buffer_add(&outbuf, grpc_slice_from_copied_string( @@ -768,7 +770,7 @@ static void destroy_stream(grpc_transport* gt, grpc_stream* gs, grpc_chttp2_stream* grpc_chttp2_parsing_accept_stream(grpc_chttp2_transport* t, uint32_t id) { - if (t->accept_stream_cb == nullptr) { + if (t->channel_callback.accept_stream == nullptr) { return nullptr; } // Don't accept the stream if memory quota doesn't allow. Note that we should @@ -786,8 +788,9 @@ grpc_chttp2_stream* grpc_chttp2_parsing_accept_stream(grpc_chttp2_transport* t, grpc_chttp2_stream* accepting = nullptr; GPR_ASSERT(t->accepting_stream == nullptr); t->accepting_stream = &accepting; - t->accept_stream_cb(t->accept_stream_cb_user_data, &t->base, - (void*)static_cast(id)); + t->channel_callback.accept_stream(t->channel_callback.accept_stream_user_data, + &t->base, + (void*)static_cast(id)); t->accepting_stream = nullptr; return accepting; } @@ -1840,8 +1843,9 @@ static void perform_transport_op(grpc_transport* gt, grpc_transport_op* op) { } if (op->set_accept_stream) { - t->accept_stream_cb = op->set_accept_stream_fn; - t->accept_stream_cb_user_data = op->set_accept_stream_user_data; + t->channel_callback.accept_stream = op->set_accept_stream_fn; + t->channel_callback.accept_stream_user_data = + op->set_accept_stream_user_data; } if (op->bind_pollset) { @@ -1857,12 +1861,10 @@ static void perform_transport_op(grpc_transport* gt, grpc_transport_op* op) { grpc_chttp2_initiate_write(t, GRPC_CHTTP2_INITIATE_WRITE_APPLICATION_PING); } - if (op->start_connectivity_watch != nullptr) { - t->state_tracker.AddWatcher(op->start_connectivity_watch_state, - std::move(op->start_connectivity_watch)); - } - if (op->stop_connectivity_watch != nullptr) { - t->state_tracker.RemoveWatcher(op->stop_connectivity_watch); + if (op->on_connectivity_state_change != nullptr) { + grpc_connectivity_state_notify_on_state_change( + &t->channel_callback.state_tracker, op->connectivity_state, + op->on_connectivity_state_change); } if (op->disconnect_with_error != GRPC_ERROR_NONE) { @@ -2848,7 +2850,8 @@ static void connectivity_state_set(grpc_chttp2_transport* t, const char* reason) { GRPC_CHTTP2_IF_TRACING( gpr_log(GPR_INFO, "transport %p set connectivity_state=%d", t, state)); - t->state_tracker.SetState(state, reason); + grpc_connectivity_state_set(&t->channel_callback.state_tracker, state, + reason); } /******************************************************************************* diff --git a/src/core/ext/transport/chttp2/transport/internal.h b/src/core/ext/transport/chttp2/transport/internal.h index 6d13d368be7..314e5fdf650 100644 --- a/src/core/ext/transport/chttp2/transport/internal.h +++ b/src/core/ext/transport/chttp2/transport/internal.h @@ -339,13 +339,15 @@ struct grpc_chttp2_transport { publish the accepted server stream */ grpc_chttp2_stream** accepting_stream = nullptr; - /* accept stream callback */ - void (*accept_stream_cb)(void* user_data, grpc_transport* transport, - const void* server_data); - void* accept_stream_cb_user_data; - - /** connectivity tracking */ - grpc_core::ConnectivityStateTracker state_tracker; + struct { + /* accept stream callback */ + void (*accept_stream)(void* user_data, grpc_transport* transport, + const void* server_data); + void* accept_stream_user_data; + + /** connectivity tracking */ + grpc_connectivity_state_tracker state_tracker; + } channel_callback; /** data to write now */ grpc_slice_buffer outbuf; diff --git a/src/core/ext/transport/inproc/inproc_transport.cc b/src/core/ext/transport/inproc/inproc_transport.cc index a6d91ef1e05..b1dcbbba29b 100644 --- a/src/core/ext/transport/inproc/inproc_transport.cc +++ b/src/core/ext/transport/inproc/inproc_transport.cc @@ -75,17 +75,17 @@ struct shared_mu { struct inproc_transport { inproc_transport(const grpc_transport_vtable* vtable, shared_mu* mu, bool is_client) - : mu(mu), - is_client(is_client), - state_tracker(is_client ? "inproc_client" : "inproc_server", - GRPC_CHANNEL_READY) { + : mu(mu), is_client(is_client) { base.vtable = vtable; // Start each side of transport with 2 refs since they each have a ref // to the other gpr_ref_init(&refs, 2); + grpc_connectivity_state_init(&connectivity, GRPC_CHANNEL_READY, + is_client ? "inproc_client" : "inproc_server"); } ~inproc_transport() { + grpc_connectivity_state_destroy(&connectivity); if (gpr_unref(&mu->refs)) { mu->~shared_mu(); gpr_free(mu); @@ -111,7 +111,7 @@ struct inproc_transport { shared_mu* mu; gpr_refcount refs; bool is_client; - grpc_core::ConnectivityStateTracker state_tracker; + grpc_connectivity_state_tracker connectivity; void (*accept_stream_cb)(void* user_data, grpc_transport* transport, const void* server_data); void* accept_stream_data; @@ -1090,7 +1090,8 @@ void perform_stream_op(grpc_transport* gt, grpc_stream* gs, void close_transport_locked(inproc_transport* t) { INPROC_LOG(GPR_INFO, "close_transport %p %d", t, t->is_closed); - t->state_tracker.SetState(GRPC_CHANNEL_SHUTDOWN, "close transport"); + grpc_connectivity_state_set(&t->connectivity, GRPC_CHANNEL_SHUTDOWN, + "close transport"); if (!t->is_closed) { t->is_closed = true; /* Also end all streams on this transport */ @@ -1109,12 +1110,10 @@ void perform_transport_op(grpc_transport* gt, grpc_transport_op* op) { inproc_transport* t = reinterpret_cast(gt); INPROC_LOG(GPR_INFO, "perform_transport_op %p %p", t, op); gpr_mu_lock(&t->mu->mu); - if (op->start_connectivity_watch != nullptr) { - t->state_tracker.AddWatcher(op->start_connectivity_watch_state, - std::move(op->start_connectivity_watch)); - } - if (op->stop_connectivity_watch != nullptr) { - t->state_tracker.RemoveWatcher(op->stop_connectivity_watch); + if (op->on_connectivity_state_change) { + grpc_connectivity_state_notify_on_state_change( + &t->connectivity, op->connectivity_state, + op->on_connectivity_state_change); } if (op->set_accept_stream) { t->accept_stream_cb = op->set_accept_stream_fn; diff --git a/src/core/lib/channel/channelz.cc b/src/core/lib/channel/channelz.cc index 24746e70d0b..fb913beb0f0 100644 --- a/src/core/lib/channel/channelz.cc +++ b/src/core/lib/channel/channelz.cc @@ -234,7 +234,8 @@ grpc_json* ChannelNode::RenderJson() { static_cast(state_field >> 1); json = grpc_json_create_child(nullptr, json, "state", nullptr, GRPC_JSON_OBJECT, false); - grpc_json_create_child(nullptr, json, "state", ConnectivityStateName(state), + grpc_json_create_child(nullptr, json, "state", + grpc_connectivity_state_name(state), GRPC_JSON_STRING, false); json = data; } diff --git a/src/core/lib/surface/lame_client.cc b/src/core/lib/surface/lame_client.cc index 565f386ba74..9208160938e 100644 --- a/src/core/lib/surface/lame_client.cc +++ b/src/core/lib/surface/lame_client.cc @@ -32,7 +32,6 @@ #include "src/core/lib/surface/call.h" #include "src/core/lib/surface/channel.h" #include "src/core/lib/surface/lame_client.h" -#include "src/core/lib/transport/connectivity_state.h" #include "src/core/lib/transport/static_metadata.h" namespace grpc_core { @@ -40,19 +39,15 @@ namespace grpc_core { namespace { struct CallData { - CallCombiner* call_combiner; + grpc_core::CallCombiner* call_combiner; grpc_linked_mdelem status; grpc_linked_mdelem details; - Atomic filled_metadata; + grpc_core::Atomic filled_metadata; }; struct ChannelData { - ChannelData() : state_tracker("lame_channel", GRPC_CHANNEL_SHUTDOWN) {} - grpc_status_code error_code; const char* error_message; - Mutex mu; - ConnectivityStateTracker state_tracker; }; static void fill_metadata(grpc_call_element* elem, grpc_metadata_batch* mdb) { @@ -99,16 +94,10 @@ static void lame_get_channel_info(grpc_channel_element* elem, static void lame_start_transport_op(grpc_channel_element* elem, grpc_transport_op* op) { - ChannelData* chand = static_cast(elem->channel_data); - { - MutexLock lock(&chand->mu); - if (op->start_connectivity_watch != nullptr) { - chand->state_tracker.AddWatcher(op->start_connectivity_watch_state, - std::move(op->start_connectivity_watch)); - } - if (op->stop_connectivity_watch != nullptr) { - chand->state_tracker.RemoveWatcher(op->stop_connectivity_watch); - } + if (op->on_connectivity_state_change) { + GPR_ASSERT(*op->connectivity_state != GRPC_CHANNEL_SHUTDOWN); + *op->connectivity_state = GRPC_CHANNEL_SHUTDOWN; + GRPC_CLOSURE_SCHED(op->on_connectivity_state_change, GRPC_ERROR_NONE); } if (op->send_ping.on_initiate != nullptr) { GRPC_CLOSURE_SCHED( @@ -143,14 +132,10 @@ static grpc_error* lame_init_channel_elem(grpc_channel_element* elem, grpc_channel_element_args* args) { GPR_ASSERT(args->is_first); GPR_ASSERT(args->is_last); - new (elem->channel_data) ChannelData; return GRPC_ERROR_NONE; } -static void lame_destroy_channel_elem(grpc_channel_element* elem) { - ChannelData* chand = static_cast(elem->channel_data); - chand->~ChannelData(); -} +static void lame_destroy_channel_elem(grpc_channel_element* elem) {} } // namespace diff --git a/src/core/lib/surface/server.cc b/src/core/lib/surface/server.cc index 4fd3b0e99f1..c14b7ba62b3 100644 --- a/src/core/lib/surface/server.cc +++ b/src/core/lib/surface/server.cc @@ -105,6 +105,7 @@ struct channel_registered_method { struct channel_data { grpc_server* server; + grpc_connectivity_state connectivity_state; grpc_channel* channel; size_t cq_idx; /* linked list of all channels on a server */ @@ -114,6 +115,7 @@ struct channel_data { uint32_t registered_method_slots; uint32_t registered_method_max_probes; grpc_closure finish_destroy_channel_closure; + grpc_closure channel_connectivity_changed; intptr_t channelz_socket_uuid; }; @@ -456,7 +458,7 @@ static void finish_destroy_channel(void* cd, grpc_error* error) { server_unref(server); } -static void destroy_channel(channel_data* chand) { +static void destroy_channel(channel_data* chand, grpc_error* error) { if (is_channel_orphaned(chand)) return; GPR_ASSERT(chand->server != nullptr); orphan_channel(chand); @@ -465,9 +467,12 @@ static void destroy_channel(channel_data* chand) { GRPC_CLOSURE_INIT(&chand->finish_destroy_channel_closure, finish_destroy_channel, chand, grpc_schedule_on_exec_ctx); - if (GRPC_TRACE_FLAG_ENABLED(grpc_server_channel_trace)) { - gpr_log(GPR_INFO, "Disconnected client"); + if (GRPC_TRACE_FLAG_ENABLED(grpc_server_channel_trace) && + error != GRPC_ERROR_NONE) { + const char* msg = grpc_error_string(error); + gpr_log(GPR_INFO, "Disconnected client: %s", msg); } + GRPC_ERROR_UNREF(error); grpc_transport_op* op = grpc_make_transport_op(&chand->finish_destroy_channel_closure); @@ -886,6 +891,24 @@ static void accept_stream(void* cd, grpc_transport* transport, grpc_call_start_batch_and_execute(call, &op, 1, &calld->got_initial_metadata); } +static void channel_connectivity_changed(void* cd, grpc_error* error) { + channel_data* chand = static_cast(cd); + grpc_server* server = chand->server; + if (chand->connectivity_state != GRPC_CHANNEL_SHUTDOWN) { + grpc_transport_op* op = grpc_make_transport_op(nullptr); + op->on_connectivity_state_change = &chand->channel_connectivity_changed; + op->connectivity_state = &chand->connectivity_state; + grpc_channel_next_op(grpc_channel_stack_element( + grpc_channel_get_channel_stack(chand->channel), 0), + op); + } else { + gpr_mu_lock(&server->mu_global); + destroy_channel(chand, GRPC_ERROR_REF(error)); + gpr_mu_unlock(&server->mu_global); + GRPC_CHANNEL_INTERNAL_UNREF(chand->channel, "connectivity"); + } +} + static grpc_error* server_init_call_elem(grpc_call_element* elem, const grpc_call_element_args* args) { channel_data* chand = static_cast(elem->channel_data); @@ -912,6 +935,10 @@ static grpc_error* server_init_channel_elem(grpc_channel_element* elem, chand->channel = nullptr; chand->next = chand->prev = chand; chand->registered_methods = nullptr; + chand->connectivity_state = GRPC_CHANNEL_IDLE; + GRPC_CLOSURE_INIT(&chand->channel_connectivity_changed, + channel_connectivity_changed, chand, + grpc_schedule_on_exec_ctx); return GRPC_ERROR_NONE; } @@ -1122,31 +1149,6 @@ void grpc_server_get_pollsets(grpc_server* server, grpc_pollset*** pollsets, *pollsets = server->pollsets; } -class ConnectivityWatcher - : public grpc_core::AsyncConnectivityStateWatcherInterface { - public: - explicit ConnectivityWatcher(channel_data* chand) : chand_(chand) { - GRPC_CHANNEL_INTERNAL_REF(chand_->channel, "connectivity"); - } - - ~ConnectivityWatcher() { - GRPC_CHANNEL_INTERNAL_UNREF(chand_->channel, "connectivity"); - } - - private: - void OnConnectivityStateChange(grpc_connectivity_state new_state) override { - // Don't do anything until we are being shut down. - if (new_state != GRPC_CHANNEL_SHUTDOWN) return; - // Shut down channel. - grpc_server* server = chand_->server; - gpr_mu_lock(&server->mu_global); - destroy_channel(chand_); - gpr_mu_unlock(&server->mu_global); - } - - channel_data* chand_; -}; - void grpc_server_setup_transport( grpc_server* s, grpc_transport* transport, grpc_pollset* accepting_pollset, const grpc_channel_args* args, @@ -1239,12 +1241,13 @@ void grpc_server_setup_transport( chand->next->prev = chand->prev->next = chand; gpr_mu_unlock(&s->mu_global); + GRPC_CHANNEL_INTERNAL_REF(channel, "connectivity"); op = grpc_make_transport_op(nullptr); op->set_accept_stream = true; op->set_accept_stream_fn = accept_stream; op->set_accept_stream_user_data = chand; - op->start_connectivity_watch.reset( - grpc_core::New(chand)); + op->on_connectivity_state_change = &chand->channel_connectivity_changed; + op->connectivity_state = &chand->connectivity_state; if (gpr_atm_acq_load(&s->shutdown_flag) != 0) { op->disconnect_with_error = GRPC_ERROR_CREATE_FROM_STATIC_STRING("Server shutdown"); diff --git a/src/core/lib/transport/connectivity_state.cc b/src/core/lib/transport/connectivity_state.cc index 45ebdca4f0d..bf35fd09def 100644 --- a/src/core/lib/transport/connectivity_state.cc +++ b/src/core/lib/transport/connectivity_state.cc @@ -26,13 +26,9 @@ #include #include -#include "src/core/lib/iomgr/exec_ctx.h" +grpc_core::TraceFlag grpc_connectivity_state_trace(false, "connectivity_state"); -namespace grpc_core { - -TraceFlag grpc_connectivity_state_trace(false, "connectivity_state"); - -const char* ConnectivityStateName(grpc_connectivity_state state) { +const char* grpc_connectivity_state_name(grpc_connectivity_state state) { switch (state) { case GRPC_CHANNEL_IDLE: return "IDLE"; @@ -48,121 +44,122 @@ const char* ConnectivityStateName(grpc_connectivity_state state) { GPR_UNREACHABLE_CODE(return "UNKNOWN"); } -// -// AsyncConnectivityStateWatcherInterface -// - -// A fire-and-forget class to asynchronously deliver a connectivity -// state notification to a watcher. -class AsyncConnectivityStateWatcherInterface::Notifier { - public: - Notifier(RefCountedPtr watcher, - grpc_connectivity_state state) - : watcher_(std::move(watcher)), state_(state) { - GRPC_CLOSURE_INIT(&closure_, SendNotification, this, - grpc_schedule_on_exec_ctx); - GRPC_CLOSURE_SCHED(&closure_, GRPC_ERROR_NONE); - } - - private: - static void SendNotification(void* arg, grpc_error* ignored) { - Notifier* self = static_cast(arg); - if (GRPC_TRACE_FLAG_ENABLED(grpc_connectivity_state_trace)) { - gpr_log(GPR_INFO, "watcher %p: delivering async notification for %s", - self->watcher_.get(), ConnectivityStateName(self->state_)); - } - self->watcher_->OnConnectivityStateChange(self->state_); - Delete(self); - } - - RefCountedPtr watcher_; - const grpc_connectivity_state state_; - grpc_closure closure_; -}; - -void AsyncConnectivityStateWatcherInterface::Notify( - grpc_connectivity_state state) { - New(Ref(), state); // Deletes itself when done. +void grpc_connectivity_state_init(grpc_connectivity_state_tracker* tracker, + grpc_connectivity_state init_state, + const char* name) { + gpr_atm_no_barrier_store(&tracker->current_state_atm, init_state); + tracker->watchers = nullptr; + tracker->name = gpr_strdup(name); } -// -// ConnectivityStateTracker -// - -ConnectivityStateTracker::~ConnectivityStateTracker() { - grpc_connectivity_state current_state = state_.Load(MemoryOrder::RELAXED); - if (current_state == GRPC_CHANNEL_SHUTDOWN) return; - for (const auto& p : watchers_) { - if (GRPC_TRACE_FLAG_ENABLED(grpc_connectivity_state_trace)) { - gpr_log(GPR_INFO, - "ConnectivityStateTracker %s[%p]: notifying watcher %p: %s -> %s", - name_, this, p.first, ConnectivityStateName(current_state), - ConnectivityStateName(GRPC_CHANNEL_SHUTDOWN)); +void grpc_connectivity_state_destroy(grpc_connectivity_state_tracker* tracker) { + grpc_error* error; + grpc_connectivity_state_watcher* w; + while ((w = tracker->watchers)) { + tracker->watchers = w->next; + + if (GRPC_CHANNEL_SHUTDOWN != *w->current) { + *w->current = GRPC_CHANNEL_SHUTDOWN; + error = GRPC_ERROR_NONE; + } else { + error = + GRPC_ERROR_CREATE_FROM_STATIC_STRING("Shutdown connectivity owner"); } - p.second->Notify(GRPC_CHANNEL_SHUTDOWN); + GRPC_CLOSURE_SCHED(w->notify, error); + gpr_free(w); } + gpr_free(tracker->name); } -void ConnectivityStateTracker::AddWatcher( - grpc_connectivity_state initial_state, - OrphanablePtr watcher) { +grpc_connectivity_state grpc_connectivity_state_check( + grpc_connectivity_state_tracker* tracker) { + grpc_connectivity_state cur = static_cast( + gpr_atm_no_barrier_load(&tracker->current_state_atm)); if (GRPC_TRACE_FLAG_ENABLED(grpc_connectivity_state_trace)) { - gpr_log(GPR_INFO, "ConnectivityStateTracker %s[%p]: add watcher %p", name_, - this, watcher.get()); - } - grpc_connectivity_state current_state = state_.Load(MemoryOrder::RELAXED); - if (initial_state != current_state) { - if (GRPC_TRACE_FLAG_ENABLED(grpc_connectivity_state_trace)) { - gpr_log(GPR_INFO, - "ConnectivityStateTracker %s[%p]: notifying watcher %p: %s -> %s", - name_, this, watcher.get(), ConnectivityStateName(initial_state), - ConnectivityStateName(current_state)); - } - watcher->Notify(current_state); + gpr_log(GPR_INFO, "CONWATCH: %p %s: get %s", tracker, tracker->name, + grpc_connectivity_state_name(cur)); } - watchers_.insert(MakePair(watcher.get(), std::move(watcher))); + return cur; } -void ConnectivityStateTracker::RemoveWatcher( - ConnectivityStateWatcherInterface* watcher) { - if (GRPC_TRACE_FLAG_ENABLED(grpc_connectivity_state_trace)) { - gpr_log(GPR_INFO, "ConnectivityStateTracker %s[%p]: remove watcher %p", - name_, this, watcher); - } - watchers_.erase(watcher); +bool grpc_connectivity_state_has_watchers( + grpc_connectivity_state_tracker* connectivity_state) { + return connectivity_state->watchers != nullptr; } -void ConnectivityStateTracker::SetState(grpc_connectivity_state state, - const char* reason) { - grpc_connectivity_state current_state = state_.Load(MemoryOrder::RELAXED); - if (state == current_state) return; +bool grpc_connectivity_state_notify_on_state_change( + grpc_connectivity_state_tracker* tracker, grpc_connectivity_state* current, + grpc_closure* notify) { + grpc_connectivity_state cur = static_cast( + gpr_atm_no_barrier_load(&tracker->current_state_atm)); if (GRPC_TRACE_FLAG_ENABLED(grpc_connectivity_state_trace)) { - gpr_log(GPR_INFO, "ConnectivityStateTracker %s[%p]: %s -> %s (%s)", name_, - this, ConnectivityStateName(current_state), - ConnectivityStateName(state), reason); + if (current == nullptr) { + gpr_log(GPR_INFO, "CONWATCH: %p %s: unsubscribe notify=%p", tracker, + tracker->name, notify); + } else { + gpr_log(GPR_INFO, "CONWATCH: %p %s: from %s [cur=%s] notify=%p", tracker, + tracker->name, grpc_connectivity_state_name(*current), + grpc_connectivity_state_name(cur), notify); + } } - state_.Store(state, MemoryOrder::RELAXED); - for (const auto& p : watchers_) { - if (GRPC_TRACE_FLAG_ENABLED(grpc_connectivity_state_trace)) { - gpr_log(GPR_INFO, - "ConnectivityStateTracker %s[%p]: notifying watcher %p: %s -> %s", - name_, this, p.first, ConnectivityStateName(current_state), - ConnectivityStateName(state)); + if (current == nullptr) { + grpc_connectivity_state_watcher* w = tracker->watchers; + if (w != nullptr && w->notify == notify) { + GRPC_CLOSURE_SCHED(notify, GRPC_ERROR_CANCELLED); + tracker->watchers = w->next; + gpr_free(w); + return false; + } + while (w != nullptr) { + grpc_connectivity_state_watcher* rm_candidate = w->next; + if (rm_candidate != nullptr && rm_candidate->notify == notify) { + GRPC_CLOSURE_SCHED(notify, GRPC_ERROR_CANCELLED); + w->next = w->next->next; + gpr_free(rm_candidate); + return false; + } + w = w->next; } - p.second->Notify(state); + return false; + } else { + if (cur != *current) { + *current = cur; + GRPC_CLOSURE_SCHED(notify, GRPC_ERROR_NONE); + } else { + grpc_connectivity_state_watcher* w = + static_cast(gpr_malloc(sizeof(*w))); + w->current = current; + w->notify = notify; + w->next = tracker->watchers; + tracker->watchers = w; + } + return cur == GRPC_CHANNEL_IDLE; } - // If the new state is SHUTDOWN, orphan all of the watchers. This - // avoids the need for the callers to explicitly cancel them. - if (state == GRPC_CHANNEL_SHUTDOWN) watchers_.clear(); } -grpc_connectivity_state ConnectivityStateTracker::state() const { - grpc_connectivity_state state = state_.Load(MemoryOrder::RELAXED); +void grpc_connectivity_state_set(grpc_connectivity_state_tracker* tracker, + grpc_connectivity_state state, + const char* reason) { + grpc_connectivity_state cur = static_cast( + gpr_atm_no_barrier_load(&tracker->current_state_atm)); + grpc_connectivity_state_watcher* w; if (GRPC_TRACE_FLAG_ENABLED(grpc_connectivity_state_trace)) { - gpr_log(GPR_INFO, "ConnectivityStateTracker %s[%p]: get current state: %s", - name_, this, ConnectivityStateName(state)); + gpr_log(GPR_INFO, "SET: %p %s: %s --> %s [%s]", tracker, tracker->name, + grpc_connectivity_state_name(cur), + grpc_connectivity_state_name(state), reason); + } + if (cur == state) { + return; + } + GPR_ASSERT(cur != GRPC_CHANNEL_SHUTDOWN); + gpr_atm_no_barrier_store(&tracker->current_state_atm, state); + while ((w = tracker->watchers) != nullptr) { + *w->current = state; + tracker->watchers = w->next; + if (GRPC_TRACE_FLAG_ENABLED(grpc_connectivity_state_trace)) { + gpr_log(GPR_INFO, "NOTIFY: %p %s: %p", tracker, tracker->name, w->notify); + } + GRPC_CLOSURE_SCHED(w->notify, GRPC_ERROR_NONE); + gpr_free(w); } - return state; } - -} // namespace grpc_core diff --git a/src/core/lib/transport/connectivity_state.h b/src/core/lib/transport/connectivity_state.h index 41f7bf08e41..0ff1432cb9d 100644 --- a/src/core/lib/transport/connectivity_state.h +++ b/src/core/lib/transport/connectivity_state.h @@ -22,98 +22,58 @@ #include #include - #include "src/core/lib/debug/trace.h" -#include "src/core/lib/gprpp/atomic.h" -#include "src/core/lib/gprpp/map.h" -#include "src/core/lib/gprpp/orphanable.h" #include "src/core/lib/iomgr/closure.h" -namespace grpc_core { - -extern TraceFlag grpc_connectivity_state_trace; - -// Enum to string conversion. -const char* ConnectivityStateName(grpc_connectivity_state state); - -// Interface for watching connectivity state. -// Subclasses must implement the Notify() method. -// -// Note: Most callers will want to use -// AsyncConnectivityStateWatcherInterface instead. -class ConnectivityStateWatcherInterface - : public InternallyRefCounted { - public: - virtual ~ConnectivityStateWatcherInterface() = default; - - // Notifies the watcher that the state has changed to new_state. - virtual void Notify(grpc_connectivity_state new_state) GRPC_ABSTRACT; - - void Orphan() override { Unref(); } - - GRPC_ABSTRACT_BASE_CLASS -}; - -// An alternative watcher interface that performs notifications via an -// asynchronous callback scheduled on the ExecCtx. -// Subclasses must implement the OnConnectivityStateChange() method. -class AsyncConnectivityStateWatcherInterface - : public ConnectivityStateWatcherInterface { - public: - virtual ~AsyncConnectivityStateWatcherInterface() = default; - - // Schedules a closure on the ExecCtx to invoke - // OnConnectivityStateChange() asynchronously. - void Notify(grpc_connectivity_state new_state) override final; - - protected: - class Notifier; - - // Invoked asynchronously when Notify() is called. - virtual void OnConnectivityStateChange(grpc_connectivity_state new_state) - GRPC_ABSTRACT; -}; - -// Tracks connectivity state. Maintains a list of watchers that are -// notified whenever the state changes. -class ConnectivityStateTracker { - public: - ConnectivityStateTracker(const char* name, - grpc_connectivity_state state = GRPC_CHANNEL_IDLE) - : name_(name), state_(state) {} - - ~ConnectivityStateTracker(); - - // Adds a watcher. - // If the current state is different than initial_state, the watcher - // will be notified immediately. Otherwise, it will be notified - // whenever the state changes. - // Not thread safe; access must be serialized with an external lock. - void AddWatcher(grpc_connectivity_state initial_state, - OrphanablePtr watcher); - - // Removes a watcher. The watcher will be orphaned. - // Not thread safe; access must be serialized with an external lock. - void RemoveWatcher(ConnectivityStateWatcherInterface* watcher); - - // Sets connectivity state. - // Not thread safe; access must be serialized with an external lock. - void SetState(grpc_connectivity_state state, const char* reason); - - // Gets the current state. - // Thread safe; no need to use an external lock. - grpc_connectivity_state state() const; - - private: - const char* name_; - Atomic state_; - // TODO(roth): This could be a set instead of a map if we had a set - // implementation. - Map> - watchers_; -}; - -} // namespace grpc_core +typedef struct grpc_connectivity_state_watcher { + /** we keep watchers in a linked list */ + struct grpc_connectivity_state_watcher* next; + /** closure to notify on change */ + grpc_closure* notify; + /** the current state as believed by the watcher */ + grpc_connectivity_state* current; +} grpc_connectivity_state_watcher; + +typedef struct { + /** current grpc_connectivity_state */ + gpr_atm current_state_atm; + /** all our watchers */ + grpc_connectivity_state_watcher* watchers; + /** a name to help debugging */ + char* name; +} grpc_connectivity_state_tracker; + +extern grpc_core::TraceFlag grpc_connectivity_state_trace; + +/** enum --> string conversion */ +const char* grpc_connectivity_state_name(grpc_connectivity_state state); + +void grpc_connectivity_state_init(grpc_connectivity_state_tracker* tracker, + grpc_connectivity_state init_state, + const char* name); +void grpc_connectivity_state_destroy(grpc_connectivity_state_tracker* tracker); + +/** Set connectivity state; not thread safe; access must be serialized with an + * external lock */ +void grpc_connectivity_state_set(grpc_connectivity_state_tracker* tracker, + grpc_connectivity_state state, + const char* reason); + +/** Return true if this connectivity state has watchers. + Access must be serialized with an external lock. */ +bool grpc_connectivity_state_has_watchers( + grpc_connectivity_state_tracker* tracker); + +/** Return the last seen connectivity state. No need to synchronize access. */ +grpc_connectivity_state grpc_connectivity_state_check( + grpc_connectivity_state_tracker* tracker); + +/** Return 1 if the channel should start connecting, 0 otherwise. + If current==NULL cancel notify if it is already queued (success==0 in that + case). + Access must be serialized with an external lock. */ +bool grpc_connectivity_state_notify_on_state_change( + grpc_connectivity_state_tracker* tracker, grpc_connectivity_state* current, + grpc_closure* notify); #endif /* GRPC_CORE_LIB_TRANSPORT_CONNECTIVITY_STATE_H */ diff --git a/src/core/lib/transport/transport.h b/src/core/lib/transport/transport.h index a46338310ae..c40b290d535 100644 --- a/src/core/lib/transport/transport.h +++ b/src/core/lib/transport/transport.h @@ -25,7 +25,6 @@ #include "src/core/lib/channel/context.h" #include "src/core/lib/gprpp/arena.h" -#include "src/core/lib/gprpp/orphanable.h" #include "src/core/lib/iomgr/call_combiner.h" #include "src/core/lib/iomgr/endpoint.h" #include "src/core/lib/iomgr/polling_entity.h" @@ -33,7 +32,6 @@ #include "src/core/lib/iomgr/pollset_set.h" #include "src/core/lib/slice/slice_internal.h" #include "src/core/lib/transport/byte_stream.h" -#include "src/core/lib/transport/connectivity_state.h" #include "src/core/lib/transport/metadata_batch.h" /* Minimum and maximum protocol accepted versions. */ @@ -322,11 +320,8 @@ typedef struct grpc_transport_op { /** Called when processing of this op is done. */ grpc_closure* on_consumed = nullptr; /** connectivity monitoring - set connectivity_state to NULL to unsubscribe */ - grpc_core::OrphanablePtr - start_connectivity_watch; - grpc_connectivity_state start_connectivity_watch_state = GRPC_CHANNEL_IDLE; - grpc_core::ConnectivityStateWatcherInterface* stop_connectivity_watch = - nullptr; + grpc_closure* on_connectivity_state_change = nullptr; + grpc_connectivity_state* connectivity_state = nullptr; /** should the transport be disconnected * Error contract: the transport that gets this op must cause * disconnect_with_error to be unref'ed after processing it */ diff --git a/src/core/lib/transport/transport_op_string.cc b/src/core/lib/transport/transport_op_string.cc index 34b36c3aec9..8c7db642a54 100644 --- a/src/core/lib/transport/transport_op_string.cc +++ b/src/core/lib/transport/transport_op_string.cc @@ -134,22 +134,19 @@ char* grpc_transport_op_string(grpc_transport_op* op) { gpr_strvec b; gpr_strvec_init(&b); - if (op->start_connectivity_watch != nullptr) { + if (op->on_connectivity_state_change != nullptr) { if (!first) gpr_strvec_add(&b, gpr_strdup(" ")); first = false; - gpr_asprintf( - &tmp, "START_CONNECTIVITY_WATCH:watcher=%p:from=%s", - op->start_connectivity_watch.get(), - grpc_core::ConnectivityStateName(op->start_connectivity_watch_state)); - gpr_strvec_add(&b, tmp); - } - - if (op->stop_connectivity_watch != nullptr) { - if (!first) gpr_strvec_add(&b, gpr_strdup(" ")); - first = false; - gpr_asprintf(&tmp, "STOP_CONNECTIVITY_WATCH:watcher=%p", - op->stop_connectivity_watch); - gpr_strvec_add(&b, tmp); + if (op->connectivity_state != nullptr) { + gpr_asprintf(&tmp, "ON_CONNECTIVITY_STATE_CHANGE:p=%p:from=%s", + op->on_connectivity_state_change, + grpc_connectivity_state_name(*op->connectivity_state)); + gpr_strvec_add(&b, tmp); + } else { + gpr_asprintf(&tmp, "ON_CONNECTIVITY_STATE_CHANGE:p=%p:unsubscribe", + op->on_connectivity_state_change); + gpr_strvec_add(&b, tmp); + } } if (op->disconnect_with_error != GRPC_ERROR_NONE) { diff --git a/test/core/surface/lame_client_test.cc b/test/core/surface/lame_client_test.cc index 34cafbbd5b7..09c3d431977 100644 --- a/test/core/surface/lame_client_test.cc +++ b/test/core/surface/lame_client_test.cc @@ -28,27 +28,31 @@ #include "test/core/end2end/cq_verifier.h" #include "test/core/util/test_config.h" -class Watcher : public grpc_core::ConnectivityStateWatcherInterface { - public: - void Notify(grpc_connectivity_state new_state) override { - GPR_ASSERT(new_state == GRPC_CHANNEL_SHUTDOWN); - } -}; +grpc_closure transport_op_cb; static void* tag(intptr_t x) { return (void*)x; } -static grpc_closure transport_op_cb; +void verify_connectivity(void* arg, grpc_error* error) { + grpc_connectivity_state* state = static_cast(arg); + GPR_ASSERT(GRPC_CHANNEL_SHUTDOWN == *state); + GPR_ASSERT(error == GRPC_ERROR_NONE); +} -static void do_nothing(void* arg, grpc_error* error) {} +void do_nothing(void* arg, grpc_error* error) {} void test_transport_op(grpc_channel* channel) { + grpc_transport_op* op; + grpc_channel_element* elem; + grpc_connectivity_state state = GRPC_CHANNEL_IDLE; grpc_core::ExecCtx exec_ctx; - grpc_transport_op* op = grpc_make_transport_op(nullptr); - op->start_connectivity_watch = - grpc_core::OrphanablePtr( - grpc_core::New()); - grpc_channel_element* elem = - grpc_channel_stack_element(grpc_channel_get_channel_stack(channel), 0); + + GRPC_CLOSURE_INIT(&transport_op_cb, verify_connectivity, &state, + grpc_schedule_on_exec_ctx); + + op = grpc_make_transport_op(nullptr); + op->on_connectivity_state_change = &transport_op_cb; + op->connectivity_state = &state; + elem = grpc_channel_stack_element(grpc_channel_get_channel_stack(channel), 0); elem->filter->start_transport_op(elem, op); GRPC_CLOSURE_INIT(&transport_op_cb, do_nothing, nullptr, diff --git a/test/core/transport/BUILD b/test/core/transport/BUILD index 12e748f7d10..94ebb602d80 100644 --- a/test/core/transport/BUILD +++ b/test/core/transport/BUILD @@ -51,9 +51,6 @@ grpc_cc_test( grpc_cc_test( name = "connectivity_state_test", srcs = ["connectivity_state_test.cc"], - external_deps = [ - "gtest", - ], language = "C++", deps = [ "//:gpr", diff --git a/test/core/transport/connectivity_state_test.cc b/test/core/transport/connectivity_state_test.cc index e0141cd02d0..26c09a76039 100644 --- a/test/core/transport/connectivity_state_test.cc +++ b/test/core/transport/connectivity_state_test.cc @@ -20,146 +20,124 @@ #include -#include - #include #include "src/core/lib/iomgr/exec_ctx.h" #include "test/core/util/test_config.h" #include "test/core/util/tracer_util.h" -namespace grpc_core { -namespace { +#define THE_ARG ((void*)(size_t)0xcafebabe) + +int g_counter; -TEST(ConnectivityStateName, Basic) { - EXPECT_STREQ("IDLE", ConnectivityStateName(GRPC_CHANNEL_IDLE)); - EXPECT_STREQ("CONNECTING", ConnectivityStateName(GRPC_CHANNEL_CONNECTING)); - EXPECT_STREQ("READY", ConnectivityStateName(GRPC_CHANNEL_READY)); - EXPECT_STREQ("TRANSIENT_FAILURE", - ConnectivityStateName(GRPC_CHANNEL_TRANSIENT_FAILURE)); - EXPECT_STREQ("SHUTDOWN", ConnectivityStateName(GRPC_CHANNEL_SHUTDOWN)); +static void must_succeed(void* arg, grpc_error* error) { + GPR_ASSERT(error == GRPC_ERROR_NONE); + GPR_ASSERT(arg == THE_ARG); + g_counter++; } -class Watcher : public ConnectivityStateWatcherInterface { - public: - Watcher(int* count, grpc_connectivity_state* output, - bool* destroyed = nullptr) - : count_(count), output_(output), destroyed_(destroyed) {} - - ~Watcher() { - if (destroyed_ != nullptr) *destroyed_ = true; - } - - void Notify(grpc_connectivity_state new_state) override { - ++*count_; - *output_ = new_state; - } - - private: - int* count_; - grpc_connectivity_state* output_; - bool* destroyed_; -}; - -TEST(StateTracker, SetAndGetState) { - ConnectivityStateTracker tracker("xxx", GRPC_CHANNEL_CONNECTING); - EXPECT_EQ(tracker.state(), GRPC_CHANNEL_CONNECTING); - tracker.SetState(GRPC_CHANNEL_READY, "whee"); - EXPECT_EQ(tracker.state(), GRPC_CHANNEL_READY); +static void must_fail(void* arg, grpc_error* error) { + GPR_ASSERT(error != GRPC_ERROR_NONE); + GPR_ASSERT(arg == THE_ARG); + g_counter++; } -TEST(StateTracker, NotificationUponAddingWatcher) { - int count = 0; - grpc_connectivity_state state = GRPC_CHANNEL_IDLE; - ConnectivityStateTracker tracker("xxx", GRPC_CHANNEL_CONNECTING); - tracker.AddWatcher(GRPC_CHANNEL_IDLE, - OrphanablePtr( - New(&count, &state))); - EXPECT_EQ(count, 1); - EXPECT_EQ(state, GRPC_CHANNEL_CONNECTING); +static void test_connectivity_state_name(void) { + gpr_log(GPR_DEBUG, "test_connectivity_state_name"); + GPR_ASSERT(0 == + strcmp(grpc_connectivity_state_name(GRPC_CHANNEL_IDLE), "IDLE")); + GPR_ASSERT(0 == strcmp(grpc_connectivity_state_name(GRPC_CHANNEL_CONNECTING), + "CONNECTING")); + GPR_ASSERT(0 == + strcmp(grpc_connectivity_state_name(GRPC_CHANNEL_READY), "READY")); + GPR_ASSERT( + 0 == strcmp(grpc_connectivity_state_name(GRPC_CHANNEL_TRANSIENT_FAILURE), + "TRANSIENT_FAILURE")); + GPR_ASSERT(0 == strcmp(grpc_connectivity_state_name(GRPC_CHANNEL_SHUTDOWN), + "SHUTDOWN")); } -TEST(StateTracker, NotificationUponStateChange) { - int count = 0; - grpc_connectivity_state state = GRPC_CHANNEL_IDLE; - ConnectivityStateTracker tracker("xxx", GRPC_CHANNEL_IDLE); - tracker.AddWatcher(GRPC_CHANNEL_IDLE, - OrphanablePtr( - New(&count, &state))); - EXPECT_EQ(count, 0); - EXPECT_EQ(state, GRPC_CHANNEL_IDLE); - tracker.SetState(GRPC_CHANNEL_CONNECTING, "whee"); - EXPECT_EQ(count, 1); - EXPECT_EQ(state, GRPC_CHANNEL_CONNECTING); +static void test_check(void) { + grpc_connectivity_state_tracker tracker; + grpc_core::ExecCtx exec_ctx; + gpr_log(GPR_DEBUG, "test_check"); + grpc_connectivity_state_init(&tracker, GRPC_CHANNEL_IDLE, "xxx"); + GPR_ASSERT(grpc_connectivity_state_check(&tracker) == GRPC_CHANNEL_IDLE); + grpc_connectivity_state_destroy(&tracker); } -TEST(StateTracker, SubscribeThenUnsubscribe) { - int count = 0; +static void test_subscribe_then_unsubscribe(void) { + grpc_connectivity_state_tracker tracker; + grpc_closure* closure = + GRPC_CLOSURE_CREATE(must_fail, THE_ARG, grpc_schedule_on_exec_ctx); grpc_connectivity_state state = GRPC_CHANNEL_IDLE; - bool destroyed = false; - ConnectivityStateTracker tracker("xxx", GRPC_CHANNEL_IDLE); - ConnectivityStateWatcherInterface* watcher = - New(&count, &state, &destroyed); - tracker.AddWatcher(GRPC_CHANNEL_IDLE, - OrphanablePtr(watcher)); - // No initial notification, since we started the watch from the - // current state. - EXPECT_EQ(count, 0); - EXPECT_EQ(state, GRPC_CHANNEL_IDLE); - // Cancel watch. This should not generate another notification. - tracker.RemoveWatcher(watcher); - EXPECT_TRUE(destroyed); - EXPECT_EQ(count, 0); - EXPECT_EQ(state, GRPC_CHANNEL_IDLE); + grpc_core::ExecCtx exec_ctx; + gpr_log(GPR_DEBUG, "test_subscribe_then_unsubscribe"); + g_counter = 0; + grpc_connectivity_state_init(&tracker, GRPC_CHANNEL_IDLE, "xxx"); + GPR_ASSERT(grpc_connectivity_state_notify_on_state_change(&tracker, &state, + closure)); + grpc_core::ExecCtx::Get()->Flush(); + GPR_ASSERT(state == GRPC_CHANNEL_IDLE); + GPR_ASSERT(g_counter == 0); + grpc_connectivity_state_notify_on_state_change(&tracker, nullptr, closure); + grpc_core::ExecCtx::Get()->Flush(); + GPR_ASSERT(state == GRPC_CHANNEL_IDLE); + GPR_ASSERT(g_counter == 1); + + grpc_connectivity_state_destroy(&tracker); } -TEST(StateTracker, NotifyShutdownAtDestruction) { - int count = 0; +static void test_subscribe_then_destroy(void) { + grpc_connectivity_state_tracker tracker; + grpc_closure* closure = + GRPC_CLOSURE_CREATE(must_succeed, THE_ARG, grpc_schedule_on_exec_ctx); grpc_connectivity_state state = GRPC_CHANNEL_IDLE; - { - ConnectivityStateTracker tracker("xxx", GRPC_CHANNEL_IDLE); - tracker.AddWatcher(GRPC_CHANNEL_IDLE, - OrphanablePtr( - New(&count, &state))); - // No initial notification, since we started the watch from the - // current state. - EXPECT_EQ(count, 0); - EXPECT_EQ(state, GRPC_CHANNEL_IDLE); - } - // Upon tracker destruction, we get a notification for SHUTDOWN. - EXPECT_EQ(count, 1); - EXPECT_EQ(state, GRPC_CHANNEL_SHUTDOWN); + grpc_core::ExecCtx exec_ctx; + gpr_log(GPR_DEBUG, "test_subscribe_then_destroy"); + g_counter = 0; + grpc_connectivity_state_init(&tracker, GRPC_CHANNEL_IDLE, "xxx"); + GPR_ASSERT(grpc_connectivity_state_notify_on_state_change(&tracker, &state, + closure)); + grpc_core::ExecCtx::Get()->Flush(); + GPR_ASSERT(state == GRPC_CHANNEL_IDLE); + GPR_ASSERT(g_counter == 0); + grpc_connectivity_state_destroy(&tracker); + + grpc_core::ExecCtx::Get()->Flush(); + GPR_ASSERT(state == GRPC_CHANNEL_SHUTDOWN); + GPR_ASSERT(g_counter == 1); } -TEST(StateTracker, DoNotNotifyShutdownAtDestructionIfAlreadyInShutdown) { - int count = 0; +static void test_subscribe_with_failure_then_destroy(void) { + grpc_connectivity_state_tracker tracker; + grpc_closure* closure = + GRPC_CLOSURE_CREATE(must_fail, THE_ARG, grpc_schedule_on_exec_ctx); grpc_connectivity_state state = GRPC_CHANNEL_SHUTDOWN; - { - ConnectivityStateTracker tracker("xxx", GRPC_CHANNEL_SHUTDOWN); - tracker.AddWatcher(GRPC_CHANNEL_SHUTDOWN, - OrphanablePtr( - New(&count, &state))); - // No initial notification, since we started the watch from the - // current state. - EXPECT_EQ(count, 0); - EXPECT_EQ(state, GRPC_CHANNEL_SHUTDOWN); - } - // No additional notification upon tracker destruction, since we were - // already in state SHUTDOWN. - EXPECT_EQ(count, 0); - EXPECT_EQ(state, GRPC_CHANNEL_SHUTDOWN); + grpc_core::ExecCtx exec_ctx; + gpr_log(GPR_DEBUG, "test_subscribe_with_failure_then_destroy"); + g_counter = 0; + grpc_connectivity_state_init(&tracker, GRPC_CHANNEL_SHUTDOWN, "xxx"); + GPR_ASSERT(0 == grpc_connectivity_state_notify_on_state_change( + &tracker, &state, closure)); + grpc_core::ExecCtx::Get()->Flush(); + GPR_ASSERT(state == GRPC_CHANNEL_SHUTDOWN); + GPR_ASSERT(g_counter == 0); + grpc_connectivity_state_destroy(&tracker); + grpc_core::ExecCtx::Get()->Flush(); + GPR_ASSERT(state == GRPC_CHANNEL_SHUTDOWN); + GPR_ASSERT(g_counter == 1); } -} // namespace -} // namespace grpc_core - int main(int argc, char** argv) { grpc::testing::TestEnvironment env(argc, argv); grpc_init(); - grpc_core::testing::grpc_tracer_enable_flag( - &grpc_core::grpc_connectivity_state_trace); - ::testing::InitGoogleTest(&argc, argv); - int ret = RUN_ALL_TESTS(); + grpc_core::testing::grpc_tracer_enable_flag(&grpc_connectivity_state_trace); + test_connectivity_state_name(); + test_check(); + test_subscribe_then_unsubscribe(); + test_subscribe_then_destroy(); + test_subscribe_with_failure_then_destroy(); grpc_shutdown(); - return ret; + return 0; } diff --git a/tools/run_tests/generated/tests.json b/tools/run_tests/generated/tests.json index b4b3822bde5..1f9634e34e3 100644 --- a/tools/run_tests/generated/tests.json +++ b/tools/run_tests/generated/tests.json @@ -2917,6 +2917,30 @@ ], "uses_polling": false }, + { + "args": [], + "benchmark": false, + "ci_platforms": [ + "linux", + "mac", + "posix", + "windows" + ], + "cpu_cost": 1.0, + "exclude_configs": [], + "exclude_iomgrs": [], + "flaky": false, + "gtest": false, + "language": "c", + "name": "transport_connectivity_state_test", + "platforms": [ + "linux", + "mac", + "posix", + "windows" + ], + "uses_polling": true + }, { "args": [], "benchmark": false, @@ -5970,30 +5994,6 @@ ], "uses_polling": true }, - { - "args": [], - "benchmark": false, - "ci_platforms": [ - "linux", - "mac", - "posix", - "windows" - ], - "cpu_cost": 1.0, - "exclude_configs": [], - "exclude_iomgrs": [], - "flaky": false, - "gtest": true, - "language": "c++", - "name": "transport_connectivity_state_test", - "platforms": [ - "linux", - "mac", - "posix", - "windows" - ], - "uses_polling": true - }, { "args": [], "benchmark": false, From cb67811c47daa5f6ffda2170a0f55e39694d9b14 Mon Sep 17 00:00:00 2001 From: "Mark D. Roth" Date: Mon, 30 Sep 2019 11:22:32 -0700 Subject: [PATCH 34/60] Revert "Merge pull request #20407 from markdroth/transport_connectivity_state_watcher_revert" This reverts commit 48550de8668a169d5f437033fddc499a0848fb5c, reversing changes made to 24b529e408bcf10f067663f1bb745b08a58f898c. --- CMakeLists.txt | 73 +++--- Makefile | 84 ++++--- build.yaml | 19 +- .../filters/client_channel/client_channel.cc | 235 ++++++++---------- .../filters/client_channel/client_channel.h | 6 + .../client_channel/client_channel_channelz.cc | 5 +- .../client_channel/lb_policy/grpclb/grpclb.cc | 8 +- .../lb_policy/pick_first/pick_first.cc | 2 +- .../lb_policy/round_robin/round_robin.cc | 4 +- .../lb_policy/subchannel_list.h | 6 +- .../client_channel/lb_policy/xds/xds.cc | 6 +- .../client_channel/resolving_lb_policy.cc | 3 +- .../ext/filters/client_channel/subchannel.cc | 97 +++----- .../ext/filters/client_channel/subchannel.h | 6 +- .../ext/filters/max_age/max_age_filter.cc | 82 +++--- .../chttp2/transport/chttp2_transport.cc | 31 ++- .../ext/transport/chttp2/transport/internal.h | 16 +- .../ext/transport/inproc/inproc_transport.cc | 23 +- src/core/lib/channel/channelz.cc | 3 +- src/core/lib/surface/lame_client.cc | 29 ++- src/core/lib/surface/server.cc | 63 +++-- src/core/lib/transport/connectivity_state.cc | 203 +++++++-------- src/core/lib/transport/connectivity_state.h | 140 +++++++---- src/core/lib/transport/transport.h | 9 +- src/core/lib/transport/transport_op_string.cc | 25 +- test/core/surface/lame_client_test.cc | 32 ++- test/core/transport/BUILD | 3 + .../core/transport/connectivity_state_test.cc | 206 ++++++++------- tools/run_tests/generated/tests.json | 48 ++-- 29 files changed, 771 insertions(+), 696 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 6ce00ecacdf..518ca81c664 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -427,7 +427,6 @@ add_dependencies(buildtests_c time_averaged_stats_test) add_dependencies(buildtests_c timeout_encoding_test) add_dependencies(buildtests_c timer_heap_test) add_dependencies(buildtests_c timer_list_test) -add_dependencies(buildtests_c transport_connectivity_state_test) add_dependencies(buildtests_c transport_metadata_test) if(_gRPC_PLATFORM_LINUX OR _gRPC_PLATFORM_MAC OR _gRPC_PLATFORM_POSIX) add_dependencies(buildtests_c transport_security_test) @@ -726,6 +725,7 @@ if(_gRPC_PLATFORM_LINUX OR _gRPC_PLATFORM_MAC OR _gRPC_PLATFORM_POSIX) add_dependencies(buildtests_cxx time_change_test) endif() add_dependencies(buildtests_cxx timer_test) +add_dependencies(buildtests_cxx transport_connectivity_state_test) add_dependencies(buildtests_cxx transport_pid_controller_test) add_dependencies(buildtests_cxx transport_security_common_api_test) if(_gRPC_PLATFORM_LINUX OR _gRPC_PLATFORM_MAC OR _gRPC_PLATFORM_POSIX) @@ -9847,37 +9847,6 @@ target_link_libraries(timer_list_test ) -endif (gRPC_BUILD_TESTS) -if (gRPC_BUILD_TESTS) - -add_executable(transport_connectivity_state_test - test/core/transport/connectivity_state_test.cc -) - - -target_include_directories(transport_connectivity_state_test - PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} - PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include - PRIVATE ${_gRPC_ADDRESS_SORTING_INCLUDE_DIR} - PRIVATE ${_gRPC_BENCHMARK_INCLUDE_DIR} - PRIVATE ${_gRPC_CARES_INCLUDE_DIR} - PRIVATE ${_gRPC_GFLAGS_INCLUDE_DIR} - PRIVATE ${_gRPC_PROTOBUF_INCLUDE_DIR} - PRIVATE ${_gRPC_SSL_INCLUDE_DIR} - PRIVATE ${_gRPC_UPB_GENERATED_DIR} - PRIVATE ${_gRPC_UPB_GRPC_GENERATED_DIR} - PRIVATE ${_gRPC_UPB_INCLUDE_DIR} - PRIVATE ${_gRPC_ZLIB_INCLUDE_DIR} -) - -target_link_libraries(transport_connectivity_state_test - ${_gRPC_ALLTARGETS_LIBRARIES} - grpc_test_util - grpc - gpr -) - - endif (gRPC_BUILD_TESTS) if (gRPC_BUILD_TESTS) @@ -16692,6 +16661,46 @@ target_link_libraries(timer_test ) +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(transport_connectivity_state_test + test/core/transport/connectivity_state_test.cc + third_party/googletest/googletest/src/gtest-all.cc + third_party/googletest/googlemock/src/gmock-all.cc +) + + +target_include_directories(transport_connectivity_state_test + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${_gRPC_ADDRESS_SORTING_INCLUDE_DIR} + PRIVATE ${_gRPC_BENCHMARK_INCLUDE_DIR} + PRIVATE ${_gRPC_CARES_INCLUDE_DIR} + PRIVATE ${_gRPC_GFLAGS_INCLUDE_DIR} + PRIVATE ${_gRPC_PROTOBUF_INCLUDE_DIR} + PRIVATE ${_gRPC_SSL_INCLUDE_DIR} + PRIVATE ${_gRPC_UPB_GENERATED_DIR} + PRIVATE ${_gRPC_UPB_GRPC_GENERATED_DIR} + PRIVATE ${_gRPC_UPB_INCLUDE_DIR} + PRIVATE ${_gRPC_ZLIB_INCLUDE_DIR} + PRIVATE third_party/googletest/googletest/include + PRIVATE third_party/googletest/googletest + PRIVATE third_party/googletest/googlemock/include + PRIVATE third_party/googletest/googlemock + PRIVATE ${_gRPC_PROTO_GENS_DIR} +) + +target_link_libraries(transport_connectivity_state_test + ${_gRPC_PROTOBUF_LIBRARIES} + ${_gRPC_ALLTARGETS_LIBRARIES} + grpc_test_util + grpc + gpr + ${_gRPC_GFLAGS_LIBRARIES} +) + + endif (gRPC_BUILD_TESTS) if (gRPC_BUILD_TESTS) diff --git a/Makefile b/Makefile index 728402c8bc0..20e01d6c10c 100644 --- a/Makefile +++ b/Makefile @@ -1137,7 +1137,6 @@ time_averaged_stats_test: $(BINDIR)/$(CONFIG)/time_averaged_stats_test timeout_encoding_test: $(BINDIR)/$(CONFIG)/timeout_encoding_test timer_heap_test: $(BINDIR)/$(CONFIG)/timer_heap_test timer_list_test: $(BINDIR)/$(CONFIG)/timer_list_test -transport_connectivity_state_test: $(BINDIR)/$(CONFIG)/transport_connectivity_state_test transport_metadata_test: $(BINDIR)/$(CONFIG)/transport_metadata_test transport_security_test: $(BINDIR)/$(CONFIG)/transport_security_test udp_server_test: $(BINDIR)/$(CONFIG)/udp_server_test @@ -1294,6 +1293,7 @@ thread_manager_test: $(BINDIR)/$(CONFIG)/thread_manager_test thread_stress_test: $(BINDIR)/$(CONFIG)/thread_stress_test time_change_test: $(BINDIR)/$(CONFIG)/time_change_test timer_test: $(BINDIR)/$(CONFIG)/timer_test +transport_connectivity_state_test: $(BINDIR)/$(CONFIG)/transport_connectivity_state_test transport_pid_controller_test: $(BINDIR)/$(CONFIG)/transport_pid_controller_test transport_security_common_api_test: $(BINDIR)/$(CONFIG)/transport_security_common_api_test writes_per_rpc_test: $(BINDIR)/$(CONFIG)/writes_per_rpc_test @@ -1563,7 +1563,6 @@ buildtests_c: privatelibs_c \ $(BINDIR)/$(CONFIG)/timeout_encoding_test \ $(BINDIR)/$(CONFIG)/timer_heap_test \ $(BINDIR)/$(CONFIG)/timer_list_test \ - $(BINDIR)/$(CONFIG)/transport_connectivity_state_test \ $(BINDIR)/$(CONFIG)/transport_metadata_test \ $(BINDIR)/$(CONFIG)/transport_security_test \ $(BINDIR)/$(CONFIG)/udp_server_test \ @@ -1766,6 +1765,7 @@ buildtests_cxx: privatelibs_cxx \ $(BINDIR)/$(CONFIG)/thread_stress_test \ $(BINDIR)/$(CONFIG)/time_change_test \ $(BINDIR)/$(CONFIG)/timer_test \ + $(BINDIR)/$(CONFIG)/transport_connectivity_state_test \ $(BINDIR)/$(CONFIG)/transport_pid_controller_test \ $(BINDIR)/$(CONFIG)/transport_security_common_api_test \ $(BINDIR)/$(CONFIG)/writes_per_rpc_test \ @@ -1936,6 +1936,7 @@ buildtests_cxx: privatelibs_cxx \ $(BINDIR)/$(CONFIG)/thread_stress_test \ $(BINDIR)/$(CONFIG)/time_change_test \ $(BINDIR)/$(CONFIG)/timer_test \ + $(BINDIR)/$(CONFIG)/transport_connectivity_state_test \ $(BINDIR)/$(CONFIG)/transport_pid_controller_test \ $(BINDIR)/$(CONFIG)/transport_security_common_api_test \ $(BINDIR)/$(CONFIG)/writes_per_rpc_test \ @@ -2213,8 +2214,6 @@ test_c: buildtests_c $(Q) $(BINDIR)/$(CONFIG)/timer_heap_test || ( echo test timer_heap_test failed ; exit 1 ) $(E) "[RUN] Testing timer_list_test" $(Q) $(BINDIR)/$(CONFIG)/timer_list_test || ( echo test timer_list_test failed ; exit 1 ) - $(E) "[RUN] Testing transport_connectivity_state_test" - $(Q) $(BINDIR)/$(CONFIG)/transport_connectivity_state_test || ( echo test transport_connectivity_state_test failed ; exit 1 ) $(E) "[RUN] Testing transport_metadata_test" $(Q) $(BINDIR)/$(CONFIG)/transport_metadata_test || ( echo test transport_metadata_test failed ; exit 1 ) $(E) "[RUN] Testing transport_security_test" @@ -2481,6 +2480,8 @@ test_cxx: buildtests_cxx $(Q) $(BINDIR)/$(CONFIG)/time_change_test || ( echo test time_change_test failed ; exit 1 ) $(E) "[RUN] Testing timer_test" $(Q) $(BINDIR)/$(CONFIG)/timer_test || ( echo test timer_test failed ; exit 1 ) + $(E) "[RUN] Testing transport_connectivity_state_test" + $(Q) $(BINDIR)/$(CONFIG)/transport_connectivity_state_test || ( echo test transport_connectivity_state_test failed ; exit 1 ) $(E) "[RUN] Testing transport_pid_controller_test" $(Q) $(BINDIR)/$(CONFIG)/transport_pid_controller_test || ( echo test transport_pid_controller_test failed ; exit 1 ) $(E) "[RUN] Testing transport_security_common_api_test" @@ -13179,38 +13180,6 @@ endif endif -TRANSPORT_CONNECTIVITY_STATE_TEST_SRC = \ - test/core/transport/connectivity_state_test.cc \ - -TRANSPORT_CONNECTIVITY_STATE_TEST_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(TRANSPORT_CONNECTIVITY_STATE_TEST_SRC)))) -ifeq ($(NO_SECURE),true) - -# You can't build secure targets if you don't have OpenSSL. - -$(BINDIR)/$(CONFIG)/transport_connectivity_state_test: openssl_dep_error - -else - - - -$(BINDIR)/$(CONFIG)/transport_connectivity_state_test: $(TRANSPORT_CONNECTIVITY_STATE_TEST_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr.a - $(E) "[LD] Linking $@" - $(Q) mkdir -p `dirname $@` - $(Q) $(LDXX) $(LDFLAGS) $(TRANSPORT_CONNECTIVITY_STATE_TEST_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LDLIBS) $(LDLIBS_SECURE) -o $(BINDIR)/$(CONFIG)/transport_connectivity_state_test - -endif - -$(OBJDIR)/$(CONFIG)/test/core/transport/connectivity_state_test.o: $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr.a - -deps_transport_connectivity_state_test: $(TRANSPORT_CONNECTIVITY_STATE_TEST_OBJS:.o=.dep) - -ifneq ($(NO_SECURE),true) -ifneq ($(NO_DEPS),true) --include $(TRANSPORT_CONNECTIVITY_STATE_TEST_OBJS:.o=.dep) -endif -endif - - TRANSPORT_METADATA_TEST_SRC = \ test/core/transport/metadata_test.cc \ @@ -19952,6 +19921,49 @@ endif endif +TRANSPORT_CONNECTIVITY_STATE_TEST_SRC = \ + test/core/transport/connectivity_state_test.cc \ + +TRANSPORT_CONNECTIVITY_STATE_TEST_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(TRANSPORT_CONNECTIVITY_STATE_TEST_SRC)))) +ifeq ($(NO_SECURE),true) + +# You can't build secure targets if you don't have OpenSSL. + +$(BINDIR)/$(CONFIG)/transport_connectivity_state_test: openssl_dep_error + +else + + + + +ifeq ($(NO_PROTOBUF),true) + +# You can't build the protoc plugins or protobuf-enabled targets if you don't have protobuf 3.5.0+. + +$(BINDIR)/$(CONFIG)/transport_connectivity_state_test: protobuf_dep_error + +else + +$(BINDIR)/$(CONFIG)/transport_connectivity_state_test: $(PROTOBUF_DEP) $(TRANSPORT_CONNECTIVITY_STATE_TEST_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr.a + $(E) "[LD] Linking $@" + $(Q) mkdir -p `dirname $@` + $(Q) $(LDXX) $(LDFLAGS) $(TRANSPORT_CONNECTIVITY_STATE_TEST_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LDLIBSXX) $(LDLIBS_PROTOBUF) $(LDLIBS) $(LDLIBS_SECURE) $(GTEST_LIB) -o $(BINDIR)/$(CONFIG)/transport_connectivity_state_test + +endif + +endif + +$(OBJDIR)/$(CONFIG)/test/core/transport/connectivity_state_test.o: $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr.a + +deps_transport_connectivity_state_test: $(TRANSPORT_CONNECTIVITY_STATE_TEST_OBJS:.o=.dep) + +ifneq ($(NO_SECURE),true) +ifneq ($(NO_DEPS),true) +-include $(TRANSPORT_CONNECTIVITY_STATE_TEST_OBJS:.o=.dep) +endif +endif + + TRANSPORT_PID_CONTROLLER_TEST_SRC = \ test/core/transport/pid_controller_test.cc \ diff --git a/build.yaml b/build.yaml index f37c59d7ccf..81058a6d1c9 100644 --- a/build.yaml +++ b/build.yaml @@ -3847,15 +3847,6 @@ targets: exclude_iomgrs: - uv uses_polling: false -- name: transport_connectivity_state_test - build: test - language: c - src: - - test/core/transport/connectivity_state_test.cc - deps: - - grpc_test_util - - grpc - - gpr - name: transport_metadata_test build: test language: c @@ -5989,6 +5980,16 @@ targets: - grpc++ - grpc - gpr +- name: transport_connectivity_state_test + gtest: true + build: test + language: c++ + src: + - test/core/transport/connectivity_state_test.cc + deps: + - grpc_test_util + - grpc + - gpr - name: transport_pid_controller_test build: test language: c++ diff --git a/src/core/ext/filters/client_channel/client_channel.cc b/src/core/ext/filters/client_channel/client_channel.cc index 0a9b5ac43fb..5aed2e113e0 100644 --- a/src/core/ext/filters/client_channel/client_channel.cc +++ b/src/core/ext/filters/client_channel/client_channel.cc @@ -152,43 +152,41 @@ class ChannelData { SubchannelInterface* subchannel) const; grpc_connectivity_state CheckConnectivityState(bool try_to_connect); + void AddExternalConnectivityWatcher(grpc_polling_entity pollent, grpc_connectivity_state* state, grpc_closure* on_complete, grpc_closure* watcher_timer_init) { - // Will delete itself. - New(this, pollent, state, on_complete, - watcher_timer_init); + MutexLock lock(&external_watchers_mu_); + // Will be deleted when the watch is complete. + GPR_ASSERT(external_watchers_[on_complete] == nullptr); + external_watchers_[on_complete] = New( + this, pollent, state, on_complete, watcher_timer_init); + } + + void RemoveExternalConnectivityWatcher(grpc_closure* on_complete, + bool cancel) { + MutexLock lock(&external_watchers_mu_); + auto it = external_watchers_.find(on_complete); + if (it != external_watchers_.end()) { + if (cancel) it->second->Cancel(); + external_watchers_.erase(it); + } } + int NumExternalConnectivityWatchers() const { - return external_connectivity_watcher_list_.size(); + MutexLock lock(&external_watchers_mu_); + return static_cast(external_watchers_.size()); } private: class SubchannelWrapper; class ClientChannelControlHelper; - class ExternalConnectivityWatcher { + // Represents a pending connectivity callback from an external caller + // via grpc_client_channel_watch_connectivity_state(). + class ExternalConnectivityWatcher : public ConnectivityStateWatcherInterface { public: - class WatcherList { - public: - WatcherList() { gpr_mu_init(&mu_); } - ~WatcherList() { gpr_mu_destroy(&mu_); } - - int size() const; - ExternalConnectivityWatcher* Lookup(grpc_closure* on_complete) const; - void Add(ExternalConnectivityWatcher* watcher); - void Remove(const ExternalConnectivityWatcher* watcher); - - private: - // head_ is guarded by a mutex, since the size() method needs to - // iterate over the list, and it's called from the C-core API - // function grpc_channel_num_external_connectivity_watchers(), which - // is synchronous and therefore cannot run in the combiner. - mutable gpr_mu mu_; - ExternalConnectivityWatcher* head_ = nullptr; - }; - ExternalConnectivityWatcher(ChannelData* chand, grpc_polling_entity pollent, grpc_connectivity_state* state, grpc_closure* on_complete, @@ -196,17 +194,23 @@ class ChannelData { ~ExternalConnectivityWatcher(); + void Notify(grpc_connectivity_state state) override; + + void Cancel(); + private: - static void OnWatchCompleteLocked(void* arg, grpc_error* error); - static void WatchConnectivityStateLocked(void* arg, grpc_error* ignored); + static void AddWatcherLocked(void* arg, grpc_error* ignored); + static void RemoveWatcherLocked(void* arg, grpc_error* ignored); ChannelData* chand_; grpc_polling_entity pollent_; + grpc_connectivity_state initial_state_; grpc_connectivity_state* state_; grpc_closure* on_complete_; grpc_closure* watcher_timer_init_; - grpc_closure my_closure_; - ExternalConnectivityWatcher* next_ = nullptr; + grpc_closure add_closure_; + grpc_closure remove_closure_; + Atomic done_{false}; }; ChannelData(grpc_channel_element_args* args, grpc_error** error); @@ -273,8 +277,7 @@ class ChannelData { grpc_pollset_set* interested_parties_; RefCountedPtr subchannel_pool_; OrphanablePtr resolving_lb_policy_; - grpc_connectivity_state_tracker state_tracker_; - ExternalConnectivityWatcher::WatcherList external_connectivity_watcher_list_; + ConnectivityStateTracker state_tracker_; UniquePtr health_check_service_name_; RefCountedPtr saved_service_config_; bool received_first_resolver_result_ = false; @@ -305,6 +308,13 @@ class ChannelData { gpr_mu info_mu_; UniquePtr info_lb_policy_name_; UniquePtr info_service_config_json_; + + // + // Fields guarded by a mutex, since they need to be accessed + // synchronously via grpc_channel_num_external_connectivity_watchers(). + // + mutable Mutex external_watchers_mu_; + Map external_watchers_; }; // @@ -994,8 +1004,7 @@ class ChannelData::SubchannelWrapper : public SubchannelInterface { "subchannel %p (connected_subchannel=%p state=%s); " "hopping into combiner", parent_->chand_, parent_.get(), parent_->subchannel_, - connected_subchannel.get(), - grpc_connectivity_state_name(new_state)); + connected_subchannel.get(), ConnectivityStateName(new_state)); } // Will delete itself. New(Ref(), new_state, std::move(connected_subchannel)); @@ -1044,7 +1053,7 @@ class ChannelData::SubchannelWrapper : public SubchannelInterface { self->parent_->parent_->chand_, self->parent_->parent_.get(), self->parent_->parent_->subchannel_, self->connected_subchannel_.get(), - grpc_connectivity_state_name(self->state_), + ConnectivityStateName(self->state_), self->parent_->watcher_.get()); } // Ignore update if the parent WatcherWrapper has been replaced @@ -1105,55 +1114,6 @@ class ChannelData::SubchannelWrapper : public SubchannelInterface { RefCountedPtr connected_subchannel_in_data_plane_; }; -// -// ChannelData::ExternalConnectivityWatcher::WatcherList -// - -int ChannelData::ExternalConnectivityWatcher::WatcherList::size() const { - MutexLock lock(&mu_); - int count = 0; - for (ExternalConnectivityWatcher* w = head_; w != nullptr; w = w->next_) { - ++count; - } - return count; -} - -ChannelData::ExternalConnectivityWatcher* -ChannelData::ExternalConnectivityWatcher::WatcherList::Lookup( - grpc_closure* on_complete) const { - MutexLock lock(&mu_); - ExternalConnectivityWatcher* w = head_; - while (w != nullptr && w->on_complete_ != on_complete) { - w = w->next_; - } - return w; -} - -void ChannelData::ExternalConnectivityWatcher::WatcherList::Add( - ExternalConnectivityWatcher* watcher) { - GPR_ASSERT(Lookup(watcher->on_complete_) == nullptr); - MutexLock lock(&mu_); - GPR_ASSERT(watcher->next_ == nullptr); - watcher->next_ = head_; - head_ = watcher; -} - -void ChannelData::ExternalConnectivityWatcher::WatcherList::Remove( - const ExternalConnectivityWatcher* watcher) { - MutexLock lock(&mu_); - if (watcher == head_) { - head_ = watcher->next_; - return; - } - for (ExternalConnectivityWatcher* w = head_; w != nullptr; w = w->next_) { - if (w->next_ == watcher) { - w->next_ = w->next_->next_; - return; - } - } - GPR_UNREACHABLE_CODE(return ); -} - // // ChannelData::ExternalConnectivityWatcher // @@ -1164,6 +1124,7 @@ ChannelData::ExternalConnectivityWatcher::ExternalConnectivityWatcher( grpc_closure* watcher_timer_init) : chand_(chand), pollent_(pollent), + initial_state_(*state), state_(state), on_complete_(on_complete), watcher_timer_init_(watcher_timer_init) { @@ -1171,7 +1132,7 @@ ChannelData::ExternalConnectivityWatcher::ExternalConnectivityWatcher( chand_->interested_parties_); GRPC_CHANNEL_STACK_REF(chand_->owning_stack_, "ExternalConnectivityWatcher"); GRPC_CLOSURE_SCHED( - GRPC_CLOSURE_INIT(&my_closure_, WatchConnectivityStateLocked, this, + GRPC_CLOSURE_INIT(&add_closure_, AddWatcherLocked, this, grpc_combiner_scheduler(chand_->combiner_)), GRPC_ERROR_NONE); } @@ -1183,42 +1144,61 @@ ChannelData::ExternalConnectivityWatcher::~ExternalConnectivityWatcher() { "ExternalConnectivityWatcher"); } -void ChannelData::ExternalConnectivityWatcher::OnWatchCompleteLocked( - void* arg, grpc_error* error) { - ExternalConnectivityWatcher* self = - static_cast(arg); - grpc_closure* on_complete = self->on_complete_; - self->chand_->external_connectivity_watcher_list_.Remove(self); - Delete(self); - GRPC_CLOSURE_SCHED(on_complete, GRPC_ERROR_REF(error)); +void ChannelData::ExternalConnectivityWatcher::Notify( + grpc_connectivity_state state) { + bool done = false; + if (!done_.CompareExchangeStrong(&done, true, MemoryOrder::RELAXED, + MemoryOrder::RELAXED)) { + return; // Already done. + } + // Report new state to the user. + *state_ = state; + GRPC_CLOSURE_SCHED(on_complete_, GRPC_ERROR_NONE); + // Remove external watcher. + chand_->RemoveExternalConnectivityWatcher(on_complete_, /*cancel=*/false); + // Hop back into the combiner to clean up. + // Not needed in state SHUTDOWN, because the tracker will + // automatically remove all watchers in that case. + if (state != GRPC_CHANNEL_SHUTDOWN) { + GRPC_CLOSURE_SCHED( + GRPC_CLOSURE_INIT(&remove_closure_, RemoveWatcherLocked, this, + grpc_combiner_scheduler(chand_->combiner_)), + GRPC_ERROR_NONE); + } +} + +void ChannelData::ExternalConnectivityWatcher::Cancel() { + bool done = false; + if (!done_.CompareExchangeStrong(&done, true, MemoryOrder::RELAXED, + MemoryOrder::RELAXED)) { + return; // Already done. + } + GRPC_CLOSURE_SCHED(on_complete_, GRPC_ERROR_CANCELLED); + // Hop back into the combiner to clean up. + GRPC_CLOSURE_SCHED( + GRPC_CLOSURE_INIT(&remove_closure_, RemoveWatcherLocked, this, + grpc_combiner_scheduler(chand_->combiner_)), + GRPC_ERROR_NONE); } -void ChannelData::ExternalConnectivityWatcher::WatchConnectivityStateLocked( +void ChannelData::ExternalConnectivityWatcher::AddWatcherLocked( void* arg, grpc_error* ignored) { ExternalConnectivityWatcher* self = static_cast(arg); - if (self->state_ == nullptr) { - // Handle cancellation. - GPR_ASSERT(self->watcher_timer_init_ == nullptr); - ExternalConnectivityWatcher* found = - self->chand_->external_connectivity_watcher_list_.Lookup( - self->on_complete_); - if (found != nullptr) { - grpc_connectivity_state_notify_on_state_change( - &found->chand_->state_tracker_, nullptr, &found->my_closure_); - } - Delete(self); - return; - } - // New watcher. - self->chand_->external_connectivity_watcher_list_.Add(self); // This assumes that the closure is scheduled on the ExecCtx scheduler - // and that GRPC_CLOSURE_RUN would run the closure immediately. + // and that GRPC_CLOSURE_RUN() will run the closure immediately. GRPC_CLOSURE_RUN(self->watcher_timer_init_, GRPC_ERROR_NONE); - GRPC_CLOSURE_INIT(&self->my_closure_, OnWatchCompleteLocked, self, - grpc_combiner_scheduler(self->chand_->combiner_)); - grpc_connectivity_state_notify_on_state_change( - &self->chand_->state_tracker_, self->state_, &self->my_closure_); + // Add new watcher. + self->chand_->state_tracker_.AddWatcher( + self->initial_state_, + OrphanablePtr(self)); +} + +void ChannelData::ExternalConnectivityWatcher::RemoveWatcherLocked( + void* arg, grpc_error* ignored) { + ExternalConnectivityWatcher* self = + static_cast(arg); + self->chand_->state_tracker_.RemoveWatcher(self); } // @@ -1271,7 +1251,7 @@ class ChannelData::ClientChannelControlHelper ? "" : " (ignoring -- channel shutting down)"; gpr_log(GPR_INFO, "chand=%p: update: state=%s picker=%p%s", chand_, - grpc_connectivity_state_name(state), picker.get(), extra); + ConnectivityStateName(state), picker.get(), extra); } // Do update only if not shutting down. if (disconnect_error == GRPC_ERROR_NONE) { @@ -1362,14 +1342,13 @@ ChannelData::ChannelData(grpc_channel_element_args* args, grpc_error** error) combiner_(grpc_combiner_create()), interested_parties_(grpc_pollset_set_create()), subchannel_pool_(GetSubchannelPool(args->channel_args)), + state_tracker_("client_channel", GRPC_CHANNEL_IDLE), disconnect_error_(GRPC_ERROR_NONE) { if (GRPC_TRACE_FLAG_ENABLED(grpc_client_channel_routing_trace)) { gpr_log(GPR_INFO, "chand=%p: creating client_channel for channel stack %p", this, owning_stack_); } // Initialize data members. - grpc_connectivity_state_init(&state_tracker_, GRPC_CHANNEL_IDLE, - "client_channel"); gpr_mu_init(&info_mu_); // Start backup polling. grpc_client_channel_start_backup_polling(interested_parties_); @@ -1433,7 +1412,6 @@ ChannelData::~ChannelData() { grpc_pollset_set_destroy(interested_parties_); GRPC_COMBINER_UNREF(combiner_, "client_channel"); GRPC_ERROR_UNREF(disconnect_error_.Load(MemoryOrder::RELAXED)); - grpc_connectivity_state_destroy(&state_tracker_); gpr_mu_destroy(&info_mu_); } @@ -1447,7 +1425,7 @@ void ChannelData::UpdateStateAndPickerLocked( received_first_resolver_result_ = false; } // Update connectivity state. - grpc_connectivity_state_set(&state_tracker_, state, reason); + state_tracker_.SetState(state, reason); if (channelz_node_ != nullptr) { channelz_node_->SetConnectivityState(state); channelz_node_->AddTraceEvent( @@ -1736,7 +1714,7 @@ bool ChannelData::ProcessResolverResultLocked( } grpc_error* ChannelData::DoPingLocked(grpc_transport_op* op) { - if (grpc_connectivity_state_check(&state_tracker_) != GRPC_CHANNEL_READY) { + if (state_tracker_.state() != GRPC_CHANNEL_READY) { return GRPC_ERROR_CREATE_FROM_STATIC_STRING("channel not connected"); } LoadBalancingPolicy::PickResult result = @@ -1764,12 +1742,12 @@ void ChannelData::StartTransportOpLocked(void* arg, grpc_error* ignored) { static_cast(op->handler_private.extra_arg); ChannelData* chand = static_cast(elem->channel_data); // Connectivity watch. - if (op->on_connectivity_state_change != nullptr) { - grpc_connectivity_state_notify_on_state_change( - &chand->state_tracker_, op->connectivity_state, - op->on_connectivity_state_change); - op->on_connectivity_state_change = nullptr; - op->connectivity_state = nullptr; + if (op->start_connectivity_watch != nullptr) { + chand->state_tracker_.AddWatcher(op->start_connectivity_watch_state, + std::move(op->start_connectivity_watch)); + } + if (op->stop_connectivity_watch != nullptr) { + chand->state_tracker_.RemoveWatcher(op->stop_connectivity_watch); } // Ping. if (op->send_ping.on_initiate != nullptr || op->send_ping.on_ack != nullptr) { @@ -1900,7 +1878,7 @@ void ChannelData::TryToConnectLocked(void* arg, grpc_error* error_ignored) { grpc_connectivity_state ChannelData::CheckConnectivityState( bool try_to_connect) { - grpc_connectivity_state out = grpc_connectivity_state_check(&state_tracker_); + grpc_connectivity_state out = state_tracker_.state(); if (out == GRPC_CHANNEL_IDLE && try_to_connect) { GRPC_CHANNEL_STACK_REF(owning_stack_, "TryToConnect"); GRPC_CLOSURE_SCHED(GRPC_CLOSURE_CREATE(TryToConnectLocked, this, @@ -3950,6 +3928,13 @@ void grpc_client_channel_watch_connectivity_state( grpc_connectivity_state* state, grpc_closure* closure, grpc_closure* watcher_timer_init) { auto* chand = static_cast(elem->channel_data); + if (state == nullptr) { + // Handle cancellation. + GPR_ASSERT(watcher_timer_init == nullptr); + chand->RemoveExternalConnectivityWatcher(closure, /*cancel=*/true); + return; + } + // Handle addition. return chand->AddExternalConnectivityWatcher(pollent, state, closure, watcher_timer_init); } diff --git a/src/core/ext/filters/client_channel/client_channel.h b/src/core/ext/filters/client_channel/client_channel.h index caaa079dd9b..72bcb404ce0 100644 --- a/src/core/ext/filters/client_channel/client_channel.h +++ b/src/core/ext/filters/client_channel/client_channel.h @@ -46,6 +46,12 @@ grpc_connectivity_state grpc_client_channel_check_connectivity_state( int grpc_client_channel_num_external_connectivity_watchers( grpc_channel_element* elem); +// TODO(roth): This function is used both when handling external +// connectivity watchers and for LB policies like grpclb and xds that +// contain nested channels. In the latter case, we ideally want +// something closer to the normal connectivity state tracker API. +// When we have time, consider refactoring this somehow to allow each +// use-case to be handled more cleanly. void grpc_client_channel_watch_connectivity_state( grpc_channel_element* elem, grpc_polling_entity pollent, grpc_connectivity_state* state, grpc_closure* on_complete, diff --git a/src/core/ext/filters/client_channel/client_channel_channelz.cc b/src/core/ext/filters/client_channel/client_channel_channelz.cc index 87a76601f02..a47766031a3 100644 --- a/src/core/ext/filters/client_channel/client_channel_channelz.cc +++ b/src/core/ext/filters/client_channel/client_channel_channelz.cc @@ -53,9 +53,8 @@ void SubchannelNode::PopulateConnectivityState(grpc_json* json) { connectivity_state_.Load(MemoryOrder::RELAXED); json = grpc_json_create_child(nullptr, json, "state", nullptr, GRPC_JSON_OBJECT, false); - grpc_json_create_child(nullptr, json, "state", - grpc_connectivity_state_name(state), GRPC_JSON_STRING, - false); + grpc_json_create_child(nullptr, json, "state", ConnectivityStateName(state), + GRPC_JSON_STRING, false); } grpc_json* SubchannelNode::RenderJson() { diff --git a/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc b/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc index 7f3c2b20f21..af7632c1728 100644 --- a/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc +++ b/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc @@ -660,7 +660,7 @@ void GrpcLb::Helper::UpdateState(grpc_connectivity_state state, gpr_log(GPR_INFO, "[grpclb %p helper %p] pending child policy %p reports state=%s", parent_.get(), this, parent_->pending_child_policy_.get(), - grpc_connectivity_state_name(state)); + ConnectivityStateName(state)); } if (state != GRPC_CHANNEL_READY) return; grpc_pollset_set_del_pollset_set( @@ -700,8 +700,7 @@ void GrpcLb::Helper::UpdateState(grpc_connectivity_state state, if (GRPC_TRACE_FLAG_ENABLED(grpc_lb_glb_trace)) { gpr_log(GPR_INFO, "[grpclb %p helper %p] state=%s passing child picker %p as-is", - parent_.get(), this, grpc_connectivity_state_name(state), - picker.get()); + parent_.get(), this, ConnectivityStateName(state), picker.get()); } parent_->channel_control_helper()->UpdateState(state, std::move(picker)); return; @@ -709,8 +708,7 @@ void GrpcLb::Helper::UpdateState(grpc_connectivity_state state, // Cases 2 and 3a: wrap picker from the child in our own picker. if (GRPC_TRACE_FLAG_ENABLED(grpc_lb_glb_trace)) { gpr_log(GPR_INFO, "[grpclb %p helper %p] state=%s wrapping child picker %p", - parent_.get(), this, grpc_connectivity_state_name(state), - picker.get()); + parent_.get(), this, ConnectivityStateName(state), picker.get()); } RefCountedPtr client_stats; if (parent_->lb_calld_ != nullptr && diff --git a/src/core/ext/filters/client_channel/lb_policy/pick_first/pick_first.cc b/src/core/ext/filters/client_channel/lb_policy/pick_first/pick_first.cc index b40b0325421..000462092ac 100644 --- a/src/core/ext/filters/client_channel/lb_policy/pick_first/pick_first.cc +++ b/src/core/ext/filters/client_channel/lb_policy/pick_first/pick_first.cc @@ -294,7 +294,7 @@ void PickFirst::PickFirstSubchannelData::ProcessConnectivityChangeLocked( if (GRPC_TRACE_FLAG_ENABLED(grpc_lb_pick_first_trace)) { gpr_log(GPR_INFO, "Pick First %p selected subchannel connectivity changed to %s", p, - grpc_connectivity_state_name(connectivity_state)); + ConnectivityStateName(connectivity_state)); } // If the new state is anything other than READY and there is a // pending update, switch to the pending update. diff --git a/src/core/ext/filters/client_channel/lb_policy/round_robin/round_robin.cc b/src/core/ext/filters/client_channel/lb_policy/round_robin/round_robin.cc index 5f69a657b61..69b3d6746e0 100644 --- a/src/core/ext/filters/client_channel/lb_policy/round_robin/round_robin.cc +++ b/src/core/ext/filters/client_channel/lb_policy/round_robin/round_robin.cc @@ -379,8 +379,8 @@ void RoundRobin::RoundRobinSubchannelData::UpdateConnectivityStateLocked( "(index %" PRIuPTR " of %" PRIuPTR "): prev_state=%s new_state=%s", p, subchannel(), subchannel_list(), Index(), subchannel_list()->num_subchannels(), - grpc_connectivity_state_name(last_connectivity_state_), - grpc_connectivity_state_name(connectivity_state)); + ConnectivityStateName(last_connectivity_state_), + ConnectivityStateName(connectivity_state)); } // Decide what state to report for aggregation purposes. // If we haven't seen a failure since the last time we were in state diff --git a/src/core/ext/filters/client_channel/lb_policy/subchannel_list.h b/src/core/ext/filters/client_channel/lb_policy/subchannel_list.h index 34cd0f549fe..b4d3fab91be 100644 --- a/src/core/ext/filters/client_channel/lb_policy/subchannel_list.h +++ b/src/core/ext/filters/client_channel/lb_policy/subchannel_list.h @@ -254,8 +254,7 @@ void SubchannelData::Watcher:: subchannel_list_.get(), subchannel_data_->Index(), subchannel_list_->num_subchannels(), subchannel_data_->subchannel_.get(), - grpc_connectivity_state_name(new_state), - subchannel_list_->shutting_down(), + ConnectivityStateName(new_state), subchannel_list_->shutting_down(), subchannel_data_->pending_watcher_); } if (!subchannel_list_->shutting_down() && @@ -318,8 +317,7 @@ void SubchannelDatatracer()->name(), subchannel_list_->policy(), subchannel_list_, Index(), subchannel_list_->num_subchannels(), - subchannel_.get(), - grpc_connectivity_state_name(connectivity_state_)); + subchannel_.get(), ConnectivityStateName(connectivity_state_)); } GPR_ASSERT(pending_watcher_ == nullptr); pending_watcher_ = diff --git a/src/core/ext/filters/client_channel/lb_policy/xds/xds.cc b/src/core/ext/filters/client_channel/lb_policy/xds/xds.cc index 7c4b1faffe2..c5b9b3dc437 100644 --- a/src/core/ext/filters/client_channel/lb_policy/xds/xds.cc +++ b/src/core/ext/filters/client_channel/lb_policy/xds/xds.cc @@ -823,7 +823,7 @@ void XdsLb::FallbackHelper::UpdateState(grpc_connectivity_state state, GPR_INFO, "[xdslb %p helper %p] pending fallback policy %p reports state=%s", parent_.get(), this, parent_->pending_fallback_policy_.get(), - grpc_connectivity_state_name(state)); + ConnectivityStateName(state)); } if (state != GRPC_CHANNEL_READY) return; grpc_pollset_set_del_pollset_set( @@ -2502,7 +2502,7 @@ void XdsLb::PriorityList::LocalityMap::UpdateConnectivityStateLocked() { gpr_log(GPR_INFO, "[xdslb %p] Priority %" PRIu32 " (%p) connectivity changed to %s", xds_policy(), priority_, this, - grpc_connectivity_state_name(connectivity_state_)); + ConnectivityStateName(connectivity_state_)); } } @@ -2834,7 +2834,7 @@ void XdsLb::PriorityList::LocalityMap::Locality::Helper::UpdateState( "[xdslb %p helper %p] pending child policy %p reports state=%s", locality_->xds_policy(), this, locality_->pending_child_policy_.get(), - grpc_connectivity_state_name(state)); + ConnectivityStateName(state)); } if (state != GRPC_CHANNEL_READY) return; grpc_pollset_set_del_pollset_set( diff --git a/src/core/ext/filters/client_channel/resolving_lb_policy.cc b/src/core/ext/filters/client_channel/resolving_lb_policy.cc index f4c0f92b7b6..d997e26f979 100644 --- a/src/core/ext/filters/client_channel/resolving_lb_policy.cc +++ b/src/core/ext/filters/client_channel/resolving_lb_policy.cc @@ -123,8 +123,7 @@ class ResolvingLoadBalancingPolicy::ResolvingControlHelper gpr_log(GPR_INFO, "resolving_lb=%p helper=%p: pending child policy %p reports " "state=%s", - parent_.get(), this, child_, - grpc_connectivity_state_name(state)); + parent_.get(), this, child_, ConnectivityStateName(state)); } if (state != GRPC_CHANNEL_READY) return; grpc_pollset_set_del_pollset_set( diff --git a/src/core/ext/filters/client_channel/subchannel.cc b/src/core/ext/filters/client_channel/subchannel.cc index e30d915d03c..2c3f899d2a7 100644 --- a/src/core/ext/filters/client_channel/subchannel.cc +++ b/src/core/ext/filters/client_channel/subchannel.cc @@ -95,15 +95,14 @@ ConnectedSubchannel::~ConnectedSubchannel() { GRPC_CHANNEL_STACK_UNREF(channel_stack_, "connected_subchannel_dtor"); } -void ConnectedSubchannel::NotifyOnStateChange( - grpc_pollset_set* interested_parties, grpc_connectivity_state* state, - grpc_closure* closure) { +void ConnectedSubchannel::StartWatch( + grpc_pollset_set* interested_parties, + OrphanablePtr watcher) { grpc_transport_op* op = grpc_make_transport_op(nullptr); - grpc_channel_element* elem; - op->connectivity_state = state; - op->on_connectivity_state_change = closure; + op->start_connectivity_watch = std::move(watcher); + op->start_connectivity_watch_state = GRPC_CHANNEL_READY; op->bind_pollset_set = interested_parties; - elem = grpc_channel_stack_element(channel_stack_, 0); + grpc_channel_element* elem = grpc_channel_stack_element(channel_stack_, 0); elem->filter->start_transport_op(elem, op); } @@ -310,19 +309,14 @@ void SubchannelCall::IncrementRefCount(const grpc_core::DebugLocation& location, // Subchannel::ConnectedSubchannelStateWatcher // -class Subchannel::ConnectedSubchannelStateWatcher { +class Subchannel::ConnectedSubchannelStateWatcher + : public AsyncConnectivityStateWatcherInterface { public: // Must be instantiated while holding c->mu. explicit ConnectedSubchannelStateWatcher(Subchannel* c) : subchannel_(c) { // Steal subchannel ref for connecting. GRPC_SUBCHANNEL_WEAK_REF(subchannel_, "state_watcher"); GRPC_SUBCHANNEL_WEAK_UNREF(subchannel_, "connecting"); - // Start watching for connectivity state changes. - GRPC_CLOSURE_INIT(&on_connectivity_changed_, OnConnectivityChanged, this, - grpc_schedule_on_exec_ctx); - c->connected_subchannel_->NotifyOnStateChange(c->pollset_set_, - &pending_connectivity_state_, - &on_connectivity_changed_); } ~ConnectedSubchannelStateWatcher() { @@ -330,54 +324,41 @@ class Subchannel::ConnectedSubchannelStateWatcher { } private: - static void OnConnectivityChanged(void* arg, grpc_error* error) { - auto* self = static_cast(arg); - Subchannel* c = self->subchannel_; - { - MutexLock lock(&c->mu_); - switch (self->pending_connectivity_state_) { - case GRPC_CHANNEL_TRANSIENT_FAILURE: - case GRPC_CHANNEL_SHUTDOWN: { - if (!c->disconnected_ && c->connected_subchannel_ != nullptr) { - if (grpc_trace_subchannel.enabled()) { - gpr_log(GPR_INFO, - "Connected subchannel %p of subchannel %p has gone into " - "%s. Attempting to reconnect.", - c->connected_subchannel_.get(), c, - grpc_connectivity_state_name( - self->pending_connectivity_state_)); - } - c->connected_subchannel_.reset(); - if (c->channelz_node() != nullptr) { - c->channelz_node()->SetChildSocket(nullptr); - } - c->SetConnectivityStateLocked(GRPC_CHANNEL_TRANSIENT_FAILURE); - c->backoff_begun_ = false; - c->backoff_.Reset(); + void OnConnectivityStateChange(grpc_connectivity_state new_state) override { + Subchannel* c = subchannel_; + MutexLock lock(&c->mu_); + switch (new_state) { + case GRPC_CHANNEL_TRANSIENT_FAILURE: + case GRPC_CHANNEL_SHUTDOWN: { + if (!c->disconnected_ && c->connected_subchannel_ != nullptr) { + if (grpc_trace_subchannel.enabled()) { + gpr_log(GPR_INFO, + "Connected subchannel %p of subchannel %p has gone into " + "%s. Attempting to reconnect.", + c->connected_subchannel_.get(), c, + ConnectivityStateName(new_state)); } - break; - } - default: { - // In principle, this should never happen. We should not get - // a callback for READY, because that was the state we started - // this watch from. And a connected subchannel should never go - // from READY to CONNECTING or IDLE. - c->SetConnectivityStateLocked(self->pending_connectivity_state_); - c->connected_subchannel_->NotifyOnStateChange( - nullptr, &self->pending_connectivity_state_, - &self->on_connectivity_changed_); - return; // So we don't delete ourself below. + c->connected_subchannel_.reset(); + if (c->channelz_node() != nullptr) { + c->channelz_node()->SetChildSocket(nullptr); + } + c->SetConnectivityStateLocked(GRPC_CHANNEL_TRANSIENT_FAILURE); + c->backoff_begun_ = false; + c->backoff_.Reset(); } + break; + } + default: { + // In principle, this should never happen. We should not get + // a callback for READY, because that was the state we started + // this watch from. And a connected subchannel should never go + // from READY to CONNECTING or IDLE. + c->SetConnectivityStateLocked(new_state); } } - // Don't delete until we've released the lock, because this might - // cause the subchannel (which contains the lock) to be destroyed. - Delete(self); } Subchannel* subchannel_; - grpc_closure on_connectivity_changed_; - grpc_connectivity_state pending_connectivity_state_ = GRPC_CHANNEL_READY; }; // @@ -1088,8 +1069,10 @@ bool Subchannel::PublishTransportLocked() { if (channelz_node_ != nullptr) { channelz_node_->SetChildSocket(std::move(socket)); } - // Instantiate state watcher. Will clean itself up. - New(this); + // Start watching connected subchannel. + connected_subchannel_->StartWatch( + pollset_set_, OrphanablePtr( + New(this))); // Report initial state. SetConnectivityStateLocked(GRPC_CHANNEL_READY); return true; diff --git a/src/core/ext/filters/client_channel/subchannel.h b/src/core/ext/filters/client_channel/subchannel.h index c178401ca8a..d6fb65814b7 100644 --- a/src/core/ext/filters/client_channel/subchannel.h +++ b/src/core/ext/filters/client_channel/subchannel.h @@ -77,9 +77,9 @@ class ConnectedSubchannel : public RefCounted { RefCountedPtr channelz_subchannel); ~ConnectedSubchannel(); - void NotifyOnStateChange(grpc_pollset_set* interested_parties, - grpc_connectivity_state* state, - grpc_closure* closure); + void StartWatch(grpc_pollset_set* interested_parties, + OrphanablePtr watcher); + void Ping(grpc_closure* on_initiate, grpc_closure* on_ack); grpc_channel_stack* channel_stack() const { return channel_stack_; } diff --git a/src/core/ext/filters/max_age/max_age_filter.cc b/src/core/ext/filters/max_age/max_age_filter.cc index 7ab506429af..982fabca833 100644 --- a/src/core/ext/filters/max_age/max_age_filter.cc +++ b/src/core/ext/filters/max_age/max_age_filter.cc @@ -90,10 +90,6 @@ struct channel_data { grpc_closure start_max_age_timer_after_init; /* Closure to run when the goaway op is finished and the max_age_timer */ grpc_closure start_max_age_grace_timer_after_goaway_op; - /* Closure to run when the channel connectivity state changes */ - grpc_closure channel_connectivity_changed; - /* Records the current connectivity state */ - grpc_connectivity_state connectivity_state; /* Number of active calls */ gpr_atm call_count; /* TODO(zyc): C++lize this state machine */ @@ -220,6 +216,47 @@ static void start_max_idle_timer_after_init(void* arg, grpc_error* error) { "max_age start_max_idle_timer_after_init"); } +namespace grpc_core { + +class ConnectivityWatcher : public AsyncConnectivityStateWatcherInterface { + public: + explicit ConnectivityWatcher(channel_data* chand) : chand_(chand) { + GRPC_CHANNEL_STACK_REF(chand_->channel_stack, "max_age conn_watch"); + } + + ~ConnectivityWatcher() { + GRPC_CHANNEL_STACK_UNREF(chand_->channel_stack, "max_age conn_watch"); + } + + private: + void OnConnectivityStateChange(grpc_connectivity_state new_state) override { + if (new_state != GRPC_CHANNEL_SHUTDOWN) return; + { + MutexLock lock(&chand_->max_age_timer_mu); + if (chand_->max_age_timer_pending) { + grpc_timer_cancel(&chand_->max_age_timer); + chand_->max_age_timer_pending = false; + } + if (chand_->max_age_grace_timer_pending) { + grpc_timer_cancel(&chand_->max_age_grace_timer); + chand_->max_age_grace_timer_pending = false; + } + } + /* If there are no active calls, this increasement will cancel + max_idle_timer, and prevent max_idle_timer from being started in the + future. */ + increase_call_count(chand_); + if (gpr_atm_acq_load(&chand_->idle_state) == + MAX_IDLE_STATE_SEEN_EXIT_IDLE) { + grpc_timer_cancel(&chand_->max_idle_timer); + } + } + + channel_data* chand_; +}; + +} // namespace grpc_core + static void start_max_age_timer_after_init(void* arg, grpc_error* error) { channel_data* chand = static_cast(arg); gpr_mu_lock(&chand->max_age_timer_mu); @@ -230,8 +267,9 @@ static void start_max_age_timer_after_init(void* arg, grpc_error* error) { &chand->close_max_age_channel); gpr_mu_unlock(&chand->max_age_timer_mu); grpc_transport_op* op = grpc_make_transport_op(nullptr); - op->on_connectivity_state_change = &chand->channel_connectivity_changed; - op->connectivity_state = &chand->connectivity_state; + op->start_connectivity_watch.reset( + grpc_core::New(chand)); + op->start_connectivity_watch_state = GRPC_CHANNEL_IDLE; grpc_channel_next_op(grpc_channel_stack_element(chand->channel_stack, 0), op); GRPC_CHANNEL_STACK_UNREF(chand->channel_stack, "max_age start_max_age_timer_after_init"); @@ -350,35 +388,6 @@ static void force_close_max_age_channel(void* arg, grpc_error* error) { GRPC_CHANNEL_STACK_UNREF(chand->channel_stack, "max_age max_age_grace_timer"); } -static void channel_connectivity_changed(void* arg, grpc_error* error) { - channel_data* chand = static_cast(arg); - if (chand->connectivity_state != GRPC_CHANNEL_SHUTDOWN) { - grpc_transport_op* op = grpc_make_transport_op(nullptr); - op->on_connectivity_state_change = &chand->channel_connectivity_changed; - op->connectivity_state = &chand->connectivity_state; - grpc_channel_next_op(grpc_channel_stack_element(chand->channel_stack, 0), - op); - } else { - gpr_mu_lock(&chand->max_age_timer_mu); - if (chand->max_age_timer_pending) { - grpc_timer_cancel(&chand->max_age_timer); - chand->max_age_timer_pending = false; - } - if (chand->max_age_grace_timer_pending) { - grpc_timer_cancel(&chand->max_age_grace_timer); - chand->max_age_grace_timer_pending = false; - } - gpr_mu_unlock(&chand->max_age_timer_mu); - /* If there are no active calls, this increasement will cancel - max_idle_timer, and prevent max_idle_timer from being started in the - future. */ - increase_call_count(chand); - if (gpr_atm_acq_load(&chand->idle_state) == MAX_IDLE_STATE_SEEN_EXIT_IDLE) { - grpc_timer_cancel(&chand->max_idle_timer); - } - } -} - /* A random jitter of +/-10% will be added to MAX_CONNECTION_AGE to spread out connection storms. Note that the MAX_CONNECTION_AGE option without jitter would not create connection storms by itself, but if there happened to be a @@ -472,9 +481,6 @@ static grpc_error* max_age_init_channel_elem(grpc_channel_element* elem, GRPC_CLOSURE_INIT(&chand->start_max_age_grace_timer_after_goaway_op, start_max_age_grace_timer_after_goaway_op, chand, grpc_schedule_on_exec_ctx); - GRPC_CLOSURE_INIT(&chand->channel_connectivity_changed, - channel_connectivity_changed, chand, - grpc_schedule_on_exec_ctx); if (chand->max_connection_age != GRPC_MILLIS_INF_FUTURE) { /* When the channel reaches its max age, we send down an op with diff --git a/src/core/ext/transport/chttp2/transport/chttp2_transport.cc b/src/core/ext/transport/chttp2/transport/chttp2_transport.cc index 647442eb290..acb3b4c2ddd 100644 --- a/src/core/ext/transport/chttp2/transport/chttp2_transport.cc +++ b/src/core/ext/transport/chttp2/transport/chttp2_transport.cc @@ -196,7 +196,6 @@ grpc_chttp2_transport::~grpc_chttp2_transport() { GPR_ASSERT(grpc_chttp2_stream_map_size(&stream_map) == 0); grpc_chttp2_stream_map_destroy(&stream_map); - grpc_connectivity_state_destroy(&channel_callback.state_tracker); cancel_pings(this, GRPC_ERROR_CREATE_FROM_STATIC_STRING("Transport destroyed")); @@ -466,6 +465,8 @@ grpc_chttp2_transport::grpc_chttp2_transport( ep(ep), peer_string(grpc_endpoint_get_peer(ep)), resource_user(resource_user), + state_tracker(is_client ? "client_transport" : "server_transport", + GRPC_CHANNEL_READY), is_client(is_client), next_stream_id(is_client ? 1 : 2), deframe_state(is_client ? GRPC_DTS_FH_0 : GRPC_DTS_CLIENT_PREFIX_0) { @@ -480,9 +481,6 @@ grpc_chttp2_transport::grpc_chttp2_transport( grpc_chttp2_stream_map_init(&stream_map, 8); grpc_slice_buffer_init(&read_buffer); - grpc_connectivity_state_init( - &channel_callback.state_tracker, GRPC_CHANNEL_READY, - is_client ? "client_transport" : "server_transport"); grpc_slice_buffer_init(&outbuf); if (is_client) { grpc_slice_buffer_add(&outbuf, grpc_slice_from_copied_string( @@ -770,7 +768,7 @@ static void destroy_stream(grpc_transport* gt, grpc_stream* gs, grpc_chttp2_stream* grpc_chttp2_parsing_accept_stream(grpc_chttp2_transport* t, uint32_t id) { - if (t->channel_callback.accept_stream == nullptr) { + if (t->accept_stream_cb == nullptr) { return nullptr; } // Don't accept the stream if memory quota doesn't allow. Note that we should @@ -788,9 +786,8 @@ grpc_chttp2_stream* grpc_chttp2_parsing_accept_stream(grpc_chttp2_transport* t, grpc_chttp2_stream* accepting = nullptr; GPR_ASSERT(t->accepting_stream == nullptr); t->accepting_stream = &accepting; - t->channel_callback.accept_stream(t->channel_callback.accept_stream_user_data, - &t->base, - (void*)static_cast(id)); + t->accept_stream_cb(t->accept_stream_cb_user_data, &t->base, + (void*)static_cast(id)); t->accepting_stream = nullptr; return accepting; } @@ -1843,9 +1840,8 @@ static void perform_transport_op(grpc_transport* gt, grpc_transport_op* op) { } if (op->set_accept_stream) { - t->channel_callback.accept_stream = op->set_accept_stream_fn; - t->channel_callback.accept_stream_user_data = - op->set_accept_stream_user_data; + t->accept_stream_cb = op->set_accept_stream_fn; + t->accept_stream_cb_user_data = op->set_accept_stream_user_data; } if (op->bind_pollset) { @@ -1861,10 +1857,12 @@ static void perform_transport_op(grpc_transport* gt, grpc_transport_op* op) { grpc_chttp2_initiate_write(t, GRPC_CHTTP2_INITIATE_WRITE_APPLICATION_PING); } - if (op->on_connectivity_state_change != nullptr) { - grpc_connectivity_state_notify_on_state_change( - &t->channel_callback.state_tracker, op->connectivity_state, - op->on_connectivity_state_change); + if (op->start_connectivity_watch != nullptr) { + t->state_tracker.AddWatcher(op->start_connectivity_watch_state, + std::move(op->start_connectivity_watch)); + } + if (op->stop_connectivity_watch != nullptr) { + t->state_tracker.RemoveWatcher(op->stop_connectivity_watch); } if (op->disconnect_with_error != GRPC_ERROR_NONE) { @@ -2850,8 +2848,7 @@ static void connectivity_state_set(grpc_chttp2_transport* t, const char* reason) { GRPC_CHTTP2_IF_TRACING( gpr_log(GPR_INFO, "transport %p set connectivity_state=%d", t, state)); - grpc_connectivity_state_set(&t->channel_callback.state_tracker, state, - reason); + t->state_tracker.SetState(state, reason); } /******************************************************************************* diff --git a/src/core/ext/transport/chttp2/transport/internal.h b/src/core/ext/transport/chttp2/transport/internal.h index 314e5fdf650..6d13d368be7 100644 --- a/src/core/ext/transport/chttp2/transport/internal.h +++ b/src/core/ext/transport/chttp2/transport/internal.h @@ -339,15 +339,13 @@ struct grpc_chttp2_transport { publish the accepted server stream */ grpc_chttp2_stream** accepting_stream = nullptr; - struct { - /* accept stream callback */ - void (*accept_stream)(void* user_data, grpc_transport* transport, - const void* server_data); - void* accept_stream_user_data; - - /** connectivity tracking */ - grpc_connectivity_state_tracker state_tracker; - } channel_callback; + /* accept stream callback */ + void (*accept_stream_cb)(void* user_data, grpc_transport* transport, + const void* server_data); + void* accept_stream_cb_user_data; + + /** connectivity tracking */ + grpc_core::ConnectivityStateTracker state_tracker; /** data to write now */ grpc_slice_buffer outbuf; diff --git a/src/core/ext/transport/inproc/inproc_transport.cc b/src/core/ext/transport/inproc/inproc_transport.cc index b1dcbbba29b..a6d91ef1e05 100644 --- a/src/core/ext/transport/inproc/inproc_transport.cc +++ b/src/core/ext/transport/inproc/inproc_transport.cc @@ -75,17 +75,17 @@ struct shared_mu { struct inproc_transport { inproc_transport(const grpc_transport_vtable* vtable, shared_mu* mu, bool is_client) - : mu(mu), is_client(is_client) { + : mu(mu), + is_client(is_client), + state_tracker(is_client ? "inproc_client" : "inproc_server", + GRPC_CHANNEL_READY) { base.vtable = vtable; // Start each side of transport with 2 refs since they each have a ref // to the other gpr_ref_init(&refs, 2); - grpc_connectivity_state_init(&connectivity, GRPC_CHANNEL_READY, - is_client ? "inproc_client" : "inproc_server"); } ~inproc_transport() { - grpc_connectivity_state_destroy(&connectivity); if (gpr_unref(&mu->refs)) { mu->~shared_mu(); gpr_free(mu); @@ -111,7 +111,7 @@ struct inproc_transport { shared_mu* mu; gpr_refcount refs; bool is_client; - grpc_connectivity_state_tracker connectivity; + grpc_core::ConnectivityStateTracker state_tracker; void (*accept_stream_cb)(void* user_data, grpc_transport* transport, const void* server_data); void* accept_stream_data; @@ -1090,8 +1090,7 @@ void perform_stream_op(grpc_transport* gt, grpc_stream* gs, void close_transport_locked(inproc_transport* t) { INPROC_LOG(GPR_INFO, "close_transport %p %d", t, t->is_closed); - grpc_connectivity_state_set(&t->connectivity, GRPC_CHANNEL_SHUTDOWN, - "close transport"); + t->state_tracker.SetState(GRPC_CHANNEL_SHUTDOWN, "close transport"); if (!t->is_closed) { t->is_closed = true; /* Also end all streams on this transport */ @@ -1110,10 +1109,12 @@ void perform_transport_op(grpc_transport* gt, grpc_transport_op* op) { inproc_transport* t = reinterpret_cast(gt); INPROC_LOG(GPR_INFO, "perform_transport_op %p %p", t, op); gpr_mu_lock(&t->mu->mu); - if (op->on_connectivity_state_change) { - grpc_connectivity_state_notify_on_state_change( - &t->connectivity, op->connectivity_state, - op->on_connectivity_state_change); + if (op->start_connectivity_watch != nullptr) { + t->state_tracker.AddWatcher(op->start_connectivity_watch_state, + std::move(op->start_connectivity_watch)); + } + if (op->stop_connectivity_watch != nullptr) { + t->state_tracker.RemoveWatcher(op->stop_connectivity_watch); } if (op->set_accept_stream) { t->accept_stream_cb = op->set_accept_stream_fn; diff --git a/src/core/lib/channel/channelz.cc b/src/core/lib/channel/channelz.cc index fb913beb0f0..24746e70d0b 100644 --- a/src/core/lib/channel/channelz.cc +++ b/src/core/lib/channel/channelz.cc @@ -234,8 +234,7 @@ grpc_json* ChannelNode::RenderJson() { static_cast(state_field >> 1); json = grpc_json_create_child(nullptr, json, "state", nullptr, GRPC_JSON_OBJECT, false); - grpc_json_create_child(nullptr, json, "state", - grpc_connectivity_state_name(state), + grpc_json_create_child(nullptr, json, "state", ConnectivityStateName(state), GRPC_JSON_STRING, false); json = data; } diff --git a/src/core/lib/surface/lame_client.cc b/src/core/lib/surface/lame_client.cc index 9208160938e..565f386ba74 100644 --- a/src/core/lib/surface/lame_client.cc +++ b/src/core/lib/surface/lame_client.cc @@ -32,6 +32,7 @@ #include "src/core/lib/surface/call.h" #include "src/core/lib/surface/channel.h" #include "src/core/lib/surface/lame_client.h" +#include "src/core/lib/transport/connectivity_state.h" #include "src/core/lib/transport/static_metadata.h" namespace grpc_core { @@ -39,15 +40,19 @@ namespace grpc_core { namespace { struct CallData { - grpc_core::CallCombiner* call_combiner; + CallCombiner* call_combiner; grpc_linked_mdelem status; grpc_linked_mdelem details; - grpc_core::Atomic filled_metadata; + Atomic filled_metadata; }; struct ChannelData { + ChannelData() : state_tracker("lame_channel", GRPC_CHANNEL_SHUTDOWN) {} + grpc_status_code error_code; const char* error_message; + Mutex mu; + ConnectivityStateTracker state_tracker; }; static void fill_metadata(grpc_call_element* elem, grpc_metadata_batch* mdb) { @@ -94,10 +99,16 @@ static void lame_get_channel_info(grpc_channel_element* elem, static void lame_start_transport_op(grpc_channel_element* elem, grpc_transport_op* op) { - if (op->on_connectivity_state_change) { - GPR_ASSERT(*op->connectivity_state != GRPC_CHANNEL_SHUTDOWN); - *op->connectivity_state = GRPC_CHANNEL_SHUTDOWN; - GRPC_CLOSURE_SCHED(op->on_connectivity_state_change, GRPC_ERROR_NONE); + ChannelData* chand = static_cast(elem->channel_data); + { + MutexLock lock(&chand->mu); + if (op->start_connectivity_watch != nullptr) { + chand->state_tracker.AddWatcher(op->start_connectivity_watch_state, + std::move(op->start_connectivity_watch)); + } + if (op->stop_connectivity_watch != nullptr) { + chand->state_tracker.RemoveWatcher(op->stop_connectivity_watch); + } } if (op->send_ping.on_initiate != nullptr) { GRPC_CLOSURE_SCHED( @@ -132,10 +143,14 @@ static grpc_error* lame_init_channel_elem(grpc_channel_element* elem, grpc_channel_element_args* args) { GPR_ASSERT(args->is_first); GPR_ASSERT(args->is_last); + new (elem->channel_data) ChannelData; return GRPC_ERROR_NONE; } -static void lame_destroy_channel_elem(grpc_channel_element* elem) {} +static void lame_destroy_channel_elem(grpc_channel_element* elem) { + ChannelData* chand = static_cast(elem->channel_data); + chand->~ChannelData(); +} } // namespace diff --git a/src/core/lib/surface/server.cc b/src/core/lib/surface/server.cc index c14b7ba62b3..4fd3b0e99f1 100644 --- a/src/core/lib/surface/server.cc +++ b/src/core/lib/surface/server.cc @@ -105,7 +105,6 @@ struct channel_registered_method { struct channel_data { grpc_server* server; - grpc_connectivity_state connectivity_state; grpc_channel* channel; size_t cq_idx; /* linked list of all channels on a server */ @@ -115,7 +114,6 @@ struct channel_data { uint32_t registered_method_slots; uint32_t registered_method_max_probes; grpc_closure finish_destroy_channel_closure; - grpc_closure channel_connectivity_changed; intptr_t channelz_socket_uuid; }; @@ -458,7 +456,7 @@ static void finish_destroy_channel(void* cd, grpc_error* error) { server_unref(server); } -static void destroy_channel(channel_data* chand, grpc_error* error) { +static void destroy_channel(channel_data* chand) { if (is_channel_orphaned(chand)) return; GPR_ASSERT(chand->server != nullptr); orphan_channel(chand); @@ -467,12 +465,9 @@ static void destroy_channel(channel_data* chand, grpc_error* error) { GRPC_CLOSURE_INIT(&chand->finish_destroy_channel_closure, finish_destroy_channel, chand, grpc_schedule_on_exec_ctx); - if (GRPC_TRACE_FLAG_ENABLED(grpc_server_channel_trace) && - error != GRPC_ERROR_NONE) { - const char* msg = grpc_error_string(error); - gpr_log(GPR_INFO, "Disconnected client: %s", msg); + if (GRPC_TRACE_FLAG_ENABLED(grpc_server_channel_trace)) { + gpr_log(GPR_INFO, "Disconnected client"); } - GRPC_ERROR_UNREF(error); grpc_transport_op* op = grpc_make_transport_op(&chand->finish_destroy_channel_closure); @@ -891,24 +886,6 @@ static void accept_stream(void* cd, grpc_transport* transport, grpc_call_start_batch_and_execute(call, &op, 1, &calld->got_initial_metadata); } -static void channel_connectivity_changed(void* cd, grpc_error* error) { - channel_data* chand = static_cast(cd); - grpc_server* server = chand->server; - if (chand->connectivity_state != GRPC_CHANNEL_SHUTDOWN) { - grpc_transport_op* op = grpc_make_transport_op(nullptr); - op->on_connectivity_state_change = &chand->channel_connectivity_changed; - op->connectivity_state = &chand->connectivity_state; - grpc_channel_next_op(grpc_channel_stack_element( - grpc_channel_get_channel_stack(chand->channel), 0), - op); - } else { - gpr_mu_lock(&server->mu_global); - destroy_channel(chand, GRPC_ERROR_REF(error)); - gpr_mu_unlock(&server->mu_global); - GRPC_CHANNEL_INTERNAL_UNREF(chand->channel, "connectivity"); - } -} - static grpc_error* server_init_call_elem(grpc_call_element* elem, const grpc_call_element_args* args) { channel_data* chand = static_cast(elem->channel_data); @@ -935,10 +912,6 @@ static grpc_error* server_init_channel_elem(grpc_channel_element* elem, chand->channel = nullptr; chand->next = chand->prev = chand; chand->registered_methods = nullptr; - chand->connectivity_state = GRPC_CHANNEL_IDLE; - GRPC_CLOSURE_INIT(&chand->channel_connectivity_changed, - channel_connectivity_changed, chand, - grpc_schedule_on_exec_ctx); return GRPC_ERROR_NONE; } @@ -1149,6 +1122,31 @@ void grpc_server_get_pollsets(grpc_server* server, grpc_pollset*** pollsets, *pollsets = server->pollsets; } +class ConnectivityWatcher + : public grpc_core::AsyncConnectivityStateWatcherInterface { + public: + explicit ConnectivityWatcher(channel_data* chand) : chand_(chand) { + GRPC_CHANNEL_INTERNAL_REF(chand_->channel, "connectivity"); + } + + ~ConnectivityWatcher() { + GRPC_CHANNEL_INTERNAL_UNREF(chand_->channel, "connectivity"); + } + + private: + void OnConnectivityStateChange(grpc_connectivity_state new_state) override { + // Don't do anything until we are being shut down. + if (new_state != GRPC_CHANNEL_SHUTDOWN) return; + // Shut down channel. + grpc_server* server = chand_->server; + gpr_mu_lock(&server->mu_global); + destroy_channel(chand_); + gpr_mu_unlock(&server->mu_global); + } + + channel_data* chand_; +}; + void grpc_server_setup_transport( grpc_server* s, grpc_transport* transport, grpc_pollset* accepting_pollset, const grpc_channel_args* args, @@ -1241,13 +1239,12 @@ void grpc_server_setup_transport( chand->next->prev = chand->prev->next = chand; gpr_mu_unlock(&s->mu_global); - GRPC_CHANNEL_INTERNAL_REF(channel, "connectivity"); op = grpc_make_transport_op(nullptr); op->set_accept_stream = true; op->set_accept_stream_fn = accept_stream; op->set_accept_stream_user_data = chand; - op->on_connectivity_state_change = &chand->channel_connectivity_changed; - op->connectivity_state = &chand->connectivity_state; + op->start_connectivity_watch.reset( + grpc_core::New(chand)); if (gpr_atm_acq_load(&s->shutdown_flag) != 0) { op->disconnect_with_error = GRPC_ERROR_CREATE_FROM_STATIC_STRING("Server shutdown"); diff --git a/src/core/lib/transport/connectivity_state.cc b/src/core/lib/transport/connectivity_state.cc index bf35fd09def..45ebdca4f0d 100644 --- a/src/core/lib/transport/connectivity_state.cc +++ b/src/core/lib/transport/connectivity_state.cc @@ -26,9 +26,13 @@ #include #include -grpc_core::TraceFlag grpc_connectivity_state_trace(false, "connectivity_state"); +#include "src/core/lib/iomgr/exec_ctx.h" -const char* grpc_connectivity_state_name(grpc_connectivity_state state) { +namespace grpc_core { + +TraceFlag grpc_connectivity_state_trace(false, "connectivity_state"); + +const char* ConnectivityStateName(grpc_connectivity_state state) { switch (state) { case GRPC_CHANNEL_IDLE: return "IDLE"; @@ -44,122 +48,121 @@ const char* grpc_connectivity_state_name(grpc_connectivity_state state) { GPR_UNREACHABLE_CODE(return "UNKNOWN"); } -void grpc_connectivity_state_init(grpc_connectivity_state_tracker* tracker, - grpc_connectivity_state init_state, - const char* name) { - gpr_atm_no_barrier_store(&tracker->current_state_atm, init_state); - tracker->watchers = nullptr; - tracker->name = gpr_strdup(name); -} +// +// AsyncConnectivityStateWatcherInterface +// -void grpc_connectivity_state_destroy(grpc_connectivity_state_tracker* tracker) { - grpc_error* error; - grpc_connectivity_state_watcher* w; - while ((w = tracker->watchers)) { - tracker->watchers = w->next; - - if (GRPC_CHANNEL_SHUTDOWN != *w->current) { - *w->current = GRPC_CHANNEL_SHUTDOWN; - error = GRPC_ERROR_NONE; - } else { - error = - GRPC_ERROR_CREATE_FROM_STATIC_STRING("Shutdown connectivity owner"); - } - GRPC_CLOSURE_SCHED(w->notify, error); - gpr_free(w); +// A fire-and-forget class to asynchronously deliver a connectivity +// state notification to a watcher. +class AsyncConnectivityStateWatcherInterface::Notifier { + public: + Notifier(RefCountedPtr watcher, + grpc_connectivity_state state) + : watcher_(std::move(watcher)), state_(state) { + GRPC_CLOSURE_INIT(&closure_, SendNotification, this, + grpc_schedule_on_exec_ctx); + GRPC_CLOSURE_SCHED(&closure_, GRPC_ERROR_NONE); } - gpr_free(tracker->name); -} -grpc_connectivity_state grpc_connectivity_state_check( - grpc_connectivity_state_tracker* tracker) { - grpc_connectivity_state cur = static_cast( - gpr_atm_no_barrier_load(&tracker->current_state_atm)); - if (GRPC_TRACE_FLAG_ENABLED(grpc_connectivity_state_trace)) { - gpr_log(GPR_INFO, "CONWATCH: %p %s: get %s", tracker, tracker->name, - grpc_connectivity_state_name(cur)); + private: + static void SendNotification(void* arg, grpc_error* ignored) { + Notifier* self = static_cast(arg); + if (GRPC_TRACE_FLAG_ENABLED(grpc_connectivity_state_trace)) { + gpr_log(GPR_INFO, "watcher %p: delivering async notification for %s", + self->watcher_.get(), ConnectivityStateName(self->state_)); + } + self->watcher_->OnConnectivityStateChange(self->state_); + Delete(self); } - return cur; + + RefCountedPtr watcher_; + const grpc_connectivity_state state_; + grpc_closure closure_; +}; + +void AsyncConnectivityStateWatcherInterface::Notify( + grpc_connectivity_state state) { + New(Ref(), state); // Deletes itself when done. } -bool grpc_connectivity_state_has_watchers( - grpc_connectivity_state_tracker* connectivity_state) { - return connectivity_state->watchers != nullptr; +// +// ConnectivityStateTracker +// + +ConnectivityStateTracker::~ConnectivityStateTracker() { + grpc_connectivity_state current_state = state_.Load(MemoryOrder::RELAXED); + if (current_state == GRPC_CHANNEL_SHUTDOWN) return; + for (const auto& p : watchers_) { + if (GRPC_TRACE_FLAG_ENABLED(grpc_connectivity_state_trace)) { + gpr_log(GPR_INFO, + "ConnectivityStateTracker %s[%p]: notifying watcher %p: %s -> %s", + name_, this, p.first, ConnectivityStateName(current_state), + ConnectivityStateName(GRPC_CHANNEL_SHUTDOWN)); + } + p.second->Notify(GRPC_CHANNEL_SHUTDOWN); + } } -bool grpc_connectivity_state_notify_on_state_change( - grpc_connectivity_state_tracker* tracker, grpc_connectivity_state* current, - grpc_closure* notify) { - grpc_connectivity_state cur = static_cast( - gpr_atm_no_barrier_load(&tracker->current_state_atm)); +void ConnectivityStateTracker::AddWatcher( + grpc_connectivity_state initial_state, + OrphanablePtr watcher) { if (GRPC_TRACE_FLAG_ENABLED(grpc_connectivity_state_trace)) { - if (current == nullptr) { - gpr_log(GPR_INFO, "CONWATCH: %p %s: unsubscribe notify=%p", tracker, - tracker->name, notify); - } else { - gpr_log(GPR_INFO, "CONWATCH: %p %s: from %s [cur=%s] notify=%p", tracker, - tracker->name, grpc_connectivity_state_name(*current), - grpc_connectivity_state_name(cur), notify); - } + gpr_log(GPR_INFO, "ConnectivityStateTracker %s[%p]: add watcher %p", name_, + this, watcher.get()); } - if (current == nullptr) { - grpc_connectivity_state_watcher* w = tracker->watchers; - if (w != nullptr && w->notify == notify) { - GRPC_CLOSURE_SCHED(notify, GRPC_ERROR_CANCELLED); - tracker->watchers = w->next; - gpr_free(w); - return false; - } - while (w != nullptr) { - grpc_connectivity_state_watcher* rm_candidate = w->next; - if (rm_candidate != nullptr && rm_candidate->notify == notify) { - GRPC_CLOSURE_SCHED(notify, GRPC_ERROR_CANCELLED); - w->next = w->next->next; - gpr_free(rm_candidate); - return false; - } - w = w->next; - } - return false; - } else { - if (cur != *current) { - *current = cur; - GRPC_CLOSURE_SCHED(notify, GRPC_ERROR_NONE); - } else { - grpc_connectivity_state_watcher* w = - static_cast(gpr_malloc(sizeof(*w))); - w->current = current; - w->notify = notify; - w->next = tracker->watchers; - tracker->watchers = w; + grpc_connectivity_state current_state = state_.Load(MemoryOrder::RELAXED); + if (initial_state != current_state) { + if (GRPC_TRACE_FLAG_ENABLED(grpc_connectivity_state_trace)) { + gpr_log(GPR_INFO, + "ConnectivityStateTracker %s[%p]: notifying watcher %p: %s -> %s", + name_, this, watcher.get(), ConnectivityStateName(initial_state), + ConnectivityStateName(current_state)); } - return cur == GRPC_CHANNEL_IDLE; + watcher->Notify(current_state); } + watchers_.insert(MakePair(watcher.get(), std::move(watcher))); } -void grpc_connectivity_state_set(grpc_connectivity_state_tracker* tracker, - grpc_connectivity_state state, - const char* reason) { - grpc_connectivity_state cur = static_cast( - gpr_atm_no_barrier_load(&tracker->current_state_atm)); - grpc_connectivity_state_watcher* w; +void ConnectivityStateTracker::RemoveWatcher( + ConnectivityStateWatcherInterface* watcher) { if (GRPC_TRACE_FLAG_ENABLED(grpc_connectivity_state_trace)) { - gpr_log(GPR_INFO, "SET: %p %s: %s --> %s [%s]", tracker, tracker->name, - grpc_connectivity_state_name(cur), - grpc_connectivity_state_name(state), reason); + gpr_log(GPR_INFO, "ConnectivityStateTracker %s[%p]: remove watcher %p", + name_, this, watcher); } - if (cur == state) { - return; + watchers_.erase(watcher); +} + +void ConnectivityStateTracker::SetState(grpc_connectivity_state state, + const char* reason) { + grpc_connectivity_state current_state = state_.Load(MemoryOrder::RELAXED); + if (state == current_state) return; + if (GRPC_TRACE_FLAG_ENABLED(grpc_connectivity_state_trace)) { + gpr_log(GPR_INFO, "ConnectivityStateTracker %s[%p]: %s -> %s (%s)", name_, + this, ConnectivityStateName(current_state), + ConnectivityStateName(state), reason); } - GPR_ASSERT(cur != GRPC_CHANNEL_SHUTDOWN); - gpr_atm_no_barrier_store(&tracker->current_state_atm, state); - while ((w = tracker->watchers) != nullptr) { - *w->current = state; - tracker->watchers = w->next; + state_.Store(state, MemoryOrder::RELAXED); + for (const auto& p : watchers_) { if (GRPC_TRACE_FLAG_ENABLED(grpc_connectivity_state_trace)) { - gpr_log(GPR_INFO, "NOTIFY: %p %s: %p", tracker, tracker->name, w->notify); + gpr_log(GPR_INFO, + "ConnectivityStateTracker %s[%p]: notifying watcher %p: %s -> %s", + name_, this, p.first, ConnectivityStateName(current_state), + ConnectivityStateName(state)); } - GRPC_CLOSURE_SCHED(w->notify, GRPC_ERROR_NONE); - gpr_free(w); + p.second->Notify(state); + } + // If the new state is SHUTDOWN, orphan all of the watchers. This + // avoids the need for the callers to explicitly cancel them. + if (state == GRPC_CHANNEL_SHUTDOWN) watchers_.clear(); +} + +grpc_connectivity_state ConnectivityStateTracker::state() const { + grpc_connectivity_state state = state_.Load(MemoryOrder::RELAXED); + if (GRPC_TRACE_FLAG_ENABLED(grpc_connectivity_state_trace)) { + gpr_log(GPR_INFO, "ConnectivityStateTracker %s[%p]: get current state: %s", + name_, this, ConnectivityStateName(state)); } + return state; } + +} // namespace grpc_core diff --git a/src/core/lib/transport/connectivity_state.h b/src/core/lib/transport/connectivity_state.h index 0ff1432cb9d..41f7bf08e41 100644 --- a/src/core/lib/transport/connectivity_state.h +++ b/src/core/lib/transport/connectivity_state.h @@ -22,58 +22,98 @@ #include #include + #include "src/core/lib/debug/trace.h" +#include "src/core/lib/gprpp/atomic.h" +#include "src/core/lib/gprpp/map.h" +#include "src/core/lib/gprpp/orphanable.h" #include "src/core/lib/iomgr/closure.h" -typedef struct grpc_connectivity_state_watcher { - /** we keep watchers in a linked list */ - struct grpc_connectivity_state_watcher* next; - /** closure to notify on change */ - grpc_closure* notify; - /** the current state as believed by the watcher */ - grpc_connectivity_state* current; -} grpc_connectivity_state_watcher; - -typedef struct { - /** current grpc_connectivity_state */ - gpr_atm current_state_atm; - /** all our watchers */ - grpc_connectivity_state_watcher* watchers; - /** a name to help debugging */ - char* name; -} grpc_connectivity_state_tracker; - -extern grpc_core::TraceFlag grpc_connectivity_state_trace; - -/** enum --> string conversion */ -const char* grpc_connectivity_state_name(grpc_connectivity_state state); - -void grpc_connectivity_state_init(grpc_connectivity_state_tracker* tracker, - grpc_connectivity_state init_state, - const char* name); -void grpc_connectivity_state_destroy(grpc_connectivity_state_tracker* tracker); - -/** Set connectivity state; not thread safe; access must be serialized with an - * external lock */ -void grpc_connectivity_state_set(grpc_connectivity_state_tracker* tracker, - grpc_connectivity_state state, - const char* reason); - -/** Return true if this connectivity state has watchers. - Access must be serialized with an external lock. */ -bool grpc_connectivity_state_has_watchers( - grpc_connectivity_state_tracker* tracker); - -/** Return the last seen connectivity state. No need to synchronize access. */ -grpc_connectivity_state grpc_connectivity_state_check( - grpc_connectivity_state_tracker* tracker); - -/** Return 1 if the channel should start connecting, 0 otherwise. - If current==NULL cancel notify if it is already queued (success==0 in that - case). - Access must be serialized with an external lock. */ -bool grpc_connectivity_state_notify_on_state_change( - grpc_connectivity_state_tracker* tracker, grpc_connectivity_state* current, - grpc_closure* notify); +namespace grpc_core { + +extern TraceFlag grpc_connectivity_state_trace; + +// Enum to string conversion. +const char* ConnectivityStateName(grpc_connectivity_state state); + +// Interface for watching connectivity state. +// Subclasses must implement the Notify() method. +// +// Note: Most callers will want to use +// AsyncConnectivityStateWatcherInterface instead. +class ConnectivityStateWatcherInterface + : public InternallyRefCounted { + public: + virtual ~ConnectivityStateWatcherInterface() = default; + + // Notifies the watcher that the state has changed to new_state. + virtual void Notify(grpc_connectivity_state new_state) GRPC_ABSTRACT; + + void Orphan() override { Unref(); } + + GRPC_ABSTRACT_BASE_CLASS +}; + +// An alternative watcher interface that performs notifications via an +// asynchronous callback scheduled on the ExecCtx. +// Subclasses must implement the OnConnectivityStateChange() method. +class AsyncConnectivityStateWatcherInterface + : public ConnectivityStateWatcherInterface { + public: + virtual ~AsyncConnectivityStateWatcherInterface() = default; + + // Schedules a closure on the ExecCtx to invoke + // OnConnectivityStateChange() asynchronously. + void Notify(grpc_connectivity_state new_state) override final; + + protected: + class Notifier; + + // Invoked asynchronously when Notify() is called. + virtual void OnConnectivityStateChange(grpc_connectivity_state new_state) + GRPC_ABSTRACT; +}; + +// Tracks connectivity state. Maintains a list of watchers that are +// notified whenever the state changes. +class ConnectivityStateTracker { + public: + ConnectivityStateTracker(const char* name, + grpc_connectivity_state state = GRPC_CHANNEL_IDLE) + : name_(name), state_(state) {} + + ~ConnectivityStateTracker(); + + // Adds a watcher. + // If the current state is different than initial_state, the watcher + // will be notified immediately. Otherwise, it will be notified + // whenever the state changes. + // Not thread safe; access must be serialized with an external lock. + void AddWatcher(grpc_connectivity_state initial_state, + OrphanablePtr watcher); + + // Removes a watcher. The watcher will be orphaned. + // Not thread safe; access must be serialized with an external lock. + void RemoveWatcher(ConnectivityStateWatcherInterface* watcher); + + // Sets connectivity state. + // Not thread safe; access must be serialized with an external lock. + void SetState(grpc_connectivity_state state, const char* reason); + + // Gets the current state. + // Thread safe; no need to use an external lock. + grpc_connectivity_state state() const; + + private: + const char* name_; + Atomic state_; + // TODO(roth): This could be a set instead of a map if we had a set + // implementation. + Map> + watchers_; +}; + +} // namespace grpc_core #endif /* GRPC_CORE_LIB_TRANSPORT_CONNECTIVITY_STATE_H */ diff --git a/src/core/lib/transport/transport.h b/src/core/lib/transport/transport.h index c40b290d535..a46338310ae 100644 --- a/src/core/lib/transport/transport.h +++ b/src/core/lib/transport/transport.h @@ -25,6 +25,7 @@ #include "src/core/lib/channel/context.h" #include "src/core/lib/gprpp/arena.h" +#include "src/core/lib/gprpp/orphanable.h" #include "src/core/lib/iomgr/call_combiner.h" #include "src/core/lib/iomgr/endpoint.h" #include "src/core/lib/iomgr/polling_entity.h" @@ -32,6 +33,7 @@ #include "src/core/lib/iomgr/pollset_set.h" #include "src/core/lib/slice/slice_internal.h" #include "src/core/lib/transport/byte_stream.h" +#include "src/core/lib/transport/connectivity_state.h" #include "src/core/lib/transport/metadata_batch.h" /* Minimum and maximum protocol accepted versions. */ @@ -320,8 +322,11 @@ typedef struct grpc_transport_op { /** Called when processing of this op is done. */ grpc_closure* on_consumed = nullptr; /** connectivity monitoring - set connectivity_state to NULL to unsubscribe */ - grpc_closure* on_connectivity_state_change = nullptr; - grpc_connectivity_state* connectivity_state = nullptr; + grpc_core::OrphanablePtr + start_connectivity_watch; + grpc_connectivity_state start_connectivity_watch_state = GRPC_CHANNEL_IDLE; + grpc_core::ConnectivityStateWatcherInterface* stop_connectivity_watch = + nullptr; /** should the transport be disconnected * Error contract: the transport that gets this op must cause * disconnect_with_error to be unref'ed after processing it */ diff --git a/src/core/lib/transport/transport_op_string.cc b/src/core/lib/transport/transport_op_string.cc index 8c7db642a54..34b36c3aec9 100644 --- a/src/core/lib/transport/transport_op_string.cc +++ b/src/core/lib/transport/transport_op_string.cc @@ -134,19 +134,22 @@ char* grpc_transport_op_string(grpc_transport_op* op) { gpr_strvec b; gpr_strvec_init(&b); - if (op->on_connectivity_state_change != nullptr) { + if (op->start_connectivity_watch != nullptr) { if (!first) gpr_strvec_add(&b, gpr_strdup(" ")); first = false; - if (op->connectivity_state != nullptr) { - gpr_asprintf(&tmp, "ON_CONNECTIVITY_STATE_CHANGE:p=%p:from=%s", - op->on_connectivity_state_change, - grpc_connectivity_state_name(*op->connectivity_state)); - gpr_strvec_add(&b, tmp); - } else { - gpr_asprintf(&tmp, "ON_CONNECTIVITY_STATE_CHANGE:p=%p:unsubscribe", - op->on_connectivity_state_change); - gpr_strvec_add(&b, tmp); - } + gpr_asprintf( + &tmp, "START_CONNECTIVITY_WATCH:watcher=%p:from=%s", + op->start_connectivity_watch.get(), + grpc_core::ConnectivityStateName(op->start_connectivity_watch_state)); + gpr_strvec_add(&b, tmp); + } + + if (op->stop_connectivity_watch != nullptr) { + if (!first) gpr_strvec_add(&b, gpr_strdup(" ")); + first = false; + gpr_asprintf(&tmp, "STOP_CONNECTIVITY_WATCH:watcher=%p", + op->stop_connectivity_watch); + gpr_strvec_add(&b, tmp); } if (op->disconnect_with_error != GRPC_ERROR_NONE) { diff --git a/test/core/surface/lame_client_test.cc b/test/core/surface/lame_client_test.cc index 09c3d431977..34cafbbd5b7 100644 --- a/test/core/surface/lame_client_test.cc +++ b/test/core/surface/lame_client_test.cc @@ -28,31 +28,27 @@ #include "test/core/end2end/cq_verifier.h" #include "test/core/util/test_config.h" -grpc_closure transport_op_cb; +class Watcher : public grpc_core::ConnectivityStateWatcherInterface { + public: + void Notify(grpc_connectivity_state new_state) override { + GPR_ASSERT(new_state == GRPC_CHANNEL_SHUTDOWN); + } +}; static void* tag(intptr_t x) { return (void*)x; } -void verify_connectivity(void* arg, grpc_error* error) { - grpc_connectivity_state* state = static_cast(arg); - GPR_ASSERT(GRPC_CHANNEL_SHUTDOWN == *state); - GPR_ASSERT(error == GRPC_ERROR_NONE); -} +static grpc_closure transport_op_cb; -void do_nothing(void* arg, grpc_error* error) {} +static void do_nothing(void* arg, grpc_error* error) {} void test_transport_op(grpc_channel* channel) { - grpc_transport_op* op; - grpc_channel_element* elem; - grpc_connectivity_state state = GRPC_CHANNEL_IDLE; grpc_core::ExecCtx exec_ctx; - - GRPC_CLOSURE_INIT(&transport_op_cb, verify_connectivity, &state, - grpc_schedule_on_exec_ctx); - - op = grpc_make_transport_op(nullptr); - op->on_connectivity_state_change = &transport_op_cb; - op->connectivity_state = &state; - elem = grpc_channel_stack_element(grpc_channel_get_channel_stack(channel), 0); + grpc_transport_op* op = grpc_make_transport_op(nullptr); + op->start_connectivity_watch = + grpc_core::OrphanablePtr( + grpc_core::New()); + grpc_channel_element* elem = + grpc_channel_stack_element(grpc_channel_get_channel_stack(channel), 0); elem->filter->start_transport_op(elem, op); GRPC_CLOSURE_INIT(&transport_op_cb, do_nothing, nullptr, diff --git a/test/core/transport/BUILD b/test/core/transport/BUILD index 94ebb602d80..12e748f7d10 100644 --- a/test/core/transport/BUILD +++ b/test/core/transport/BUILD @@ -51,6 +51,9 @@ grpc_cc_test( grpc_cc_test( name = "connectivity_state_test", srcs = ["connectivity_state_test.cc"], + external_deps = [ + "gtest", + ], language = "C++", deps = [ "//:gpr", diff --git a/test/core/transport/connectivity_state_test.cc b/test/core/transport/connectivity_state_test.cc index 26c09a76039..e0141cd02d0 100644 --- a/test/core/transport/connectivity_state_test.cc +++ b/test/core/transport/connectivity_state_test.cc @@ -20,124 +20,146 @@ #include +#include + #include #include "src/core/lib/iomgr/exec_ctx.h" #include "test/core/util/test_config.h" #include "test/core/util/tracer_util.h" -#define THE_ARG ((void*)(size_t)0xcafebabe) - -int g_counter; +namespace grpc_core { +namespace { -static void must_succeed(void* arg, grpc_error* error) { - GPR_ASSERT(error == GRPC_ERROR_NONE); - GPR_ASSERT(arg == THE_ARG); - g_counter++; +TEST(ConnectivityStateName, Basic) { + EXPECT_STREQ("IDLE", ConnectivityStateName(GRPC_CHANNEL_IDLE)); + EXPECT_STREQ("CONNECTING", ConnectivityStateName(GRPC_CHANNEL_CONNECTING)); + EXPECT_STREQ("READY", ConnectivityStateName(GRPC_CHANNEL_READY)); + EXPECT_STREQ("TRANSIENT_FAILURE", + ConnectivityStateName(GRPC_CHANNEL_TRANSIENT_FAILURE)); + EXPECT_STREQ("SHUTDOWN", ConnectivityStateName(GRPC_CHANNEL_SHUTDOWN)); } -static void must_fail(void* arg, grpc_error* error) { - GPR_ASSERT(error != GRPC_ERROR_NONE); - GPR_ASSERT(arg == THE_ARG); - g_counter++; +class Watcher : public ConnectivityStateWatcherInterface { + public: + Watcher(int* count, grpc_connectivity_state* output, + bool* destroyed = nullptr) + : count_(count), output_(output), destroyed_(destroyed) {} + + ~Watcher() { + if (destroyed_ != nullptr) *destroyed_ = true; + } + + void Notify(grpc_connectivity_state new_state) override { + ++*count_; + *output_ = new_state; + } + + private: + int* count_; + grpc_connectivity_state* output_; + bool* destroyed_; +}; + +TEST(StateTracker, SetAndGetState) { + ConnectivityStateTracker tracker("xxx", GRPC_CHANNEL_CONNECTING); + EXPECT_EQ(tracker.state(), GRPC_CHANNEL_CONNECTING); + tracker.SetState(GRPC_CHANNEL_READY, "whee"); + EXPECT_EQ(tracker.state(), GRPC_CHANNEL_READY); } -static void test_connectivity_state_name(void) { - gpr_log(GPR_DEBUG, "test_connectivity_state_name"); - GPR_ASSERT(0 == - strcmp(grpc_connectivity_state_name(GRPC_CHANNEL_IDLE), "IDLE")); - GPR_ASSERT(0 == strcmp(grpc_connectivity_state_name(GRPC_CHANNEL_CONNECTING), - "CONNECTING")); - GPR_ASSERT(0 == - strcmp(grpc_connectivity_state_name(GRPC_CHANNEL_READY), "READY")); - GPR_ASSERT( - 0 == strcmp(grpc_connectivity_state_name(GRPC_CHANNEL_TRANSIENT_FAILURE), - "TRANSIENT_FAILURE")); - GPR_ASSERT(0 == strcmp(grpc_connectivity_state_name(GRPC_CHANNEL_SHUTDOWN), - "SHUTDOWN")); +TEST(StateTracker, NotificationUponAddingWatcher) { + int count = 0; + grpc_connectivity_state state = GRPC_CHANNEL_IDLE; + ConnectivityStateTracker tracker("xxx", GRPC_CHANNEL_CONNECTING); + tracker.AddWatcher(GRPC_CHANNEL_IDLE, + OrphanablePtr( + New(&count, &state))); + EXPECT_EQ(count, 1); + EXPECT_EQ(state, GRPC_CHANNEL_CONNECTING); } -static void test_check(void) { - grpc_connectivity_state_tracker tracker; - grpc_core::ExecCtx exec_ctx; - gpr_log(GPR_DEBUG, "test_check"); - grpc_connectivity_state_init(&tracker, GRPC_CHANNEL_IDLE, "xxx"); - GPR_ASSERT(grpc_connectivity_state_check(&tracker) == GRPC_CHANNEL_IDLE); - grpc_connectivity_state_destroy(&tracker); +TEST(StateTracker, NotificationUponStateChange) { + int count = 0; + grpc_connectivity_state state = GRPC_CHANNEL_IDLE; + ConnectivityStateTracker tracker("xxx", GRPC_CHANNEL_IDLE); + tracker.AddWatcher(GRPC_CHANNEL_IDLE, + OrphanablePtr( + New(&count, &state))); + EXPECT_EQ(count, 0); + EXPECT_EQ(state, GRPC_CHANNEL_IDLE); + tracker.SetState(GRPC_CHANNEL_CONNECTING, "whee"); + EXPECT_EQ(count, 1); + EXPECT_EQ(state, GRPC_CHANNEL_CONNECTING); } -static void test_subscribe_then_unsubscribe(void) { - grpc_connectivity_state_tracker tracker; - grpc_closure* closure = - GRPC_CLOSURE_CREATE(must_fail, THE_ARG, grpc_schedule_on_exec_ctx); +TEST(StateTracker, SubscribeThenUnsubscribe) { + int count = 0; grpc_connectivity_state state = GRPC_CHANNEL_IDLE; - grpc_core::ExecCtx exec_ctx; - gpr_log(GPR_DEBUG, "test_subscribe_then_unsubscribe"); - g_counter = 0; - grpc_connectivity_state_init(&tracker, GRPC_CHANNEL_IDLE, "xxx"); - GPR_ASSERT(grpc_connectivity_state_notify_on_state_change(&tracker, &state, - closure)); - grpc_core::ExecCtx::Get()->Flush(); - GPR_ASSERT(state == GRPC_CHANNEL_IDLE); - GPR_ASSERT(g_counter == 0); - grpc_connectivity_state_notify_on_state_change(&tracker, nullptr, closure); - grpc_core::ExecCtx::Get()->Flush(); - GPR_ASSERT(state == GRPC_CHANNEL_IDLE); - GPR_ASSERT(g_counter == 1); - - grpc_connectivity_state_destroy(&tracker); + bool destroyed = false; + ConnectivityStateTracker tracker("xxx", GRPC_CHANNEL_IDLE); + ConnectivityStateWatcherInterface* watcher = + New(&count, &state, &destroyed); + tracker.AddWatcher(GRPC_CHANNEL_IDLE, + OrphanablePtr(watcher)); + // No initial notification, since we started the watch from the + // current state. + EXPECT_EQ(count, 0); + EXPECT_EQ(state, GRPC_CHANNEL_IDLE); + // Cancel watch. This should not generate another notification. + tracker.RemoveWatcher(watcher); + EXPECT_TRUE(destroyed); + EXPECT_EQ(count, 0); + EXPECT_EQ(state, GRPC_CHANNEL_IDLE); } -static void test_subscribe_then_destroy(void) { - grpc_connectivity_state_tracker tracker; - grpc_closure* closure = - GRPC_CLOSURE_CREATE(must_succeed, THE_ARG, grpc_schedule_on_exec_ctx); +TEST(StateTracker, NotifyShutdownAtDestruction) { + int count = 0; grpc_connectivity_state state = GRPC_CHANNEL_IDLE; - grpc_core::ExecCtx exec_ctx; - gpr_log(GPR_DEBUG, "test_subscribe_then_destroy"); - g_counter = 0; - grpc_connectivity_state_init(&tracker, GRPC_CHANNEL_IDLE, "xxx"); - GPR_ASSERT(grpc_connectivity_state_notify_on_state_change(&tracker, &state, - closure)); - grpc_core::ExecCtx::Get()->Flush(); - GPR_ASSERT(state == GRPC_CHANNEL_IDLE); - GPR_ASSERT(g_counter == 0); - grpc_connectivity_state_destroy(&tracker); - - grpc_core::ExecCtx::Get()->Flush(); - GPR_ASSERT(state == GRPC_CHANNEL_SHUTDOWN); - GPR_ASSERT(g_counter == 1); + { + ConnectivityStateTracker tracker("xxx", GRPC_CHANNEL_IDLE); + tracker.AddWatcher(GRPC_CHANNEL_IDLE, + OrphanablePtr( + New(&count, &state))); + // No initial notification, since we started the watch from the + // current state. + EXPECT_EQ(count, 0); + EXPECT_EQ(state, GRPC_CHANNEL_IDLE); + } + // Upon tracker destruction, we get a notification for SHUTDOWN. + EXPECT_EQ(count, 1); + EXPECT_EQ(state, GRPC_CHANNEL_SHUTDOWN); } -static void test_subscribe_with_failure_then_destroy(void) { - grpc_connectivity_state_tracker tracker; - grpc_closure* closure = - GRPC_CLOSURE_CREATE(must_fail, THE_ARG, grpc_schedule_on_exec_ctx); +TEST(StateTracker, DoNotNotifyShutdownAtDestructionIfAlreadyInShutdown) { + int count = 0; grpc_connectivity_state state = GRPC_CHANNEL_SHUTDOWN; - grpc_core::ExecCtx exec_ctx; - gpr_log(GPR_DEBUG, "test_subscribe_with_failure_then_destroy"); - g_counter = 0; - grpc_connectivity_state_init(&tracker, GRPC_CHANNEL_SHUTDOWN, "xxx"); - GPR_ASSERT(0 == grpc_connectivity_state_notify_on_state_change( - &tracker, &state, closure)); - grpc_core::ExecCtx::Get()->Flush(); - GPR_ASSERT(state == GRPC_CHANNEL_SHUTDOWN); - GPR_ASSERT(g_counter == 0); - grpc_connectivity_state_destroy(&tracker); - grpc_core::ExecCtx::Get()->Flush(); - GPR_ASSERT(state == GRPC_CHANNEL_SHUTDOWN); - GPR_ASSERT(g_counter == 1); + { + ConnectivityStateTracker tracker("xxx", GRPC_CHANNEL_SHUTDOWN); + tracker.AddWatcher(GRPC_CHANNEL_SHUTDOWN, + OrphanablePtr( + New(&count, &state))); + // No initial notification, since we started the watch from the + // current state. + EXPECT_EQ(count, 0); + EXPECT_EQ(state, GRPC_CHANNEL_SHUTDOWN); + } + // No additional notification upon tracker destruction, since we were + // already in state SHUTDOWN. + EXPECT_EQ(count, 0); + EXPECT_EQ(state, GRPC_CHANNEL_SHUTDOWN); } +} // namespace +} // namespace grpc_core + int main(int argc, char** argv) { grpc::testing::TestEnvironment env(argc, argv); grpc_init(); - grpc_core::testing::grpc_tracer_enable_flag(&grpc_connectivity_state_trace); - test_connectivity_state_name(); - test_check(); - test_subscribe_then_unsubscribe(); - test_subscribe_then_destroy(); - test_subscribe_with_failure_then_destroy(); + grpc_core::testing::grpc_tracer_enable_flag( + &grpc_core::grpc_connectivity_state_trace); + ::testing::InitGoogleTest(&argc, argv); + int ret = RUN_ALL_TESTS(); grpc_shutdown(); - return 0; + return ret; } diff --git a/tools/run_tests/generated/tests.json b/tools/run_tests/generated/tests.json index 1f9634e34e3..b4b3822bde5 100644 --- a/tools/run_tests/generated/tests.json +++ b/tools/run_tests/generated/tests.json @@ -2917,30 +2917,6 @@ ], "uses_polling": false }, - { - "args": [], - "benchmark": false, - "ci_platforms": [ - "linux", - "mac", - "posix", - "windows" - ], - "cpu_cost": 1.0, - "exclude_configs": [], - "exclude_iomgrs": [], - "flaky": false, - "gtest": false, - "language": "c", - "name": "transport_connectivity_state_test", - "platforms": [ - "linux", - "mac", - "posix", - "windows" - ], - "uses_polling": true - }, { "args": [], "benchmark": false, @@ -5994,6 +5970,30 @@ ], "uses_polling": true }, + { + "args": [], + "benchmark": false, + "ci_platforms": [ + "linux", + "mac", + "posix", + "windows" + ], + "cpu_cost": 1.0, + "exclude_configs": [], + "exclude_iomgrs": [], + "flaky": false, + "gtest": true, + "language": "c++", + "name": "transport_connectivity_state_test", + "platforms": [ + "linux", + "mac", + "posix", + "windows" + ], + "uses_polling": true + }, { "args": [], "benchmark": false, From 40105dfa4b1c227c518bd8a9617075975ae067d4 Mon Sep 17 00:00:00 2001 From: Yihua Zhang Date: Mon, 30 Sep 2019 13:32:41 -0700 Subject: [PATCH 35/60] update grpc_ssl_peer_to_auth_context --- .../security_connector/ssl/ssl_security_connector.cc | 3 ++- src/core/lib/security/security_connector/ssl_utils.cc | 4 ++-- src/core/lib/security/security_connector/ssl_utils.h | 2 +- .../security_connector/tls/spiffe_security_connector.cc | 6 ++++-- 4 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/core/lib/security/security_connector/ssl/ssl_security_connector.cc b/src/core/lib/security/security_connector/ssl/ssl_security_connector.cc index 0318e0aeb62..87ebd7ad171 100644 --- a/src/core/lib/security/security_connector/ssl/ssl_security_connector.cc +++ b/src/core/lib/security/security_connector/ssl/ssl_security_connector.cc @@ -56,7 +56,8 @@ grpc_error* ssl_check_peer( gpr_free(msg); return error; } - *auth_context = grpc_ssl_peer_to_auth_context(peer); + *auth_context = + grpc_ssl_peer_to_auth_context(peer, GRPC_SSL_TRANSPORT_SECURITY_TYPE); return GRPC_ERROR_NONE; } diff --git a/src/core/lib/security/security_connector/ssl_utils.cc b/src/core/lib/security/security_connector/ssl_utils.cc index bacd31a1f30..9686426074e 100644 --- a/src/core/lib/security/security_connector/ssl_utils.cc +++ b/src/core/lib/security/security_connector/ssl_utils.cc @@ -195,7 +195,7 @@ int grpc_ssl_cmp_target_name( } grpc_core::RefCountedPtr grpc_ssl_peer_to_auth_context( - const tsi_peer* peer) { + const tsi_peer* peer, const char* transport_security_type) { size_t i; const char* peer_identity_property_name = nullptr; @@ -205,7 +205,7 @@ grpc_core::RefCountedPtr grpc_ssl_peer_to_auth_context( grpc_core::MakeRefCounted(nullptr); grpc_auth_context_add_cstring_property( ctx.get(), GRPC_TRANSPORT_SECURITY_TYPE_PROPERTY_NAME, - GRPC_SSL_TRANSPORT_SECURITY_TYPE); + transport_security_type); for (i = 0; i < peer->property_count; i++) { const tsi_peer_property* prop = &peer->properties[i]; if (prop->name == nullptr) continue; diff --git a/src/core/lib/security/security_connector/ssl_utils.h b/src/core/lib/security/security_connector/ssl_utils.h index c13dd90a932..6ee2c3c7248 100644 --- a/src/core/lib/security/security_connector/ssl_utils.h +++ b/src/core/lib/security/security_connector/ssl_utils.h @@ -85,7 +85,7 @@ grpc_security_status grpc_ssl_tsi_server_handshaker_factory_init( /* Exposed for testing only. */ grpc_core::RefCountedPtr grpc_ssl_peer_to_auth_context( - const tsi_peer* peer); + const tsi_peer* peer, const char* transport_security_type); tsi_peer grpc_shallow_peer_from_ssl_auth_context( const grpc_auth_context* auth_context); void grpc_shallow_peer_destruct(tsi_peer* peer); diff --git a/src/core/lib/security/security_connector/tls/spiffe_security_connector.cc b/src/core/lib/security/security_connector/tls/spiffe_security_connector.cc index bac32c08813..85ff3c43eab 100644 --- a/src/core/lib/security/security_connector/tls/spiffe_security_connector.cc +++ b/src/core/lib/security/security_connector/tls/spiffe_security_connector.cc @@ -173,7 +173,8 @@ void SpiffeChannelSecurityConnector::check_peer( tsi_peer_destruct(&peer); return; } - *auth_context = grpc_ssl_peer_to_auth_context(&peer); + *auth_context = grpc_ssl_peer_to_auth_context( + &peer, GRPC_TLS_SPIFFE_TRANSPORT_SECURITY_TYPE); const SpiffeCredentials* creds = static_cast(channel_creds()); const grpc_tls_server_authorization_check_config* config = @@ -436,7 +437,8 @@ void SpiffeServerSecurityConnector::check_peer( grpc_core::RefCountedPtr* auth_context, grpc_closure* on_peer_checked) { grpc_error* error = grpc_ssl_check_alpn(&peer); - *auth_context = grpc_ssl_peer_to_auth_context(&peer); + *auth_context = grpc_ssl_peer_to_auth_context( + &peer, GRPC_TLS_SPIFFE_TRANSPORT_SECURITY_TYPE); tsi_peer_destruct(&peer); GRPC_CLOSURE_SCHED(on_peer_checked, error); } From dbad2db8482f264944ba3b33b405dfbac1ebdef3 Mon Sep 17 00:00:00 2001 From: "Mark D. Roth" Date: Mon, 30 Sep 2019 12:17:34 -0700 Subject: [PATCH 36/60] Immediately orphan watcher if state is SHUTDOWN when it is added. --- src/core/lib/transport/connectivity_state.cc | 6 +++- src/core/lib/transport/connectivity_state.h | 4 +++ .../core/transport/connectivity_state_test.cc | 34 +++++++++++++++++++ 3 files changed, 43 insertions(+), 1 deletion(-) diff --git a/src/core/lib/transport/connectivity_state.cc b/src/core/lib/transport/connectivity_state.cc index 45ebdca4f0d..32aa99306be 100644 --- a/src/core/lib/transport/connectivity_state.cc +++ b/src/core/lib/transport/connectivity_state.cc @@ -120,7 +120,11 @@ void ConnectivityStateTracker::AddWatcher( } watcher->Notify(current_state); } - watchers_.insert(MakePair(watcher.get(), std::move(watcher))); + // If we're in state SHUTDOWN, don't add the watcher, so that it will + // be orphaned immediately. + if (current_state != GRPC_CHANNEL_SHUTDOWN) { + watchers_.insert(MakePair(watcher.get(), std::move(watcher))); + } } void ConnectivityStateTracker::RemoveWatcher( diff --git a/src/core/lib/transport/connectivity_state.h b/src/core/lib/transport/connectivity_state.h index 41f7bf08e41..25b43561364 100644 --- a/src/core/lib/transport/connectivity_state.h +++ b/src/core/lib/transport/connectivity_state.h @@ -76,6 +76,10 @@ class AsyncConnectivityStateWatcherInterface // Tracks connectivity state. Maintains a list of watchers that are // notified whenever the state changes. +// +// Note that once the state becomes SHUTDOWN, watchers will be notified +// and then automatically orphaned (i.e., RemoveWatcher() does not need +// to be called). class ConnectivityStateTracker { public: ConnectivityStateTracker(const char* name, diff --git a/test/core/transport/connectivity_state_test.cc b/test/core/transport/connectivity_state_test.cc index e0141cd02d0..6493a62ff3c 100644 --- a/test/core/transport/connectivity_state_test.cc +++ b/test/core/transport/connectivity_state_test.cc @@ -113,6 +113,40 @@ TEST(StateTracker, SubscribeThenUnsubscribe) { EXPECT_EQ(state, GRPC_CHANNEL_IDLE); } +TEST(StateTracker, OrphanUponShutdown) { + int count = 0; + grpc_connectivity_state state = GRPC_CHANNEL_IDLE; + bool destroyed = false; + ConnectivityStateTracker tracker("xxx", GRPC_CHANNEL_IDLE); + ConnectivityStateWatcherInterface* watcher = + New(&count, &state, &destroyed); + tracker.AddWatcher(GRPC_CHANNEL_IDLE, + OrphanablePtr(watcher)); + // No initial notification, since we started the watch from the + // current state. + EXPECT_EQ(count, 0); + EXPECT_EQ(state, GRPC_CHANNEL_IDLE); + // Set state to SHUTDOWN. + tracker.SetState(GRPC_CHANNEL_SHUTDOWN, "shutting down"); + EXPECT_TRUE(destroyed); + EXPECT_EQ(count, 1); + EXPECT_EQ(state, GRPC_CHANNEL_SHUTDOWN); +} + +TEST(StateTracker, AddWhenAlreadyShutdown) { + int count = 0; + grpc_connectivity_state state = GRPC_CHANNEL_IDLE; + bool destroyed = false; + ConnectivityStateTracker tracker("xxx", GRPC_CHANNEL_SHUTDOWN); + ConnectivityStateWatcherInterface* watcher = + New(&count, &state, &destroyed); + tracker.AddWatcher(GRPC_CHANNEL_IDLE, + OrphanablePtr(watcher)); + EXPECT_TRUE(destroyed); + EXPECT_EQ(count, 1); + EXPECT_EQ(state, GRPC_CHANNEL_SHUTDOWN); +} + TEST(StateTracker, NotifyShutdownAtDestruction) { int count = 0; grpc_connectivity_state state = GRPC_CHANNEL_IDLE; From 9be983d40bf49888df96e66ca49d12241c3eb45d Mon Sep 17 00:00:00 2001 From: Yihua Zhang Date: Mon, 30 Sep 2019 14:04:52 -0700 Subject: [PATCH 37/60] fix tests. --- test/core/security/security_connector_test.cc | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/test/core/security/security_connector_test.cc b/test/core/security/security_connector_test.cc index c888c90c646..48a3088fde8 100644 --- a/test/core/security/security_connector_test.cc +++ b/test/core/security/security_connector_test.cc @@ -92,7 +92,7 @@ static void test_unauthenticated_ssl_peer(void) { TSI_CERTIFICATE_TYPE_PEER_PROPERTY, TSI_X509_CERTIFICATE_TYPE, &peer.properties[0]) == TSI_OK); grpc_core::RefCountedPtr ctx = - grpc_ssl_peer_to_auth_context(&peer); + grpc_ssl_peer_to_auth_context(&peer, GRPC_SSL_TRANSPORT_SECURITY_TYPE); GPR_ASSERT(ctx != nullptr); GPR_ASSERT(!grpc_auth_context_peer_is_authenticated(ctx.get())); GPR_ASSERT(check_transport_security_type(ctx.get())); @@ -192,7 +192,7 @@ static void test_cn_only_ssl_peer_to_auth_context(void) { TSI_X509_PEM_CERT_PROPERTY, expected_pem_cert, &peer.properties[2]) == TSI_OK); grpc_core::RefCountedPtr ctx = - grpc_ssl_peer_to_auth_context(&peer); + grpc_ssl_peer_to_auth_context(&peer, GRPC_SSL_TRANSPORT_SECURITY_TYPE); GPR_ASSERT(ctx != nullptr); GPR_ASSERT(grpc_auth_context_peer_is_authenticated(ctx.get())); GPR_ASSERT( @@ -230,7 +230,7 @@ static void test_cn_and_one_san_ssl_peer_to_auth_context(void) { &peer.properties[3]) == TSI_OK); grpc_core::RefCountedPtr ctx = - grpc_ssl_peer_to_auth_context(&peer); + grpc_ssl_peer_to_auth_context(&peer, GRPC_SSL_TRANSPORT_SECURITY_TYPE); GPR_ASSERT(ctx != nullptr); GPR_ASSERT(grpc_auth_context_peer_is_authenticated(ctx.get())); GPR_ASSERT( @@ -271,7 +271,7 @@ static void test_cn_and_multiple_sans_ssl_peer_to_auth_context(void) { expected_sans[i], &peer.properties[3 + i]) == TSI_OK); } grpc_core::RefCountedPtr ctx = - grpc_ssl_peer_to_auth_context(&peer); + grpc_ssl_peer_to_auth_context(&peer, GRPC_SSL_TRANSPORT_SECURITY_TYPE); GPR_ASSERT(ctx != nullptr); GPR_ASSERT(grpc_auth_context_peer_is_authenticated(ctx.get())); GPR_ASSERT(check_identity(ctx.get(), GRPC_X509_SAN_PROPERTY_NAME, @@ -317,7 +317,7 @@ static void test_cn_and_multiple_sans_and_others_ssl_peer_to_auth_context( expected_sans[i], &peer.properties[5 + i]) == TSI_OK); } grpc_core::RefCountedPtr ctx = - grpc_ssl_peer_to_auth_context(&peer); + grpc_ssl_peer_to_auth_context(&peer, GRPC_SSL_TRANSPORT_SECURITY_TYPE); GPR_ASSERT(ctx != nullptr); GPR_ASSERT(grpc_auth_context_peer_is_authenticated(ctx.get())); GPR_ASSERT(check_identity(ctx.get(), GRPC_X509_SAN_PROPERTY_NAME, From 4ecc1fe6a402bbcd4628ad1b46186832dfb54d94 Mon Sep 17 00:00:00 2001 From: chentanjun <2799194073@qq.com> Date: Sat, 28 Sep 2019 22:57:38 +0800 Subject: [PATCH 38/60] fix the wrong word --- doc/interop-test-descriptions.md | 2 +- examples/csharp/HelloworldXamarin/iOS/AppDelegate.cs | 2 +- examples/python/cancellation/README.md | 2 +- examples/python/cancellation/hash_name.proto | 2 +- examples/python/data_transmission/README.en.md | 2 +- src/compiler/ruby_generator_string-inl.h | 2 +- test/cpp/util/cli_credentials.cc | 4 ++-- test/cpp/util/proto_file_parser.h | 4 ++-- tools/buildgen/plugins/check_attrs.py | 2 +- tools/gce/linux_kokoro_performance_worker_init.sh | 2 +- tools/github/pr_latency.py | 2 +- tools/internal_ci/linux/grpc_publish_packages.sh | 2 +- tools/interop_matrix/create_matrix_images.py | 2 +- tools/interop_matrix/create_testcases.sh | 2 +- tools/profiling/microbenchmarks/bm_diff/bm_main.py | 4 ++-- tools/run_tests/performance/README.md | 2 +- tools/run_tests/run_tests.py | 4 ++-- 17 files changed, 21 insertions(+), 21 deletions(-) diff --git a/doc/interop-test-descriptions.md b/doc/interop-test-descriptions.md index 44473099cee..978c422d470 100755 --- a/doc/interop-test-descriptions.md +++ b/doc/interop-test-descriptions.md @@ -1121,7 +1121,7 @@ for the `SimpleRequest.response_type`. If the server does not support the Server gets the default SimpleRequest proto as the request. The content of the request is ignored. It returns the SimpleResponse proto with the payload set to current timestamp. The timestamp is an integer representing current time -with nanosecond resolution. This integer is formated as ASCII decimal in the +with nanosecond resolution. This integer is formatted as ASCII decimal in the response. The format is not really important as long as the response payload is different for each request. In addition it adds 1. cache control headers such that the response can be cached by proxies in diff --git a/examples/csharp/HelloworldXamarin/iOS/AppDelegate.cs b/examples/csharp/HelloworldXamarin/iOS/AppDelegate.cs index 16a071c4d60..53835f89dac 100644 --- a/examples/csharp/HelloworldXamarin/iOS/AppDelegate.cs +++ b/examples/csharp/HelloworldXamarin/iOS/AppDelegate.cs @@ -58,7 +58,7 @@ namespace HelloworldXamarin.iOS public override void WillEnterForeground(UIApplication application) { - // Called as part of the transiton from background to active state. + // Called as part of the transition from background to active state. // Here you can undo many of the changes made on entering the background. } diff --git a/examples/python/cancellation/README.md b/examples/python/cancellation/README.md index 26ef61c329f..87d0c76d9b1 100644 --- a/examples/python/cancellation/README.md +++ b/examples/python/cancellation/README.md @@ -76,7 +76,7 @@ catch the `RpcError` raised by the for loop upon cancellation. #### Cancellation on the Server Side -A server is reponsible for cancellation in two ways. It must respond in some way +A server is responsible for cancellation in two ways. It must respond in some way when a client initiates a cancellation, otherwise long-running computations could continue indefinitely. diff --git a/examples/python/cancellation/hash_name.proto b/examples/python/cancellation/hash_name.proto index 7b4e47e056f..262f12b21f8 100644 --- a/examples/python/cancellation/hash_name.proto +++ b/examples/python/cancellation/hash_name.proto @@ -21,7 +21,7 @@ message HashNameRequest { // The string that is desired in the secret's hash. string desired_name = 1; - // The ideal Hamming distance betwen desired_name and the secret that will + // The ideal Hamming distance between desired_name and the secret that will // be searched for. int32 ideal_hamming_distance = 2; diff --git a/examples/python/data_transmission/README.en.md b/examples/python/data_transmission/README.en.md index d9639290549..b935943477f 100644 --- a/examples/python/data_transmission/README.en.md +++ b/examples/python/data_transmission/README.en.md @@ -1,6 +1,6 @@ ## Data transmission demo for using gRPC in Python -Four ways of data transmission when gRPC is used in Python. [Offical Guide]() +Four ways of data transmission when gRPC is used in Python. [Official Guide]() - #### unary-unary diff --git a/src/compiler/ruby_generator_string-inl.h b/src/compiler/ruby_generator_string-inl.h index 7d6b50a516d..005e9f09c75 100644 --- a/src/compiler/ruby_generator_string-inl.h +++ b/src/compiler/ruby_generator_string-inl.h @@ -106,7 +106,7 @@ inline grpc::string RubyPackage(const grpc::protobuf::FileDescriptor* file) { if (file->options().has_ruby_package()) { package_name = file->options().ruby_package(); - // If :: is in the package convert the Ruby formated name + // If :: is in the package convert the Ruby formatted name // -> A::B::C // to use the dot seperator notation // -> A.B.C diff --git a/test/cpp/util/cli_credentials.cc b/test/cpp/util/cli_credentials.cc index 91acc904aac..1f7af81a331 100644 --- a/test/cpp/util/cli_credentials.cc +++ b/test/cpp/util/cli_credentials.cc @@ -41,11 +41,11 @@ DEFINE_string( "validation."); DEFINE_string( ssl_client_cert, "", - "If not empty, load this PEM formated client certificate file. Requires " + "If not empty, load this PEM formatted client certificate file. Requires " "use of --ssl_client_key."); DEFINE_string( ssl_client_key, "", - "If not empty, load this PEM formated private key. Requires use of " + "If not empty, load this PEM formatted private key. Requires use of " "--ssl_client_cert"); DEFINE_string( channel_creds_type, "", diff --git a/test/cpp/util/proto_file_parser.h b/test/cpp/util/proto_file_parser.h index 1e49c98daf9..114f5cba7c6 100644 --- a/test/cpp/util/proto_file_parser.h +++ b/test/cpp/util/proto_file_parser.h @@ -63,7 +63,7 @@ class ProtoFileParser { /// \param is_json_format if \c true the \c formatted_proto is treated as a /// json-formatted proto, otherwise it is treated as a text-formatted /// proto - /// \return the serialised binary proto represenation of \c formatted_proto + /// \return the serialised binary proto representation of \c formatted_proto grpc::string GetSerializedProtoFromMethod(const grpc::string& method, const grpc::string& formatted_proto, bool is_request, @@ -72,7 +72,7 @@ class ProtoFileParser { /// Converts a text or json string to its proto representation for the given /// message type. /// \param formatted_proto the text- or json-formatted proto string - /// \return the serialised binary proto represenation of \c formatted_proto + /// \return the serialised binary proto representation of \c formatted_proto grpc::string GetSerializedProtoFromMessageType( const grpc::string& message_type_name, const grpc::string& formatted_proto, bool is_json_format); diff --git a/tools/buildgen/plugins/check_attrs.py b/tools/buildgen/plugins/check_attrs.py index 0730f8a1bbb..1fadd3a2310 100644 --- a/tools/buildgen/plugins/check_attrs.py +++ b/tools/buildgen/plugins/check_attrs.py @@ -112,7 +112,7 @@ def mako_plugin(dictionary): This validates that filegroups, libs, and target can have only valid attributes. This is mainly for preventing build.yaml from having - unnecessary and misleading attributes accidently. + unnecessary and misleading attributes accidentally. """ errors = [] diff --git a/tools/gce/linux_kokoro_performance_worker_init.sh b/tools/gce/linux_kokoro_performance_worker_init.sh index 46061a0cc67..78c98ce1e3b 100755 --- a/tools/gce/linux_kokoro_performance_worker_init.sh +++ b/tools/gce/linux_kokoro_performance_worker_init.sh @@ -92,7 +92,7 @@ sudo pypy get-pip.py sudo pypy -m pip install tabulate sudo pypy -m pip install google-api-python-client oauth2client # TODO(jtattermusch): for some reason, we need psutil installed -# in pypy for kokoro_log_reader.py (strange, because the comand is +# in pypy for kokoro_log_reader.py (strange, because the command is # "python kokoro_log_reader.py" and pypy is not the system default) sudo pypy -m pip install psutil diff --git a/tools/github/pr_latency.py b/tools/github/pr_latency.py index 34870a53260..2eb87aa66bb 100644 --- a/tools/github/pr_latency.py +++ b/tools/github/pr_latency.py @@ -18,7 +18,7 @@ You'll need a github API token to avoid being rate-limited. See https://help.github.com/articles/creating-a-personal-access-token-for-the-command-line/ This script goes over the most recent 100 pull requests. For PRs with a single -commit, it uses the PR's creation as the initial time; othewise, it uses the +commit, it uses the PR's creation as the initial time; otherwise, it uses the date of the last commit. This is somewhat fragile, and imposed by the fact that GitHub reports a PR's updated timestamp for any event that modifies the PR (e.g. comments), not just the addition of new commits. diff --git a/tools/internal_ci/linux/grpc_publish_packages.sh b/tools/internal_ci/linux/grpc_publish_packages.sh index 87684214d84..db5c9d0b03b 100755 --- a/tools/internal_ci/linux/grpc_publish_packages.sh +++ b/tools/internal_ci/linux/grpc_publish_packages.sh @@ -223,7 +223,7 @@ EOF # Upload the current build artifacts gsutil -m cp -r "$LOCAL_STAGING_TEMPDIR/${BUILD_RELPATH%%/*}" "$GCS_ARCHIVE_ROOT" -# Upload directory indicies for subdirectories +# Upload directory indices for subdirectories ( cd "$LOCAL_BUILD_ROOT" find * -type d | while read -r directory diff --git a/tools/interop_matrix/create_matrix_images.py b/tools/interop_matrix/create_matrix_images.py index 28dc4be0f4d..0e4423b92ac 100755 --- a/tools/interop_matrix/create_matrix_images.py +++ b/tools/interop_matrix/create_matrix_images.py @@ -25,7 +25,7 @@ import subprocess import sys import tempfile -# Langauage Runtime Matrix +# Language Runtime Matrix import client_matrix python_util_dir = os.path.abspath( diff --git a/tools/interop_matrix/create_testcases.sh b/tools/interop_matrix/create_testcases.sh index b3e3ee6cd25..5074a8abbf5 100755 --- a/tools/interop_matrix/create_testcases.sh +++ b/tools/interop_matrix/create_testcases.sh @@ -19,7 +19,7 @@ # Params: # LANG - The language. # SKIP_TEST - If set, skip running the test cases for sanity. -# RELEASE - Create testcase for specific release, defautl to 'master'. +# RELEASE - Create testcase for specific release, default to 'master'. # KEEP_IMAGE - Do not clean local docker image created for the test cases. set -e diff --git a/tools/profiling/microbenchmarks/bm_diff/bm_main.py b/tools/profiling/microbenchmarks/bm_diff/bm_main.py index e5061b24f57..2dbaa1b7bef 100755 --- a/tools/profiling/microbenchmarks/bm_diff/bm_main.py +++ b/tools/profiling/microbenchmarks/bm_diff/bm_main.py @@ -66,7 +66,7 @@ def _args(): '--old', default='old', type=str, - help='Name of baseline run to compare to. Ususally just called "old"') + help='Name of baseline run to compare to. Usually just called "old"') argp.add_argument( '-r', '--regex', @@ -91,7 +91,7 @@ def _args(): '--pr_comment_name', type=str, default="microbenchmarks", - help='Name that Jenkins will use to commen on the PR') + help='Name that Jenkins will use to comment on the PR') argp.add_argument('--counters', dest='counters', action='store_true') argp.add_argument('--no-counters', dest='counters', action='store_false') argp.set_defaults(counters=True) diff --git a/tools/run_tests/performance/README.md b/tools/run_tests/performance/README.md index 791270ab389..787f3229bc9 100644 --- a/tools/run_tests/performance/README.md +++ b/tools/run_tests/performance/README.md @@ -24,7 +24,7 @@ GCE "worker" machines that are in the same zone. * For example, to start the grpc-go benchmark worker: [grpc-go worker main.go](https://github.com/grpc/grpc-go/blob/master/benchmark/worker/main.go) --driver_port -#### Comands to start workers in different languages: +#### Commands to start workers in different languages: * Note that these commands are what the top-level [run_performance_test.py](../run_performance_tests.py) script uses to build and run different workers through the diff --git a/tools/run_tests/run_tests.py b/tools/run_tests/run_tests.py index 6786b8d53bb..7d2d56530af 100755 --- a/tools/run_tests/run_tests.py +++ b/tools/run_tests/run_tests.py @@ -1380,7 +1380,7 @@ def _docker_arch_suffix(arch): def runs_per_test_type(arg_str): - """Auxilary function to parse the "runs_per_test" flag. + """Auxiliary function to parse the "runs_per_test" flag. Returns: A positive integer or 0, the latter indicating an infinite number of @@ -1786,7 +1786,7 @@ def _shut_down_legacy_server(legacy_server_port): def _calculate_num_runs_failures(list_of_results): - """Caculate number of runs and failures for a particular test. + """Calculate number of runs and failures for a particular test. Args: list_of_results: (List) of JobResult object. From 5f83f6c43f37be6ba2394aefb2adbd94d82f59cf Mon Sep 17 00:00:00 2001 From: Jan Tattermusch Date: Tue, 1 Oct 2019 09:34:44 +0200 Subject: [PATCH 39/60] Revert "Make public header files in include/grpcpp/test installed with 'make install'" --- CMakeLists.txt | 60 --------------------------------- Makefile | 91 ++------------------------------------------------ build.yaml | 20 +++++------ grpc.gyp | 10 ------ 4 files changed, 11 insertions(+), 170 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 814fcc60342..6ce00ecacdf 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3776,66 +3776,6 @@ if (gRPC_INSTALL) endif() endif (gRPC_BUILD_CODEGEN) - -add_library(grpc++_test -) - -if(WIN32 AND MSVC) - set_target_properties(grpc++_test PROPERTIES COMPILE_PDB_NAME "grpc++_test" - COMPILE_PDB_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}" - ) - if (gRPC_INSTALL) - install(FILES ${CMAKE_CURRENT_BINARY_DIR}/grpc++_test.pdb - DESTINATION ${gRPC_INSTALL_LIBDIR} OPTIONAL - ) - endif() -endif() - - -target_include_directories(grpc++_test - PUBLIC $ $ - PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} - PRIVATE ${_gRPC_ADDRESS_SORTING_INCLUDE_DIR} - PRIVATE ${_gRPC_BENCHMARK_INCLUDE_DIR} - PRIVATE ${_gRPC_CARES_INCLUDE_DIR} - PRIVATE ${_gRPC_GFLAGS_INCLUDE_DIR} - PRIVATE ${_gRPC_PROTOBUF_INCLUDE_DIR} - PRIVATE ${_gRPC_SSL_INCLUDE_DIR} - PRIVATE ${_gRPC_UPB_GENERATED_DIR} - PRIVATE ${_gRPC_UPB_GRPC_GENERATED_DIR} - PRIVATE ${_gRPC_UPB_INCLUDE_DIR} - PRIVATE ${_gRPC_ZLIB_INCLUDE_DIR} - PRIVATE ${_gRPC_PROTO_GENS_DIR} -) -target_link_libraries(grpc++_test - ${_gRPC_PROTOBUF_LIBRARIES} - ${_gRPC_ALLTARGETS_LIBRARIES} - grpc++ - grpc -) - -foreach(_hdr - include/grpc++/test/mock_stream.h - include/grpc++/test/server_context_test_spouse.h - include/grpcpp/test/mock_stream.h - include/grpcpp/test/server_context_test_spouse.h -) - string(REPLACE "include/" "" _path ${_hdr}) - get_filename_component(_path ${_path} PATH) - install(FILES ${_hdr} - DESTINATION "${gRPC_INSTALL_INCLUDEDIR}/${_path}" - ) -endforeach() - - -if (gRPC_INSTALL) - install(TARGETS grpc++_test EXPORT gRPCTargets - RUNTIME DESTINATION ${gRPC_INSTALL_BINDIR} - LIBRARY DESTINATION ${gRPC_INSTALL_LIBDIR} - ARCHIVE DESTINATION ${gRPC_INSTALL_LIBDIR} - ) -endif() - if (gRPC_BUILD_TESTS) add_library(grpc++_test_config diff --git a/Makefile b/Makefile index 5a3848737eb..728402c8bc0 100644 --- a/Makefile +++ b/Makefile @@ -1401,14 +1401,14 @@ static: static_c static_cxx static_c: pc_c pc_c_unsecure cache.mk $(LIBDIR)/$(CONFIG)/libaddress_sorting.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgrpc_cronet.a $(LIBDIR)/$(CONFIG)/libgrpc_unsecure.a -static_cxx: pc_cxx pc_cxx_unsecure cache.mk $(LIBDIR)/$(CONFIG)/libgrpc++.a $(LIBDIR)/$(CONFIG)/libgrpc++_error_details.a $(LIBDIR)/$(CONFIG)/libgrpc++_reflection.a $(LIBDIR)/$(CONFIG)/libgrpc++_test.a $(LIBDIR)/$(CONFIG)/libgrpc++_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpcpp_channelz.a +static_cxx: pc_cxx pc_cxx_unsecure cache.mk $(LIBDIR)/$(CONFIG)/libgrpc++.a $(LIBDIR)/$(CONFIG)/libgrpc++_error_details.a $(LIBDIR)/$(CONFIG)/libgrpc++_reflection.a $(LIBDIR)/$(CONFIG)/libgrpc++_unsecure.a $(LIBDIR)/$(CONFIG)/libgrpcpp_channelz.a static_csharp: static_c $(LIBDIR)/$(CONFIG)/libgrpc_csharp_ext.a shared: shared_c shared_cxx shared_c: pc_c pc_c_unsecure cache.mk $(LIBDIR)/$(CONFIG)/$(SHARED_PREFIX)address_sorting$(SHARED_VERSION_CORE).$(SHARED_EXT_CORE) $(LIBDIR)/$(CONFIG)/$(SHARED_PREFIX)gpr$(SHARED_VERSION_CORE).$(SHARED_EXT_CORE) $(LIBDIR)/$(CONFIG)/$(SHARED_PREFIX)grpc$(SHARED_VERSION_CORE).$(SHARED_EXT_CORE) $(LIBDIR)/$(CONFIG)/$(SHARED_PREFIX)grpc_cronet$(SHARED_VERSION_CORE).$(SHARED_EXT_CORE) $(LIBDIR)/$(CONFIG)/$(SHARED_PREFIX)grpc_unsecure$(SHARED_VERSION_CORE).$(SHARED_EXT_CORE) -shared_cxx: pc_cxx pc_cxx_unsecure cache.mk $(LIBDIR)/$(CONFIG)/$(SHARED_PREFIX)grpc++$(SHARED_VERSION_CPP).$(SHARED_EXT_CPP) $(LIBDIR)/$(CONFIG)/$(SHARED_PREFIX)grpc++_error_details$(SHARED_VERSION_CPP).$(SHARED_EXT_CPP) $(LIBDIR)/$(CONFIG)/$(SHARED_PREFIX)grpc++_reflection$(SHARED_VERSION_CPP).$(SHARED_EXT_CPP) $(LIBDIR)/$(CONFIG)/$(SHARED_PREFIX)grpc++_test$(SHARED_VERSION_CPP).$(SHARED_EXT_CPP) $(LIBDIR)/$(CONFIG)/$(SHARED_PREFIX)grpc++_unsecure$(SHARED_VERSION_CPP).$(SHARED_EXT_CPP) $(LIBDIR)/$(CONFIG)/$(SHARED_PREFIX)grpcpp_channelz$(SHARED_VERSION_CPP).$(SHARED_EXT_CPP) +shared_cxx: pc_cxx pc_cxx_unsecure cache.mk $(LIBDIR)/$(CONFIG)/$(SHARED_PREFIX)grpc++$(SHARED_VERSION_CPP).$(SHARED_EXT_CPP) $(LIBDIR)/$(CONFIG)/$(SHARED_PREFIX)grpc++_error_details$(SHARED_VERSION_CPP).$(SHARED_EXT_CPP) $(LIBDIR)/$(CONFIG)/$(SHARED_PREFIX)grpc++_reflection$(SHARED_VERSION_CPP).$(SHARED_EXT_CPP) $(LIBDIR)/$(CONFIG)/$(SHARED_PREFIX)grpc++_unsecure$(SHARED_VERSION_CPP).$(SHARED_EXT_CPP) $(LIBDIR)/$(CONFIG)/$(SHARED_PREFIX)grpcpp_channelz$(SHARED_VERSION_CPP).$(SHARED_EXT_CPP) shared_csharp: shared_c $(LIBDIR)/$(CONFIG)/$(SHARED_PREFIX)grpc_csharp_ext$(SHARED_VERSION_CSHARP).$(SHARED_EXT_CSHARP) grpc_csharp_ext: shared_csharp @@ -2581,8 +2581,6 @@ ifeq ($(CONFIG),opt) $(Q) $(STRIP) $(LIBDIR)/$(CONFIG)/libgrpc++_error_details.a $(E) "[STRIP] Stripping libgrpc++_reflection.a" $(Q) $(STRIP) $(LIBDIR)/$(CONFIG)/libgrpc++_reflection.a - $(E) "[STRIP] Stripping libgrpc++_test.a" - $(Q) $(STRIP) $(LIBDIR)/$(CONFIG)/libgrpc++_test.a $(E) "[STRIP] Stripping libgrpc++_unsecure.a" $(Q) $(STRIP) $(LIBDIR)/$(CONFIG)/libgrpc++_unsecure.a $(E) "[STRIP] Stripping libgrpcpp_channelz.a" @@ -2611,8 +2609,6 @@ ifeq ($(CONFIG),opt) $(Q) $(STRIP) $(LIBDIR)/$(CONFIG)/$(SHARED_PREFIX)grpc++_error_details$(SHARED_VERSION_CPP).$(SHARED_EXT_CPP) $(E) "[STRIP] Stripping $(SHARED_PREFIX)grpc++_reflection$(SHARED_VERSION_CPP).$(SHARED_EXT_CPP)" $(Q) $(STRIP) $(LIBDIR)/$(CONFIG)/$(SHARED_PREFIX)grpc++_reflection$(SHARED_VERSION_CPP).$(SHARED_EXT_CPP) - $(E) "[STRIP] Stripping $(SHARED_PREFIX)grpc++_test$(SHARED_VERSION_CPP).$(SHARED_EXT_CPP)" - $(Q) $(STRIP) $(LIBDIR)/$(CONFIG)/$(SHARED_PREFIX)grpc++_test$(SHARED_VERSION_CPP).$(SHARED_EXT_CPP) $(E) "[STRIP] Stripping $(SHARED_PREFIX)grpc++_unsecure$(SHARED_VERSION_CPP).$(SHARED_EXT_CPP)" $(Q) $(STRIP) $(LIBDIR)/$(CONFIG)/$(SHARED_PREFIX)grpc++_unsecure$(SHARED_VERSION_CPP).$(SHARED_EXT_CPP) $(E) "[STRIP] Stripping $(SHARED_PREFIX)grpcpp_channelz$(SHARED_VERSION_CPP).$(SHARED_EXT_CPP)" @@ -3139,9 +3135,6 @@ install-static_cxx: static_cxx strip-static_cxx install-pkg-config_cxx $(E) "[INSTALL] Installing libgrpc++_reflection.a" $(Q) $(INSTALL) -d $(prefix)/lib $(Q) $(INSTALL) $(LIBDIR)/$(CONFIG)/libgrpc++_reflection.a $(prefix)/lib/libgrpc++_reflection.a - $(E) "[INSTALL] Installing libgrpc++_test.a" - $(Q) $(INSTALL) -d $(prefix)/lib - $(Q) $(INSTALL) $(LIBDIR)/$(CONFIG)/libgrpc++_test.a $(prefix)/lib/libgrpc++_test.a $(E) "[INSTALL] Installing libgrpc++_unsecure.a" $(Q) $(INSTALL) -d $(prefix)/lib $(Q) $(INSTALL) $(LIBDIR)/$(CONFIG)/libgrpc++_unsecure.a $(prefix)/lib/libgrpc++_unsecure.a @@ -3231,15 +3224,6 @@ ifeq ($(SYSTEM),MINGW32) else ifneq ($(SYSTEM),Darwin) $(Q) ln -sf $(SHARED_PREFIX)grpc++_reflection$(SHARED_VERSION_CPP).$(SHARED_EXT_CPP) $(prefix)/lib/libgrpc++_reflection.so.1 $(Q) ln -sf $(SHARED_PREFIX)grpc++_reflection$(SHARED_VERSION_CPP).$(SHARED_EXT_CPP) $(prefix)/lib/libgrpc++_reflection.so -endif - $(E) "[INSTALL] Installing $(SHARED_PREFIX)grpc++_test$(SHARED_VERSION_CPP).$(SHARED_EXT_CPP)" - $(Q) $(INSTALL) -d $(prefix)/lib - $(Q) $(INSTALL) $(LIBDIR)/$(CONFIG)/$(SHARED_PREFIX)grpc++_test$(SHARED_VERSION_CPP).$(SHARED_EXT_CPP) $(prefix)/lib/$(SHARED_PREFIX)grpc++_test$(SHARED_VERSION_CPP).$(SHARED_EXT_CPP) -ifeq ($(SYSTEM),MINGW32) - $(Q) $(INSTALL) $(LIBDIR)/$(CONFIG)/libgrpc++_test$(SHARED_VERSION_CPP)-dll.a $(prefix)/lib/libgrpc++_test.a -else ifneq ($(SYSTEM),Darwin) - $(Q) ln -sf $(SHARED_PREFIX)grpc++_test$(SHARED_VERSION_CPP).$(SHARED_EXT_CPP) $(prefix)/lib/libgrpc++_test.so.1 - $(Q) ln -sf $(SHARED_PREFIX)grpc++_test$(SHARED_VERSION_CPP).$(SHARED_EXT_CPP) $(prefix)/lib/libgrpc++_test.so endif $(E) "[INSTALL] Installing $(SHARED_PREFIX)grpc++_unsecure$(SHARED_VERSION_CPP).$(SHARED_EXT_CPP)" $(Q) $(INSTALL) -d $(prefix)/lib @@ -6286,77 +6270,6 @@ $(OBJDIR)/$(CONFIG)/src/cpp/ext/proto_server_reflection.o: $(GENDIR)/src/proto/g $(OBJDIR)/$(CONFIG)/src/cpp/ext/proto_server_reflection_plugin.o: $(GENDIR)/src/proto/grpc/reflection/v1alpha/reflection.pb.cc $(GENDIR)/src/proto/grpc/reflection/v1alpha/reflection.grpc.pb.cc -LIBGRPC++_TEST_SRC = \ - -PUBLIC_HEADERS_CXX += \ - include/grpc++/test/mock_stream.h \ - include/grpc++/test/server_context_test_spouse.h \ - include/grpcpp/test/mock_stream.h \ - include/grpcpp/test/server_context_test_spouse.h \ - -LIBGRPC++_TEST_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(LIBGRPC++_TEST_SRC)))) - - -ifeq ($(NO_SECURE),true) - -# You can't build secure libraries if you don't have OpenSSL. - -$(LIBDIR)/$(CONFIG)/libgrpc++_test.a: openssl_dep_error - -$(LIBDIR)/$(CONFIG)/$(SHARED_PREFIX)grpc++_test$(SHARED_VERSION_CPP).$(SHARED_EXT_CPP): openssl_dep_error - -else - -ifeq ($(NO_PROTOBUF),true) - -# You can't build a C++ library if you don't have protobuf - a bit overreached, but still okay. - -$(LIBDIR)/$(CONFIG)/libgrpc++_test.a: protobuf_dep_error - -$(LIBDIR)/$(CONFIG)/$(SHARED_PREFIX)grpc++_test$(SHARED_VERSION_CPP).$(SHARED_EXT_CPP): protobuf_dep_error - -else - -$(LIBDIR)/$(CONFIG)/libgrpc++_test.a: $(ZLIB_DEP) $(OPENSSL_DEP) $(CARES_DEP) $(ADDRESS_SORTING_DEP) $(PROTOBUF_DEP) $(LIBGRPC++_TEST_OBJS) - $(E) "[AR] Creating $@" - $(Q) mkdir -p `dirname $@` - $(Q) rm -f $(LIBDIR)/$(CONFIG)/libgrpc++_test.a - $(Q) $(AR) $(AROPTS) $(LIBDIR)/$(CONFIG)/libgrpc++_test.a $(LIBGRPC++_TEST_OBJS) -ifeq ($(SYSTEM),Darwin) - $(Q) ranlib -no_warning_for_no_symbols $(LIBDIR)/$(CONFIG)/libgrpc++_test.a -endif - - - -ifeq ($(SYSTEM),MINGW32) -$(LIBDIR)/$(CONFIG)/grpc++_test$(SHARED_VERSION_CPP).$(SHARED_EXT_CPP): $(LIBGRPC++_TEST_OBJS) $(ZLIB_DEP) $(CARES_DEP) $(ADDRESS_SORTING_DEP) $(PROTOBUF_DEP) $(LIBDIR)/$(CONFIG)/grpc++$(SHARED_VERSION_CPP).$(SHARED_EXT_CPP) $(LIBDIR)/$(CONFIG)/grpc$(SHARED_VERSION_CORE).$(SHARED_EXT_CORE) $(OPENSSL_DEP) - $(E) "[LD] Linking $@" - $(Q) mkdir -p `dirname $@` - $(Q) $(LDXX) $(LDFLAGS) -L$(LIBDIR)/$(CONFIG) -shared -Wl,--output-def=$(LIBDIR)/$(CONFIG)/grpc++_test$(SHARED_VERSION_CPP).def -Wl,--out-implib=$(LIBDIR)/$(CONFIG)/libgrpc++_test$(SHARED_VERSION_CPP)-dll.a -o $(LIBDIR)/$(CONFIG)/grpc++_test$(SHARED_VERSION_CPP).$(SHARED_EXT_CPP) $(LIBGRPC++_TEST_OBJS) $(ZLIB_MERGE_LIBS) $(CARES_MERGE_LIBS) $(ADDRESS_SORTING_MERGE_LIBS) $(LDLIBSXX) $(LDLIBS_PROTOBUF) $(LDLIBS) -lgrpc++$(SHARED_VERSION_CPP)-dll -lgrpc$(SHARED_VERSION_CORE)-dll -else -$(LIBDIR)/$(CONFIG)/libgrpc++_test$(SHARED_VERSION_CPP).$(SHARED_EXT_CPP): $(LIBGRPC++_TEST_OBJS) $(ZLIB_DEP) $(CARES_DEP) $(ADDRESS_SORTING_DEP) $(PROTOBUF_DEP) $(LIBDIR)/$(CONFIG)/libgrpc++.$(SHARED_EXT_CPP) $(LIBDIR)/$(CONFIG)/libgrpc.$(SHARED_EXT_CORE) $(OPENSSL_DEP) - $(E) "[LD] Linking $@" - $(Q) mkdir -p `dirname $@` -ifeq ($(SYSTEM),Darwin) - $(Q) $(LDXX) $(LDFLAGS) -L$(LIBDIR)/$(CONFIG) -install_name $(SHARED_PREFIX)grpc++_test$(SHARED_VERSION_CPP).$(SHARED_EXT_CPP) -dynamiclib -o $(LIBDIR)/$(CONFIG)/libgrpc++_test$(SHARED_VERSION_CPP).$(SHARED_EXT_CPP) $(LIBGRPC++_TEST_OBJS) $(ZLIB_MERGE_LIBS) $(CARES_MERGE_LIBS) $(ADDRESS_SORTING_MERGE_LIBS) $(LDLIBSXX) $(LDLIBS_PROTOBUF) $(LDLIBS) -lgrpc++ -lgrpc -else - $(Q) $(LDXX) $(LDFLAGS) -L$(LIBDIR)/$(CONFIG) -shared -Wl,-soname,libgrpc++_test.so.1 -o $(LIBDIR)/$(CONFIG)/libgrpc++_test$(SHARED_VERSION_CPP).$(SHARED_EXT_CPP) $(LIBGRPC++_TEST_OBJS) $(ZLIB_MERGE_LIBS) $(CARES_MERGE_LIBS) $(ADDRESS_SORTING_MERGE_LIBS) $(LDLIBSXX) $(LDLIBS_PROTOBUF) $(LDLIBS) -lgrpc++ -lgrpc - $(Q) ln -sf $(SHARED_PREFIX)grpc++_test$(SHARED_VERSION_CPP).$(SHARED_EXT_CPP) $(LIBDIR)/$(CONFIG)/libgrpc++_test$(SHARED_VERSION_CPP).so.1 - $(Q) ln -sf $(SHARED_PREFIX)grpc++_test$(SHARED_VERSION_CPP).$(SHARED_EXT_CPP) $(LIBDIR)/$(CONFIG)/libgrpc++_test$(SHARED_VERSION_CPP).so -endif -endif - -endif - -endif - -ifneq ($(NO_SECURE),true) -ifneq ($(NO_DEPS),true) --include $(LIBGRPC++_TEST_OBJS:.o=.dep) -endif -endif - - LIBGRPC++_TEST_CONFIG_SRC = \ test/cpp/util/test_config_cc.cc \ diff --git a/build.yaml b/build.yaml index 78b3128753c..f37c59d7ccf 100644 --- a/build.yaml +++ b/build.yaml @@ -611,6 +611,15 @@ filegroups: - name: grpc++_reflection_proto src: - src/proto/grpc/reflection/v1alpha/reflection.proto +- name: grpc++_test + public_headers: + - include/grpc++/test/mock_stream.h + - include/grpc++/test/server_context_test_spouse.h + - include/grpcpp/test/mock_stream.h + - include/grpcpp/test/server_context_test_spouse.h + deps: + - grpc++ + - grpc - name: grpc_base src: - src/core/lib/avl/avl.cc @@ -1889,17 +1898,6 @@ libs: - grpc filegroups: - grpc++_reflection_proto -- name: grpc++_test - build: all - language: c++ - public_headers: - - include/grpc++/test/mock_stream.h - - include/grpc++/test/server_context_test_spouse.h - - include/grpcpp/test/mock_stream.h - - include/grpcpp/test/server_context_test_spouse.h - deps: - - grpc++ - - grpc - name: grpc++_test_config build: private language: c++ diff --git a/grpc.gyp b/grpc.gyp index 4cadd8e936d..4d08d766bc8 100644 --- a/grpc.gyp +++ b/grpc.gyp @@ -1642,16 +1642,6 @@ 'src/proto/grpc/reflection/v1alpha/reflection.proto', ], }, - { - 'target_name': 'grpc++_test', - 'type': 'static_library', - 'dependencies': [ - 'grpc++', - 'grpc', - ], - 'sources': [ - ], - }, { 'target_name': 'grpc++_test_config', 'type': 'static_library', From 782d9bfb349ac4f1be71b17e80b2c56723cfb284 Mon Sep 17 00:00:00 2001 From: Jan Tattermusch Date: Tue, 1 Oct 2019 08:24:10 -0400 Subject: [PATCH 40/60] add alpine distribtest --- .../csharp/run_distrib_test_dotnetcli.sh | 13 +++++---- .../distribtest/csharp_alpine_x64/Dockerfile | 28 +++++++++++++++++++ .../artifacts/distribtest_targets.py | 1 + 3 files changed, 37 insertions(+), 5 deletions(-) create mode 100644 tools/dockerfile/distribtest/csharp_alpine_x64/Dockerfile diff --git a/test/distrib/csharp/run_distrib_test_dotnetcli.sh b/test/distrib/csharp/run_distrib_test_dotnetcli.sh index ca22bce9d85..e326e3af553 100755 --- a/test/distrib/csharp/run_distrib_test_dotnetcli.sh +++ b/test/distrib/csharp/run_distrib_test_dotnetcli.sh @@ -33,11 +33,14 @@ dotnet publish -f net45 DistribTestDotNet.csproj ls -R bin -# .NET 4.5 target after dotnet build -mono bin/Debug/net45/publish/DistribTestDotNet.exe - -# .NET 4.5 target after dotnet publish -mono bin/Debug/net45/publish/DistribTestDotNet.exe +if [ "${SKIP_MONO_DISTRIBTEST}" != "1" ] +then + # .NET 4.5 target after dotnet build + mono bin/Debug/net45/publish/DistribTestDotNet.exe + + # .NET 4.5 target after dotnet publish + mono bin/Debug/net45/publish/DistribTestDotNet.exe +fi # .NET Core target after dotnet build dotnet exec bin/Debug/netcoreapp2.1/DistribTestDotNet.dll diff --git a/tools/dockerfile/distribtest/csharp_alpine_x64/Dockerfile b/tools/dockerfile/distribtest/csharp_alpine_x64/Dockerfile new file mode 100644 index 00000000000..2ee336d88fd --- /dev/null +++ b/tools/dockerfile/distribtest/csharp_alpine_x64/Dockerfile @@ -0,0 +1,28 @@ +# Copyright 2019 The gRPC Authors +# +# 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. + +FROM mcr.microsoft.com/dotnet/core/sdk:2.1-alpine3.9 + +RUN apk update && apk add bash +RUN apk update && apk add unzip + +# Workaround for https://github.com/grpc/grpc/issues/18428 +# Also see https://github.com/sgerrand/alpine-pkg-glibc +RUN apk update && apk --no-cache add ca-certificates wget +RUN wget -q -O /etc/apk/keys/sgerrand.rsa.pub https://alpine-pkgs.sgerrand.com/sgerrand.rsa.pub +RUN wget https://github.com/sgerrand/alpine-pkg-glibc/releases/download/2.30-r0/glibc-2.30-r0.apk +RUN apk add glibc-2.30-r0.apk + +# installing mono on alpine is hard and we don't really need it +ENV SKIP_MONO_DISTRIBTEST=1 diff --git a/tools/run_tests/artifacts/distribtest_targets.py b/tools/run_tests/artifacts/distribtest_targets.py index d65ce934a58..dfee23c4f2a 100644 --- a/tools/run_tests/artifacts/distribtest_targets.py +++ b/tools/run_tests/artifacts/distribtest_targets.py @@ -310,6 +310,7 @@ def targets(): CSharpDistribTest('linux', 'x64', 'centos7'), CSharpDistribTest('linux', 'x64', 'ubuntu1604'), CSharpDistribTest('linux', 'x64', 'ubuntu1604', use_dotnet_cli=True), + CSharpDistribTest('linux', 'x64', 'alpine', use_dotnet_cli=True), CSharpDistribTest('macos', 'x86'), CSharpDistribTest('windows', 'x86'), CSharpDistribTest('windows', 'x64'), From 92f7faff05fe5853626679bdac37882a8ffcefbb Mon Sep 17 00:00:00 2001 From: "Mark D. Roth" Date: Tue, 1 Oct 2019 08:02:48 -0700 Subject: [PATCH 41/60] Remove external watcher before sending notification to avoid race condition. --- src/core/ext/filters/client_channel/client_channel.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/core/ext/filters/client_channel/client_channel.cc b/src/core/ext/filters/client_channel/client_channel.cc index 5aed2e113e0..4768e46449e 100644 --- a/src/core/ext/filters/client_channel/client_channel.cc +++ b/src/core/ext/filters/client_channel/client_channel.cc @@ -1151,11 +1151,11 @@ void ChannelData::ExternalConnectivityWatcher::Notify( MemoryOrder::RELAXED)) { return; // Already done. } + // Remove external watcher. + chand_->RemoveExternalConnectivityWatcher(on_complete_, /*cancel=*/false); // Report new state to the user. *state_ = state; GRPC_CLOSURE_SCHED(on_complete_, GRPC_ERROR_NONE); - // Remove external watcher. - chand_->RemoveExternalConnectivityWatcher(on_complete_, /*cancel=*/false); // Hop back into the combiner to clean up. // Not needed in state SHUTDOWN, because the tracker will // automatically remove all watchers in that case. From 5e9404e41a06d102b41483f5523fcd8faa3e8e84 Mon Sep 17 00:00:00 2001 From: "Mark D. Roth" Date: Tue, 1 Oct 2019 09:34:05 -0700 Subject: [PATCH 42/60] Fix polymorphism for UniquePtr<> and OrphanablePtr<>. --- .../filters/client_channel/client_channel.cc | 9 ++--- .../client_channel/http_connect_handshaker.cc | 2 +- .../client_channel/lb_policy/grpclb/grpclb.cc | 10 +++--- .../lb_policy/pick_first/pick_first.cc | 31 ++++++++--------- .../lb_policy/round_robin/round_robin.cc | 17 +++++----- .../client_channel/lb_policy/xds/xds.cc | 18 +++++----- .../resolver/dns/c_ares/dns_resolver_ares.cc | 5 ++- .../dns/c_ares/grpc_ares_ev_driver_libuv.cc | 2 +- .../dns/c_ares/grpc_ares_ev_driver_posix.cc | 2 +- .../dns/c_ares/grpc_ares_ev_driver_windows.cc | 3 +- .../resolver/dns/native/dns_resolver.cc | 8 ++--- .../resolver/fake/fake_resolver.cc | 5 ++- .../resolver/sockaddr/sockaddr_resolver.cc | 13 +++----- .../resolver/xds/xds_resolver.cc | 5 ++- .../client_channel/resolver_result_parsing.cc | 17 ++++------ .../client_channel/resolving_lb_policy.cc | 9 +++-- .../ext/filters/client_channel/subchannel.cc | 3 +- .../message_size/message_size_filter.cc | 8 ++--- src/core/lib/gprpp/memory.h | 33 ++++++++----------- src/core/lib/gprpp/orphanable.h | 8 +++-- .../security/transport/security_handshaker.cc | 4 +-- .../session_cache/ssl_session_boringssl.cc | 3 +- .../ssl/session_cache/ssl_session_openssl.cc | 3 +- .../resolvers/dns_resolver_test.cc | 10 ++---- .../resolvers/sockaddr_resolver_test.cc | 8 ++--- .../client_channel/service_config_test.cc | 29 +++++++--------- .../readahead_handshaker_server_ssl.cc | 2 +- test/core/surface/lame_client_test.cc | 4 +-- .../core/transport/connectivity_state_test.cc | 12 +++---- test/core/util/test_lb_policies.cc | 5 ++- 30 files changed, 115 insertions(+), 173 deletions(-) diff --git a/src/core/ext/filters/client_channel/client_channel.cc b/src/core/ext/filters/client_channel/client_channel.cc index 4768e46449e..af2425a6faa 100644 --- a/src/core/ext/filters/client_channel/client_channel.cc +++ b/src/core/ext/filters/client_channel/client_channel.cc @@ -1515,9 +1515,7 @@ void ChannelData::CreateResolvingLoadBalancingPolicyLocked() { // Instantiate resolving LB policy. LoadBalancingPolicy::Args lb_args; lb_args.combiner = combiner_; - lb_args.channel_control_helper = - UniquePtr( - New(this)); + lb_args.channel_control_helper = MakeUnique(this); lb_args.args = channel_args_; UniquePtr target_uri(gpr_strdup(target_uri_.get())); resolving_lb_policy_.reset(New( @@ -1791,9 +1789,8 @@ void ChannelData::StartTransportOpLocked(void* arg, grpc_error* ignored) { MemoryOrder::RELEASE); chand->UpdateStateAndPickerLocked( GRPC_CHANNEL_SHUTDOWN, "shutdown from API", - UniquePtr( - New( - GRPC_ERROR_REF(op->disconnect_with_error)))); + MakeUnique( + GRPC_ERROR_REF(op->disconnect_with_error))); } } GRPC_CHANNEL_STACK_UNREF(chand->owning_stack_, "start_transport_op"); diff --git a/src/core/ext/filters/client_channel/http_connect_handshaker.cc b/src/core/ext/filters/client_channel/http_connect_handshaker.cc index 95366b57386..660f6b85c00 100644 --- a/src/core/ext/filters/client_channel/http_connect_handshaker.cc +++ b/src/core/ext/filters/client_channel/http_connect_handshaker.cc @@ -356,5 +356,5 @@ void grpc_http_connect_register_handshaker_factory() { using namespace grpc_core; HandshakerRegistry::RegisterHandshakerFactory( true /* at_start */, HANDSHAKER_CLIENT, - UniquePtr(New())); + MakeUnique()); } diff --git a/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc b/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc index af7632c1728..20c6c1af601 100644 --- a/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc +++ b/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc @@ -716,9 +716,8 @@ void GrpcLb::Helper::UpdateState(grpc_connectivity_state state, client_stats = parent_->lb_calld_->client_stats()->Ref(); } parent_->channel_control_helper()->UpdateState( - state, UniquePtr( - New(parent_.get(), parent_->serverlist_, - std::move(picker), std::move(client_stats)))); + state, MakeUnique(parent_.get(), parent_->serverlist_, + std::move(picker), std::move(client_stats))); } void GrpcLb::Helper::RequestReresolution() { @@ -1794,7 +1793,7 @@ class GrpcLbFactory : public LoadBalancingPolicyFactory { public: OrphanablePtr CreateLoadBalancingPolicy( LoadBalancingPolicy::Args args) const override { - return OrphanablePtr(New(std::move(args))); + return MakeOrphanable(std::move(args)); } const char* name() const override { return kGrpclb; } @@ -1869,8 +1868,7 @@ bool maybe_add_client_load_reporting_filter(grpc_channel_stack_builder* builder, void grpc_lb_policy_grpclb_init() { grpc_core::LoadBalancingPolicyRegistry::Builder:: RegisterLoadBalancingPolicyFactory( - grpc_core::UniquePtr( - grpc_core::New())); + grpc_core::MakeUnique()); grpc_channel_init_register_stage(GRPC_CLIENT_SUBCHANNEL, GRPC_CHANNEL_INIT_BUILTIN_PRIORITY, maybe_add_client_load_reporting_filter, diff --git a/src/core/ext/filters/client_channel/lb_policy/pick_first/pick_first.cc b/src/core/ext/filters/client_channel/lb_policy/pick_first/pick_first.cc index 000462092ac..1b14f96748c 100644 --- a/src/core/ext/filters/client_channel/lb_policy/pick_first/pick_first.cc +++ b/src/core/ext/filters/client_channel/lb_policy/pick_first/pick_first.cc @@ -201,7 +201,7 @@ void PickFirst::AttemptToConnectUsingLatestUpdateArgsLocked() { GRPC_ERROR_INT_GRPC_STATUS, GRPC_STATUS_UNAVAILABLE); channel_control_helper()->UpdateState( GRPC_CHANNEL_TRANSIENT_FAILURE, - UniquePtr(New(error))); + MakeUnique(error)); return; } // If one of the subchannels in the new list is already in state @@ -319,12 +319,11 @@ void PickFirst::PickFirstSubchannelData::ProcessConnectivityChangeLocked( GRPC_ERROR_INT_GRPC_STATUS, GRPC_STATUS_UNAVAILABLE); p->channel_control_helper()->UpdateState( GRPC_CHANNEL_TRANSIENT_FAILURE, - UniquePtr(New(error))); + MakeUnique(error)); } else { p->channel_control_helper()->UpdateState( GRPC_CHANNEL_CONNECTING, - UniquePtr( - New(p->Ref(DEBUG_LOCATION, "QueuePicker")))); + MakeUnique(p->Ref(DEBUG_LOCATION, "QueuePicker"))); } } else { if (connectivity_state == GRPC_CHANNEL_TRANSIENT_FAILURE) { @@ -339,20 +338,19 @@ void PickFirst::PickFirstSubchannelData::ProcessConnectivityChangeLocked( p->selected_ = nullptr; p->subchannel_list_.reset(); p->channel_control_helper()->UpdateState( - GRPC_CHANNEL_IDLE, UniquePtr(New( - p->Ref(DEBUG_LOCATION, "QueuePicker")))); + GRPC_CHANNEL_IDLE, + MakeUnique(p->Ref(DEBUG_LOCATION, "QueuePicker"))); } else { // This is unlikely but can happen when a subchannel has been asked // to reconnect by a different channel and this channel has dropped // some connectivity state notifications. if (connectivity_state == GRPC_CHANNEL_READY) { p->channel_control_helper()->UpdateState( - GRPC_CHANNEL_READY, - UniquePtr(New(subchannel()->Ref()))); + GRPC_CHANNEL_READY, MakeUnique(subchannel()->Ref())); } else { // CONNECTING p->channel_control_helper()->UpdateState( - connectivity_state, UniquePtr(New( - p->Ref(DEBUG_LOCATION, "QueuePicker")))); + connectivity_state, + MakeUnique(p->Ref(DEBUG_LOCATION, "QueuePicker"))); } } } @@ -396,7 +394,7 @@ void PickFirst::PickFirstSubchannelData::ProcessConnectivityChangeLocked( GRPC_ERROR_INT_GRPC_STATUS, GRPC_STATUS_UNAVAILABLE); p->channel_control_helper()->UpdateState( GRPC_CHANNEL_TRANSIENT_FAILURE, - UniquePtr(New(error))); + MakeUnique(error)); } } sd->CheckConnectivityStateAndStartWatchingLocked(); @@ -408,8 +406,7 @@ void PickFirst::PickFirstSubchannelData::ProcessConnectivityChangeLocked( if (subchannel_list() == p->subchannel_list_.get()) { p->channel_control_helper()->UpdateState( GRPC_CHANNEL_CONNECTING, - UniquePtr( - New(p->Ref(DEBUG_LOCATION, "QueuePicker")))); + MakeUnique(p->Ref(DEBUG_LOCATION, "QueuePicker"))); } break; } @@ -448,8 +445,7 @@ void PickFirst::PickFirstSubchannelData::ProcessUnselectedReadyLocked() { } p->selected_ = this; p->channel_control_helper()->UpdateState( - GRPC_CHANNEL_READY, - UniquePtr(New(subchannel()->Ref()))); + GRPC_CHANNEL_READY, MakeUnique(subchannel()->Ref())); for (size_t i = 0; i < subchannel_list()->num_subchannels(); ++i) { if (i != Index()) { subchannel_list()->subchannel(i)->ShutdownLocked(); @@ -488,7 +484,7 @@ class PickFirstFactory : public LoadBalancingPolicyFactory { public: OrphanablePtr CreateLoadBalancingPolicy( LoadBalancingPolicy::Args args) const override { - return OrphanablePtr(New(std::move(args))); + return MakeOrphanable(std::move(args)); } const char* name() const override { return kPickFirst; } @@ -510,8 +506,7 @@ class PickFirstFactory : public LoadBalancingPolicyFactory { void grpc_lb_policy_pick_first_init() { grpc_core::LoadBalancingPolicyRegistry::Builder:: RegisterLoadBalancingPolicyFactory( - grpc_core::UniquePtr( - grpc_core::New())); + grpc_core::MakeUnique()); } void grpc_lb_policy_pick_first_shutdown() {} diff --git a/src/core/ext/filters/client_channel/lb_policy/round_robin/round_robin.cc b/src/core/ext/filters/client_channel/lb_policy/round_robin/round_robin.cc index 69b3d6746e0..66fa66f4eff 100644 --- a/src/core/ext/filters/client_channel/lb_policy/round_robin/round_robin.cc +++ b/src/core/ext/filters/client_channel/lb_policy/round_robin/round_robin.cc @@ -321,13 +321,13 @@ void RoundRobin::RoundRobinSubchannelList:: */ if (num_ready_ > 0) { /* 1) READY */ - p->channel_control_helper()->UpdateState( - GRPC_CHANNEL_READY, UniquePtr(New(p, this))); + p->channel_control_helper()->UpdateState(GRPC_CHANNEL_READY, + MakeUnique(p, this)); } else if (num_connecting_ > 0) { /* 2) CONNECTING */ p->channel_control_helper()->UpdateState( - GRPC_CHANNEL_CONNECTING, UniquePtr(New( - p->Ref(DEBUG_LOCATION, "QueuePicker")))); + GRPC_CHANNEL_CONNECTING, + MakeUnique(p->Ref(DEBUG_LOCATION, "QueuePicker"))); } else if (num_transient_failure_ == num_subchannels()) { /* 3) TRANSIENT_FAILURE */ grpc_error* error = @@ -336,7 +336,7 @@ void RoundRobin::RoundRobinSubchannelList:: GRPC_ERROR_INT_GRPC_STATUS, GRPC_STATUS_UNAVAILABLE); p->channel_control_helper()->UpdateState( GRPC_CHANNEL_TRANSIENT_FAILURE, - UniquePtr(New(error))); + MakeUnique(error)); } } @@ -453,7 +453,7 @@ void RoundRobin::UpdateLocked(UpdateArgs args) { GRPC_ERROR_INT_GRPC_STATUS, GRPC_STATUS_UNAVAILABLE); channel_control_helper()->UpdateState( GRPC_CHANNEL_TRANSIENT_FAILURE, - UniquePtr(New(error))); + MakeUnique(error)); subchannel_list_ = std::move(latest_pending_subchannel_list_); } else if (subchannel_list_ == nullptr) { // If there is no current list, immediately promote the new list to @@ -480,7 +480,7 @@ class RoundRobinFactory : public LoadBalancingPolicyFactory { public: OrphanablePtr CreateLoadBalancingPolicy( LoadBalancingPolicy::Args args) const override { - return OrphanablePtr(New(std::move(args))); + return MakeOrphanable(std::move(args)); } const char* name() const override { return kRoundRobin; } @@ -502,8 +502,7 @@ class RoundRobinFactory : public LoadBalancingPolicyFactory { void grpc_lb_policy_round_robin_init() { grpc_core::LoadBalancingPolicyRegistry::Builder:: RegisterLoadBalancingPolicyFactory( - grpc_core::UniquePtr( - grpc_core::New())); + grpc_core::MakeUnique()); } void grpc_lb_policy_round_robin_shutdown() {} diff --git a/src/core/ext/filters/client_channel/lb_policy/xds/xds.cc b/src/core/ext/filters/client_channel/lb_policy/xds/xds.cc index c5b9b3dc437..c148023bf5b 100644 --- a/src/core/ext/filters/client_channel/lb_policy/xds/xds.cc +++ b/src/core/ext/filters/client_channel/lb_policy/xds/xds.cc @@ -2179,7 +2179,7 @@ void XdsLb::PriorityList::UpdateXdsPickerLocked() { GRPC_ERROR_INT_GRPC_STATUS, GRPC_STATUS_UNAVAILABLE); xds_policy_->channel_control_helper()->UpdateState( GRPC_CHANNEL_TRANSIENT_FAILURE, - UniquePtr(New(error))); + MakeUnique(error)); return; } priorities_[current_priority_]->UpdateXdsPickerLocked(); @@ -2272,9 +2272,8 @@ XdsLb::PriorityList::LocalityMap::LocalityMap(RefCountedPtr xds_policy, // This is the first locality map ever created, report CONNECTING. if (priority_ == 0) { xds_policy_->channel_control_helper()->UpdateState( - GRPC_CHANNEL_CONNECTING, - UniquePtr( - New(xds_policy_->Ref(DEBUG_LOCATION, "QueuePicker")))); + GRPC_CHANNEL_CONNECTING, MakeUnique(xds_policy_->Ref( + DEBUG_LOCATION, "QueuePicker"))); } } @@ -2347,9 +2346,9 @@ void XdsLb::PriorityList::LocalityMap::UpdateXdsPickerLocked() { picker_list.push_back(MakePair(end, locality->picker_wrapper())); } xds_policy()->channel_control_helper()->UpdateState( - GRPC_CHANNEL_READY, UniquePtr(New( - xds_policy_->Ref(DEBUG_LOCATION, "XdsLb+Picker"), - std::move(picker_list)))); + GRPC_CHANNEL_READY, + MakeUnique(xds_policy_->Ref(DEBUG_LOCATION, "XdsLb+Picker"), + std::move(picker_list))); } OrphanablePtr @@ -2898,7 +2897,7 @@ class XdsFactory : public LoadBalancingPolicyFactory { public: OrphanablePtr CreateLoadBalancingPolicy( LoadBalancingPolicy::Args args) const override { - return OrphanablePtr(New(std::move(args))); + return MakeOrphanable(std::move(args)); } const char* name() const override { return kXds; } @@ -2982,8 +2981,7 @@ class XdsFactory : public LoadBalancingPolicyFactory { void grpc_lb_policy_xds_init() { grpc_core::LoadBalancingPolicyRegistry::Builder:: RegisterLoadBalancingPolicyFactory( - grpc_core::UniquePtr( - grpc_core::New())); + grpc_core::MakeUnique()); } void grpc_lb_policy_xds_shutdown() {} diff --git a/src/core/ext/filters/client_channel/resolver/dns/c_ares/dns_resolver_ares.cc b/src/core/ext/filters/client_channel/resolver/dns/c_ares/dns_resolver_ares.cc index 65f80525e54..8924fdf4172 100644 --- a/src/core/ext/filters/client_channel/resolver/dns/c_ares/dns_resolver_ares.cc +++ b/src/core/ext/filters/client_channel/resolver/dns/c_ares/dns_resolver_ares.cc @@ -436,7 +436,7 @@ class AresDnsResolverFactory : public ResolverFactory { bool IsValidUri(const grpc_uri* uri) const override { return true; } OrphanablePtr CreateResolver(ResolverArgs args) const override { - return OrphanablePtr(New(std::move(args))); + return MakeOrphanable(std::move(args)); } const char* scheme() const override { return "dns"; } @@ -494,8 +494,7 @@ void grpc_resolver_dns_ares_init() { } grpc_set_resolver_impl(&ares_resolver); grpc_core::ResolverRegistry::Builder::RegisterResolverFactory( - grpc_core::UniquePtr( - grpc_core::New())); + grpc_core::MakeUnique()); } else { g_use_ares_dns_resolver = false; } diff --git a/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_libuv.cc b/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_libuv.cc index 04e36fbcee7..81d2f7becd4 100644 --- a/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_libuv.cc +++ b/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_libuv.cc @@ -171,7 +171,7 @@ class GrpcPolledFdFactoryLibuv : public GrpcPolledFdFactory { }; UniquePtr NewGrpcPolledFdFactory(grpc_combiner* combiner) { - return UniquePtr(New()); + return MakeUnique(); } } // namespace grpc_core diff --git a/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_posix.cc b/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_posix.cc index aa58e1aaf50..f167047ebc9 100644 --- a/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_posix.cc +++ b/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_posix.cc @@ -98,7 +98,7 @@ class GrpcPolledFdFactoryPosix : public GrpcPolledFdFactory { }; UniquePtr NewGrpcPolledFdFactory(grpc_combiner* combiner) { - return UniquePtr(New()); + return MakeUnique(); } } // namespace grpc_core diff --git a/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_windows.cc b/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_windows.cc index d72c453d748..bc79b7c3648 100644 --- a/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_windows.cc +++ b/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_windows.cc @@ -904,8 +904,7 @@ class GrpcPolledFdFactoryWindows : public GrpcPolledFdFactory { }; UniquePtr NewGrpcPolledFdFactory(grpc_combiner* combiner) { - return UniquePtr( - New(combiner)); + return MakeUnique(combiner); } } // namespace grpc_core diff --git a/src/core/ext/filters/client_channel/resolver/dns/native/dns_resolver.cc b/src/core/ext/filters/client_channel/resolver/dns/native/dns_resolver.cc index 629b7360a88..5f674992e64 100644 --- a/src/core/ext/filters/client_channel/resolver/dns/native/dns_resolver.cc +++ b/src/core/ext/filters/client_channel/resolver/dns/native/dns_resolver.cc @@ -268,7 +268,7 @@ class NativeDnsResolverFactory : public ResolverFactory { OrphanablePtr CreateResolver(ResolverArgs args) const override { if (!IsValidUri(args.uri)) return nullptr; - return OrphanablePtr(New(std::move(args))); + return MakeOrphanable(std::move(args)); } const char* scheme() const override { return "dns"; } @@ -284,8 +284,7 @@ void grpc_resolver_dns_native_init() { if (gpr_stricmp(resolver.get(), "native") == 0) { gpr_log(GPR_DEBUG, "Using native dns resolver"); grpc_core::ResolverRegistry::Builder::RegisterResolverFactory( - grpc_core::UniquePtr( - grpc_core::New())); + grpc_core::MakeUnique()); } else { grpc_core::ResolverRegistry::Builder::InitRegistry(); grpc_core::ResolverFactory* existing_factory = @@ -293,8 +292,7 @@ void grpc_resolver_dns_native_init() { if (existing_factory == nullptr) { gpr_log(GPR_DEBUG, "Using native dns resolver"); grpc_core::ResolverRegistry::Builder::RegisterResolverFactory( - grpc_core::UniquePtr( - grpc_core::New())); + grpc_core::MakeUnique()); } } } diff --git a/src/core/ext/filters/client_channel/resolver/fake/fake_resolver.cc b/src/core/ext/filters/client_channel/resolver/fake/fake_resolver.cc index 443a709ea6c..98beef37de3 100644 --- a/src/core/ext/filters/client_channel/resolver/fake/fake_resolver.cc +++ b/src/core/ext/filters/client_channel/resolver/fake/fake_resolver.cc @@ -382,7 +382,7 @@ class FakeResolverFactory : public ResolverFactory { bool IsValidUri(const grpc_uri* uri) const override { return true; } OrphanablePtr CreateResolver(ResolverArgs args) const override { - return OrphanablePtr(New(std::move(args))); + return MakeOrphanable(std::move(args)); } const char* scheme() const override { return "fake"; } @@ -394,8 +394,7 @@ class FakeResolverFactory : public ResolverFactory { void grpc_resolver_fake_init() { grpc_core::ResolverRegistry::Builder::RegisterResolverFactory( - grpc_core::UniquePtr( - grpc_core::New())); + grpc_core::MakeUnique()); } void grpc_resolver_fake_shutdown() {} diff --git a/src/core/ext/filters/client_channel/resolver/sockaddr/sockaddr_resolver.cc b/src/core/ext/filters/client_channel/resolver/sockaddr/sockaddr_resolver.cc index 532fd6df9b7..ece5ffe86d4 100644 --- a/src/core/ext/filters/client_channel/resolver/sockaddr/sockaddr_resolver.cc +++ b/src/core/ext/filters/client_channel/resolver/sockaddr/sockaddr_resolver.cc @@ -119,8 +119,8 @@ OrphanablePtr CreateSockaddrResolver( ServerAddressList addresses; if (!ParseUri(args.uri, parse, &addresses)) return nullptr; // Instantiate resolver. - return OrphanablePtr( - New(std::move(addresses), std::move(args))); + return MakeOrphanable(std::move(addresses), + std::move(args)); } class IPv4ResolverFactory : public ResolverFactory { @@ -174,15 +174,12 @@ class UnixResolverFactory : public ResolverFactory { void grpc_resolver_sockaddr_init() { grpc_core::ResolverRegistry::Builder::RegisterResolverFactory( - grpc_core::UniquePtr( - grpc_core::New())); + grpc_core::MakeUnique()); grpc_core::ResolverRegistry::Builder::RegisterResolverFactory( - grpc_core::UniquePtr( - grpc_core::New())); + grpc_core::MakeUnique()); #ifdef GRPC_HAVE_UNIX_SOCKET grpc_core::ResolverRegistry::Builder::RegisterResolverFactory( - grpc_core::UniquePtr( - grpc_core::New())); + grpc_core::MakeUnique()); #endif } diff --git a/src/core/ext/filters/client_channel/resolver/xds/xds_resolver.cc b/src/core/ext/filters/client_channel/resolver/xds/xds_resolver.cc index 8be1b89eee0..eac64b44a98 100644 --- a/src/core/ext/filters/client_channel/resolver/xds/xds_resolver.cc +++ b/src/core/ext/filters/client_channel/resolver/xds/xds_resolver.cc @@ -70,7 +70,7 @@ class XdsResolverFactory : public ResolverFactory { OrphanablePtr CreateResolver(ResolverArgs args) const override { if (!IsValidUri(args.uri)) return nullptr; - return OrphanablePtr(New(std::move(args))); + return MakeOrphanable(std::move(args)); } const char* scheme() const override { return "xds-experimental"; } @@ -82,8 +82,7 @@ class XdsResolverFactory : public ResolverFactory { void grpc_resolver_xds_init() { grpc_core::ResolverRegistry::Builder::RegisterResolverFactory( - grpc_core::UniquePtr( - grpc_core::New())); + grpc_core::MakeUnique()); } void grpc_resolver_xds_shutdown() {} diff --git a/src/core/ext/filters/client_channel/resolver_result_parsing.cc b/src/core/ext/filters/client_channel/resolver_result_parsing.cc index 3a1960bfded..221e0f4feb3 100644 --- a/src/core/ext/filters/client_channel/resolver_result_parsing.cc +++ b/src/core/ext/filters/client_channel/resolver_result_parsing.cc @@ -53,9 +53,8 @@ size_t ClientChannelServiceConfigParser::ParserIndex() { } void ClientChannelServiceConfigParser::Register() { - g_client_channel_service_config_parser_index = - ServiceConfig::RegisterParser(UniquePtr( - New())); + g_client_channel_service_config_parser_index = ServiceConfig::RegisterParser( + MakeUnique()); } namespace { @@ -439,10 +438,9 @@ ClientChannelServiceConfigParser::ParseGlobalParams(const grpc_json* json, *error = GRPC_ERROR_CREATE_FROM_VECTOR("Client channel global parser", &error_list); if (*error == GRPC_ERROR_NONE) { - return UniquePtr( - New( - std::move(parsed_lb_config), std::move(lb_policy_name), - retry_throttling, health_check_service_name)); + return MakeUnique( + std::move(parsed_lb_config), std::move(lb_policy_name), + retry_throttling, health_check_service_name); } return nullptr; } @@ -493,9 +491,8 @@ ClientChannelServiceConfigParser::ParsePerMethodParams(const grpc_json* json, } *error = GRPC_ERROR_CREATE_FROM_VECTOR("Client channel parser", &error_list); if (*error == GRPC_ERROR_NONE) { - return UniquePtr( - New(timeout, wait_for_ready, - std::move(retry_policy))); + return MakeUnique(timeout, wait_for_ready, + std::move(retry_policy)); } return nullptr; } diff --git a/src/core/ext/filters/client_channel/resolving_lb_policy.cc b/src/core/ext/filters/client_channel/resolving_lb_policy.cc index d997e26f979..a2b946bb5c6 100644 --- a/src/core/ext/filters/client_channel/resolving_lb_policy.cc +++ b/src/core/ext/filters/client_channel/resolving_lb_policy.cc @@ -187,16 +187,15 @@ ResolvingLoadBalancingPolicy::ResolvingLoadBalancingPolicy( GPR_ASSERT(process_resolver_result != nullptr); resolver_ = ResolverRegistry::CreateResolver( target_uri_.get(), args.args, interested_parties(), combiner(), - UniquePtr(New(Ref()))); + MakeUnique(Ref())); // Since the validity of args has been checked when create the channel, // CreateResolver() must return a non-null result. GPR_ASSERT(resolver_ != nullptr); if (GRPC_TRACE_FLAG_ENABLED(*tracer_)) { gpr_log(GPR_INFO, "resolving_lb=%p: starting name resolution", this); } - channel_control_helper()->UpdateState( - GRPC_CHANNEL_CONNECTING, - UniquePtr(New(Ref()))); + channel_control_helper()->UpdateState(GRPC_CHANNEL_CONNECTING, + MakeUnique(Ref())); resolver_->StartLocked(); } @@ -262,7 +261,7 @@ void ResolvingLoadBalancingPolicy::OnResolverError(grpc_error* error) { "Resolver transient failure", &error, 1); channel_control_helper()->UpdateState( GRPC_CHANNEL_TRANSIENT_FAILURE, - UniquePtr(New(state_error))); + MakeUnique(state_error)); } GRPC_ERROR_UNREF(error); } diff --git a/src/core/ext/filters/client_channel/subchannel.cc b/src/core/ext/filters/client_channel/subchannel.cc index 2c3f899d2a7..df8473d160a 100644 --- a/src/core/ext/filters/client_channel/subchannel.cc +++ b/src/core/ext/filters/client_channel/subchannel.cc @@ -1071,8 +1071,7 @@ bool Subchannel::PublishTransportLocked() { } // Start watching connected subchannel. connected_subchannel_->StartWatch( - pollset_set_, OrphanablePtr( - New(this))); + pollset_set_, MakeOrphanable(this)); // Report initial state. SetConnectivityStateLocked(GRPC_CHANNEL_READY); return true; diff --git a/src/core/ext/filters/message_size/message_size_filter.cc b/src/core/ext/filters/message_size/message_size_filter.cc index df447c226b1..7e6c71de77e 100644 --- a/src/core/ext/filters/message_size/message_size_filter.cc +++ b/src/core/ext/filters/message_size/message_size_filter.cc @@ -88,13 +88,13 @@ UniquePtr MessageSizeParser::ParsePerMethodParams( *error = GRPC_ERROR_CREATE_FROM_VECTOR("Message size parser", &error_list); return nullptr; } - return UniquePtr(New( - max_request_message_bytes, max_response_message_bytes)); + return MakeUnique(max_request_message_bytes, + max_response_message_bytes); } void MessageSizeParser::Register() { - g_message_size_parser_index = ServiceConfig::RegisterParser( - UniquePtr(New())); + g_message_size_parser_index = + ServiceConfig::RegisterParser(MakeUnique()); } size_t MessageSizeParser::ParserIndex() { return g_message_size_parser_index; } diff --git a/src/core/lib/gprpp/memory.h b/src/core/lib/gprpp/memory.h index be158d118a1..53b89507c6f 100644 --- a/src/core/lib/gprpp/memory.h +++ b/src/core/lib/gprpp/memory.h @@ -33,10 +33,8 @@ // Should not be used in new code. // TODO(juanlishen): Remove this macro, and instead comment that the public dtor // should not be used directly. -#define GRPC_ALLOW_CLASS_TO_USE_NON_PUBLIC_DELETE \ - template \ - friend void ::grpc_core::Delete(_Delete_T*); \ - template \ +#define GRPC_ALLOW_CLASS_TO_USE_NON_PUBLIC_DELETE \ + template \ friend void ::grpc_core::Delete(_Delete_T*); // Add this to a class that want to use New(), but has a private or @@ -58,33 +56,28 @@ inline T* New(Args&&... args) { } // Alternative to delete, since we cannot use it (for fear of libstdc++) -// We cannot add a default value for can_be_null, because they are used as -// as friend template methods where we cannot define a default value. -// Instead we simply define two variants, one with and one without the boolean -// argument. -template +template inline void Delete(T* p) { - GPR_DEBUG_ASSERT(can_be_null || p != nullptr); - if (can_be_null && p == nullptr) return; + if (p == nullptr) return; p->~T(); gpr_free(p); } -template -inline void Delete(T* p) { - Delete(p); -} -template class DefaultDelete { public: + template void operator()(T* p) { - // std::unique_ptr is gauranteed not to call the deleter - // if the pointer is nullptr. - Delete(p); + // Delete() checks whether the value is null, but std::unique_ptr<> is + // gauranteed not to call the deleter if the pointer is nullptr + // (i.e., it already does this check for us), and we don't want to + // do the check twice. So, instead of calling Delete() here, we + // manually call the object's dtor and free it. + p->~T(); + gpr_free(p); } }; -template > +template using UniquePtr = std::unique_ptr; template diff --git a/src/core/lib/gprpp/orphanable.h b/src/core/lib/gprpp/orphanable.h index 82350a19a2c..ab02d80827b 100644 --- a/src/core/lib/gprpp/orphanable.h +++ b/src/core/lib/gprpp/orphanable.h @@ -59,13 +59,15 @@ class Orphanable { virtual ~Orphanable() {} }; -template class OrphanableDelete { public: - void operator()(T* p) { p->Orphan(); } + template + void operator()(T* p) { + p->Orphan(); + } }; -template > +template using OrphanablePtr = std::unique_ptr; template diff --git a/src/core/lib/security/transport/security_handshaker.cc b/src/core/lib/security/transport/security_handshaker.cc index 1d0b5ec0c6e..0128a344e1f 100644 --- a/src/core/lib/security/transport/security_handshaker.cc +++ b/src/core/lib/security/transport/security_handshaker.cc @@ -515,10 +515,10 @@ RefCountedPtr SecurityHandshakerCreate( void SecurityRegisterHandshakerFactories() { HandshakerRegistry::RegisterHandshakerFactory( false /* at_start */, HANDSHAKER_CLIENT, - UniquePtr(New())); + MakeUnique()); HandshakerRegistry::RegisterHandshakerFactory( false /* at_start */, HANDSHAKER_SERVER, - UniquePtr(New())); + MakeUnique()); } } // namespace grpc_core diff --git a/src/core/tsi/ssl/session_cache/ssl_session_boringssl.cc b/src/core/tsi/ssl/session_cache/ssl_session_boringssl.cc index 0da5a96164e..a3ba5fedee9 100644 --- a/src/core/tsi/ssl/session_cache/ssl_session_boringssl.cc +++ b/src/core/tsi/ssl/session_cache/ssl_session_boringssl.cc @@ -49,8 +49,7 @@ class BoringSslCachedSession : public SslCachedSession { grpc_core::UniquePtr SslCachedSession::Create( SslSessionPtr session) { - return grpc_core::UniquePtr( - grpc_core::New(std::move(session))); + return grpc_core::MakeUnique(std::move(session)); } } // namespace tsi diff --git a/src/core/tsi/ssl/session_cache/ssl_session_openssl.cc b/src/core/tsi/ssl/session_cache/ssl_session_openssl.cc index 61c036c7eb5..b03d005574e 100644 --- a/src/core/tsi/ssl/session_cache/ssl_session_openssl.cc +++ b/src/core/tsi/ssl/session_cache/ssl_session_openssl.cc @@ -67,8 +67,7 @@ class OpenSslCachedSession : public SslCachedSession { grpc_core::UniquePtr SslCachedSession::Create( SslSessionPtr session) { - return grpc_core::UniquePtr( - grpc_core::New(std::move(session))); + return grpc_core::MakeUnique(std::move(session)); } } // namespace tsi diff --git a/test/core/client_channel/resolvers/dns_resolver_test.cc b/test/core/client_channel/resolvers/dns_resolver_test.cc index ce44fd51b82..d03782ef159 100644 --- a/test/core/client_channel/resolvers/dns_resolver_test.cc +++ b/test/core/client_channel/resolvers/dns_resolver_test.cc @@ -35,12 +35,6 @@ class TestResultHandler : public grpc_core::Resolver::ResultHandler { void ReturnError(grpc_error* error) override {} }; -static grpc_core::UniquePtr -create_test_result_handler() { - return grpc_core::UniquePtr( - grpc_core::New()); -} - static void test_succeeds(grpc_core::ResolverFactory* factory, const char* string) { gpr_log(GPR_DEBUG, "test: '%s' should be valid for '%s'", string, @@ -51,7 +45,7 @@ static void test_succeeds(grpc_core::ResolverFactory* factory, grpc_core::ResolverArgs args; args.uri = uri; args.combiner = g_combiner; - args.result_handler = create_test_result_handler(); + args.result_handler = grpc_core::MakeUnique(); grpc_core::OrphanablePtr resolver = factory->CreateResolver(std::move(args)); GPR_ASSERT(resolver != nullptr); @@ -68,7 +62,7 @@ static void test_fails(grpc_core::ResolverFactory* factory, grpc_core::ResolverArgs args; args.uri = uri; args.combiner = g_combiner; - args.result_handler = create_test_result_handler(); + args.result_handler = grpc_core::MakeUnique(); grpc_core::OrphanablePtr resolver = factory->CreateResolver(std::move(args)); GPR_ASSERT(resolver == nullptr); diff --git a/test/core/client_channel/resolvers/sockaddr_resolver_test.cc b/test/core/client_channel/resolvers/sockaddr_resolver_test.cc index ac3d31b8ff8..8cbacaca999 100644 --- a/test/core/client_channel/resolvers/sockaddr_resolver_test.cc +++ b/test/core/client_channel/resolvers/sockaddr_resolver_test.cc @@ -47,9 +47,7 @@ static void test_succeeds(grpc_core::ResolverFactory* factory, grpc_core::ResolverArgs args; args.uri = uri; args.combiner = g_combiner; - args.result_handler = - grpc_core::UniquePtr( - grpc_core::New()); + args.result_handler = grpc_core::MakeUnique(); grpc_core::OrphanablePtr resolver = factory->CreateResolver(std::move(args)); GPR_ASSERT(resolver != nullptr); @@ -70,9 +68,7 @@ static void test_fails(grpc_core::ResolverFactory* factory, grpc_core::ResolverArgs args; args.uri = uri; args.combiner = g_combiner; - args.result_handler = - grpc_core::UniquePtr( - grpc_core::New()); + args.result_handler = grpc_core::MakeUnique(); grpc_core::OrphanablePtr resolver = factory->CreateResolver(std::move(args)); GPR_ASSERT(resolver == nullptr); diff --git a/test/core/client_channel/service_config_test.cc b/test/core/client_channel/service_config_test.cc index b1fe6453d62..491b43dfb50 100644 --- a/test/core/client_channel/service_config_test.cc +++ b/test/core/client_channel/service_config_test.cc @@ -60,8 +60,7 @@ class TestParser1 : public ServiceConfig::Parser { GRPC_ERROR_CREATE_FROM_STATIC_STRING(InvalidValueErrorMessage()); return nullptr; } - return UniquePtr( - New(value)); + return MakeUnique(value); } } return nullptr; @@ -98,8 +97,7 @@ class TestParser2 : public ServiceConfig::Parser { GRPC_ERROR_CREATE_FROM_STATIC_STRING(InvalidValueErrorMessage()); return nullptr; } - return UniquePtr( - New(value)); + return MakeUnique(value); } } return nullptr; @@ -148,10 +146,8 @@ class ServiceConfigTest : public ::testing::Test { void SetUp() override { ServiceConfig::Shutdown(); ServiceConfig::Init(); - EXPECT_TRUE(ServiceConfig::RegisterParser( - UniquePtr(New())) == 0); - EXPECT_TRUE(ServiceConfig::RegisterParser( - UniquePtr(New())) == 1); + EXPECT_TRUE(ServiceConfig::RegisterParser(MakeUnique()) == 0); + EXPECT_TRUE(ServiceConfig::RegisterParser(MakeUnique()) == 1); } }; @@ -312,10 +308,8 @@ class ErroredParsersScopingTest : public ::testing::Test { void SetUp() override { ServiceConfig::Shutdown(); ServiceConfig::Init(); - EXPECT_TRUE(ServiceConfig::RegisterParser( - UniquePtr(New())) == 0); - EXPECT_TRUE(ServiceConfig::RegisterParser( - UniquePtr(New())) == 1); + EXPECT_TRUE(ServiceConfig::RegisterParser(MakeUnique()) == 0); + EXPECT_TRUE(ServiceConfig::RegisterParser(MakeUnique()) == 1); } }; @@ -359,10 +353,9 @@ class ClientChannelParserTest : public ::testing::Test { void SetUp() override { ServiceConfig::Shutdown(); ServiceConfig::Init(); - EXPECT_TRUE( - ServiceConfig::RegisterParser(UniquePtr( - New())) == - 0); + EXPECT_TRUE(ServiceConfig::RegisterParser( + MakeUnique()) == + 0); } }; @@ -929,8 +922,8 @@ class MessageSizeParserTest : public ::testing::Test { void SetUp() override { ServiceConfig::Shutdown(); ServiceConfig::Init(); - EXPECT_TRUE(ServiceConfig::RegisterParser(UniquePtr( - New())) == 0); + EXPECT_TRUE( + ServiceConfig::RegisterParser(MakeUnique()) == 0); } }; diff --git a/test/core/handshake/readahead_handshaker_server_ssl.cc b/test/core/handshake/readahead_handshaker_server_ssl.cc index c0ab61136cb..36d489cc815 100644 --- a/test/core/handshake/readahead_handshaker_server_ssl.cc +++ b/test/core/handshake/readahead_handshaker_server_ssl.cc @@ -81,7 +81,7 @@ int main(int argc, char* argv[]) { grpc_init(); HandshakerRegistry::RegisterHandshakerFactory( true /* at_start */, HANDSHAKER_SERVER, - UniquePtr(New())); + MakeUnique()); const char* full_alpn_list[] = {"grpc-exp", "h2"}; GPR_ASSERT(server_ssl_test(full_alpn_list, 2, "grpc-exp")); grpc_shutdown_blocking(); diff --git a/test/core/surface/lame_client_test.cc b/test/core/surface/lame_client_test.cc index 34cafbbd5b7..dc961b5b458 100644 --- a/test/core/surface/lame_client_test.cc +++ b/test/core/surface/lame_client_test.cc @@ -44,9 +44,7 @@ static void do_nothing(void* arg, grpc_error* error) {} void test_transport_op(grpc_channel* channel) { grpc_core::ExecCtx exec_ctx; grpc_transport_op* op = grpc_make_transport_op(nullptr); - op->start_connectivity_watch = - grpc_core::OrphanablePtr( - grpc_core::New()); + op->start_connectivity_watch = grpc_core::MakeOrphanable(); grpc_channel_element* elem = grpc_channel_stack_element(grpc_channel_get_channel_stack(channel), 0); elem->filter->start_transport_op(elem, op); diff --git a/test/core/transport/connectivity_state_test.cc b/test/core/transport/connectivity_state_test.cc index 6493a62ff3c..5a82bb5979a 100644 --- a/test/core/transport/connectivity_state_test.cc +++ b/test/core/transport/connectivity_state_test.cc @@ -73,8 +73,7 @@ TEST(StateTracker, NotificationUponAddingWatcher) { grpc_connectivity_state state = GRPC_CHANNEL_IDLE; ConnectivityStateTracker tracker("xxx", GRPC_CHANNEL_CONNECTING); tracker.AddWatcher(GRPC_CHANNEL_IDLE, - OrphanablePtr( - New(&count, &state))); + MakeOrphanable(&count, &state)); EXPECT_EQ(count, 1); EXPECT_EQ(state, GRPC_CHANNEL_CONNECTING); } @@ -84,8 +83,7 @@ TEST(StateTracker, NotificationUponStateChange) { grpc_connectivity_state state = GRPC_CHANNEL_IDLE; ConnectivityStateTracker tracker("xxx", GRPC_CHANNEL_IDLE); tracker.AddWatcher(GRPC_CHANNEL_IDLE, - OrphanablePtr( - New(&count, &state))); + MakeOrphanable(&count, &state)); EXPECT_EQ(count, 0); EXPECT_EQ(state, GRPC_CHANNEL_IDLE); tracker.SetState(GRPC_CHANNEL_CONNECTING, "whee"); @@ -153,8 +151,7 @@ TEST(StateTracker, NotifyShutdownAtDestruction) { { ConnectivityStateTracker tracker("xxx", GRPC_CHANNEL_IDLE); tracker.AddWatcher(GRPC_CHANNEL_IDLE, - OrphanablePtr( - New(&count, &state))); + MakeOrphanable(&count, &state)); // No initial notification, since we started the watch from the // current state. EXPECT_EQ(count, 0); @@ -171,8 +168,7 @@ TEST(StateTracker, DoNotNotifyShutdownAtDestructionIfAlreadyInShutdown) { { ConnectivityStateTracker tracker("xxx", GRPC_CHANNEL_SHUTDOWN); tracker.AddWatcher(GRPC_CHANNEL_SHUTDOWN, - OrphanablePtr( - New(&count, &state))); + MakeOrphanable(&count, &state)); // No initial notification, since we started the watch from the // current state. EXPECT_EQ(count, 0); diff --git a/test/core/util/test_lb_policies.cc b/test/core/util/test_lb_policies.cc index d4ce3a27e50..8330c47ac46 100644 --- a/test/core/util/test_lb_policies.cc +++ b/test/core/util/test_lb_policies.cc @@ -219,9 +219,8 @@ class InterceptTrailingFactory : public LoadBalancingPolicyFactory { OrphanablePtr CreateLoadBalancingPolicy( LoadBalancingPolicy::Args args) const override { - return OrphanablePtr( - New(std::move(args), - cb_, user_data_)); + return MakeOrphanable( + std::move(args), cb_, user_data_); } const char* name() const override { From 07109f07e21ea7aa4e008677ed58556851cb0366 Mon Sep 17 00:00:00 2001 From: Richard Belleville Date: Tue, 1 Oct 2019 11:23:20 -0700 Subject: [PATCH 43/60] Fix grpc_testing context.abort --- .../grpc_testing/_server/_servicer_context.py | 1 + .../tests/testing/_application_common.py | 5 +++++ .../tests/testing/_server_application.py | 18 ++++++++++++++++++ .../grpcio_tests/tests/testing/_server_test.py | 13 +++++++++++++ 4 files changed, 37 insertions(+) diff --git a/src/python/grpcio_testing/grpc_testing/_server/_servicer_context.py b/src/python/grpcio_testing/grpc_testing/_server/_servicer_context.py index 6fa8c6b3ba8..c63750f9785 100644 --- a/src/python/grpcio_testing/grpc_testing/_server/_servicer_context.py +++ b/src/python/grpcio_testing/grpc_testing/_server/_servicer_context.py @@ -76,6 +76,7 @@ class ServicerContext(grpc.ServicerContext): def abort(self, code, details): with self._rpc._condition: self._rpc._abort(code, details) + raise Exception() def abort_with_status(self, status): raise NotImplementedError() diff --git a/src/python/grpcio_tests/tests/testing/_application_common.py b/src/python/grpcio_tests/tests/testing/_application_common.py index 4e98879607a..b7d5b236051 100644 --- a/src/python/grpcio_tests/tests/testing/_application_common.py +++ b/src/python/grpcio_tests/tests/testing/_application_common.py @@ -32,5 +32,10 @@ STREAM_UNARY_RESPONSE = services_pb2.Strange(first_strange_field=17) STREAM_STREAM_REQUEST = requests_pb2.Top(first_top_field=19) STREAM_STREAM_RESPONSE = services_pb2.Bottom(first_bottom_field=23) TWO_STREAM_STREAM_RESPONSES = (STREAM_STREAM_RESPONSE,) * 2 +ABORT_REQUEST = requests_pb2.Up(first_up_field=42) +ABORT_SUCCESS_QUERY = requests_pb2.Up(first_up_field=43) +ABORT_NO_STATUS_RESPONSE = services_pb2.Down(first_down_field=50) +ABORT_SUCCESS_RESPONSE = services_pb2.Down(first_down_field=51) +ABORT_FAILURE_RESPONSE = services_pb2.Down(first_down_field=52) INFINITE_REQUEST_STREAM_TIMEOUT = 0.2 diff --git a/src/python/grpcio_tests/tests/testing/_server_application.py b/src/python/grpcio_tests/tests/testing/_server_application.py index 243c385dafd..8126bfaca70 100644 --- a/src/python/grpcio_tests/tests/testing/_server_application.py +++ b/src/python/grpcio_tests/tests/testing/_server_application.py @@ -15,6 +15,8 @@ import grpc +import threading + # requests_pb2 is a semantic dependency of this module. from tests.testing import _application_common from tests.testing.proto import requests_pb2 # pylint: disable=unused-import @@ -25,9 +27,25 @@ from tests.testing.proto import services_pb2_grpc class FirstServiceServicer(services_pb2_grpc.FirstServiceServicer): """Services RPCs.""" + def __init__(self): + self._abort_lock = threading.RLock() + self._abort_response = _application_common.ABORT_NO_STATUS_RESPONSE + def UnUn(self, request, context): if _application_common.UNARY_UNARY_REQUEST == request: return _application_common.UNARY_UNARY_RESPONSE + elif request == _application_common.ABORT_REQUEST: + with self._abort_lock: + try: + context.abort(grpc.StatusCode.PERMISSION_DENIED, + "Denying permission to test abort.") + except Exception as e: + self._abort_response = _application_common.ABORT_SUCCESS_RESPONSE + else: + self._abort_status = _application_common.ABORT_FAILURE_RESPONSE + elif request == _application_common.ABORT_SUCCESS_QUERY: + with self._abort_lock: + return self._abort_response else: context.set_code(grpc.StatusCode.INVALID_ARGUMENT) context.set_details('Something is wrong with your request!') diff --git a/src/python/grpcio_tests/tests/testing/_server_test.py b/src/python/grpcio_tests/tests/testing/_server_test.py index 88e3a79ae59..902e8952aff 100644 --- a/src/python/grpcio_tests/tests/testing/_server_test.py +++ b/src/python/grpcio_tests/tests/testing/_server_test.py @@ -164,6 +164,19 @@ class FirstServiceServicerTest(unittest.TestCase): self.assertIs(code, grpc.StatusCode.DEADLINE_EXCEEDED) + def test_servicer_context_abort(self): + rpc = self._real_time_server.invoke_unary_unary( + _application_testing_common.FIRST_SERVICE_UNUN, (), + _application_common.ABORT_REQUEST, None) + response, trailing_metadata, code, details = rpc.termination() + self.assertIs(code, grpc.StatusCode.PERMISSION_DENIED) + rpc = self._real_time_server.invoke_unary_unary( + _application_testing_common.FIRST_SERVICE_UNUN, (), + _application_common.ABORT_SUCCESS_QUERY, None) + response, trailing_metadata, code, details = rpc.termination() + self.assertEqual(_application_common.ABORT_SUCCESS_RESPONSE, response) + self.assertIs(code, grpc.StatusCode.OK) + if __name__ == '__main__': unittest.main(verbosity=2) From 92c61e131ed16c73ceeb4cd5d4a59ff230570bd9 Mon Sep 17 00:00:00 2001 From: Richard Belleville Date: Tue, 1 Oct 2019 12:06:00 -0700 Subject: [PATCH 44/60] Spruce up styling --- src/python/grpcio_tests/tests/testing/_server_application.py | 2 +- src/python/grpcio_tests/tests/testing/_server_test.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/python/grpcio_tests/tests/testing/_server_application.py b/src/python/grpcio_tests/tests/testing/_server_application.py index 8126bfaca70..2f9a75b1eb6 100644 --- a/src/python/grpcio_tests/tests/testing/_server_application.py +++ b/src/python/grpcio_tests/tests/testing/_server_application.py @@ -32,7 +32,7 @@ class FirstServiceServicer(services_pb2_grpc.FirstServiceServicer): self._abort_response = _application_common.ABORT_NO_STATUS_RESPONSE def UnUn(self, request, context): - if _application_common.UNARY_UNARY_REQUEST == request: + if request == _application_common.UNARY_UNARY_REQUEST: return _application_common.UNARY_UNARY_RESPONSE elif request == _application_common.ABORT_REQUEST: with self._abort_lock: diff --git a/src/python/grpcio_tests/tests/testing/_server_test.py b/src/python/grpcio_tests/tests/testing/_server_test.py index 902e8952aff..45975f229bc 100644 --- a/src/python/grpcio_tests/tests/testing/_server_test.py +++ b/src/python/grpcio_tests/tests/testing/_server_test.py @@ -168,12 +168,12 @@ class FirstServiceServicerTest(unittest.TestCase): rpc = self._real_time_server.invoke_unary_unary( _application_testing_common.FIRST_SERVICE_UNUN, (), _application_common.ABORT_REQUEST, None) - response, trailing_metadata, code, details = rpc.termination() + _, _, code, _ = rpc.termination() self.assertIs(code, grpc.StatusCode.PERMISSION_DENIED) rpc = self._real_time_server.invoke_unary_unary( _application_testing_common.FIRST_SERVICE_UNUN, (), _application_common.ABORT_SUCCESS_QUERY, None) - response, trailing_metadata, code, details = rpc.termination() + response, _, code, _ = rpc.termination() self.assertEqual(_application_common.ABORT_SUCCESS_RESPONSE, response) self.assertIs(code, grpc.StatusCode.OK) From 1c16b8c470054cdbee47dd289d9dc1376d62588b Mon Sep 17 00:00:00 2001 From: Richard Belleville Date: Tue, 1 Oct 2019 13:14:08 -0700 Subject: [PATCH 45/60] Bow to the linter --- src/python/grpcio_tests/tests/testing/_server_application.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/python/grpcio_tests/tests/testing/_server_application.py b/src/python/grpcio_tests/tests/testing/_server_application.py index 2f9a75b1eb6..1dc5e8f3917 100644 --- a/src/python/grpcio_tests/tests/testing/_server_application.py +++ b/src/python/grpcio_tests/tests/testing/_server_application.py @@ -39,10 +39,11 @@ class FirstServiceServicer(services_pb2_grpc.FirstServiceServicer): try: context.abort(grpc.StatusCode.PERMISSION_DENIED, "Denying permission to test abort.") - except Exception as e: + except Exception as e: # pylint: disable=broad-except self._abort_response = _application_common.ABORT_SUCCESS_RESPONSE else: self._abort_status = _application_common.ABORT_FAILURE_RESPONSE + return None # NOTE: For the linter. elif request == _application_common.ABORT_SUCCESS_QUERY: with self._abort_lock: return self._abort_response From f47d14160ab06b114ec35015dd56e43acf6989a6 Mon Sep 17 00:00:00 2001 From: Stanley Cheung Date: Mon, 30 Sep 2019 14:23:44 -0700 Subject: [PATCH 46/60] PHP: add various scenarios to test PECL extension --- examples/php/echo/README.md | 86 +++++++++++++++ examples/php/echo/apache.Dockerfile | 49 +++++++++ examples/php/echo/base.Dockerfile | 38 +++++++ examples/php/echo/cli.Dockerfile | 52 +++++++++ examples/php/echo/client.php | 45 ++++++++ examples/php/echo/composer.json | 12 +++ examples/php/echo/echo.proto | 100 ++++++++++++++++++ examples/php/echo/fpm.Dockerfile | 49 +++++++++ examples/php/echo/nginx.conf | 23 ++++ src/php/bin/build_all_docker_images.sh | 40 +++++++ src/php/bin/run_all_docker_images.sh | 40 +++++++ src/php/docker/README.md | 96 +++++++++++++++++ src/php/docker/alpine/Dockerfile | 38 +++++++ src/php/docker/fork-support/Dockerfile | 27 +++++ src/php/docker/fork-support/fork.php | 35 ++++++ src/php/docker/grpc-ext/Dockerfile | 40 +++++++ src/php/docker/grpc-src/Dockerfile | 48 +++++++++ src/php/docker/php-future/Dockerfile | 40 +++++++ src/php/docker/php-src/Dockerfile | 62 +++++++++++ src/php/docker/php-zts/Dockerfile | 40 +++++++ src/php/docker/php5/Dockerfile | 40 +++++++ .../php/echo/apache.Dockerfile.template | 41 +++++++ .../php/echo/base.Dockerfile.template | 40 +++++++ .../examples/php/echo/cli.Dockerfile.template | 44 ++++++++ .../php/echo/copy_from_grpc_base.include | 10 ++ .../examples/php/echo/fpm.Dockerfile.template | 41 +++++++ .../src/php/docker/alpine/Dockerfile.template | 28 +++++ .../src/php/docker/download_phpunit.include | 3 + .../php/docker/grpc-ext/Dockerfile.template | 30 ++++++ .../php/docker/grpc-src/Dockerfile.template | 47 ++++++++ .../src/php/docker/pecl_ext_build_src.include | 9 ++ .../php/docker/php-future/Dockerfile.template | 30 ++++++ .../php/docker/php-src/Dockerfile.template | 52 +++++++++ .../php/docker/php-zts/Dockerfile.template | 30 ++++++ .../src/php/docker/php5/Dockerfile.template | 30 ++++++ tools/buildgen/plugins/expand_version.py | 6 ++ 36 files changed, 1441 insertions(+) create mode 100644 examples/php/echo/README.md create mode 100644 examples/php/echo/apache.Dockerfile create mode 100644 examples/php/echo/base.Dockerfile create mode 100644 examples/php/echo/cli.Dockerfile create mode 100644 examples/php/echo/client.php create mode 100644 examples/php/echo/composer.json create mode 100644 examples/php/echo/echo.proto create mode 100644 examples/php/echo/fpm.Dockerfile create mode 100644 examples/php/echo/nginx.conf create mode 100755 src/php/bin/build_all_docker_images.sh create mode 100755 src/php/bin/run_all_docker_images.sh create mode 100644 src/php/docker/README.md create mode 100644 src/php/docker/alpine/Dockerfile create mode 100644 src/php/docker/fork-support/Dockerfile create mode 100644 src/php/docker/fork-support/fork.php create mode 100644 src/php/docker/grpc-ext/Dockerfile create mode 100644 src/php/docker/grpc-src/Dockerfile create mode 100644 src/php/docker/php-future/Dockerfile create mode 100644 src/php/docker/php-src/Dockerfile create mode 100644 src/php/docker/php-zts/Dockerfile create mode 100644 src/php/docker/php5/Dockerfile create mode 100644 templates/examples/php/echo/apache.Dockerfile.template create mode 100644 templates/examples/php/echo/base.Dockerfile.template create mode 100644 templates/examples/php/echo/cli.Dockerfile.template create mode 100644 templates/examples/php/echo/copy_from_grpc_base.include create mode 100644 templates/examples/php/echo/fpm.Dockerfile.template create mode 100644 templates/src/php/docker/alpine/Dockerfile.template create mode 100644 templates/src/php/docker/download_phpunit.include create mode 100644 templates/src/php/docker/grpc-ext/Dockerfile.template create mode 100644 templates/src/php/docker/grpc-src/Dockerfile.template create mode 100644 templates/src/php/docker/pecl_ext_build_src.include create mode 100644 templates/src/php/docker/php-future/Dockerfile.template create mode 100644 templates/src/php/docker/php-src/Dockerfile.template create mode 100644 templates/src/php/docker/php-zts/Dockerfile.template create mode 100644 templates/src/php/docker/php5/Dockerfile.template diff --git a/examples/php/echo/README.md b/examples/php/echo/README.md new file mode 100644 index 00000000000..c34ea468784 --- /dev/null +++ b/examples/php/echo/README.md @@ -0,0 +1,86 @@ + +# gRPC PHP End-to-End Examples + +This page shows a number of ways to create a PHP gRPC client and connect with +a gRPC backend service. + + +## Run the Server + +For all the following examples, we use a simple gRPC server, written in Node. + +```sh +$ git clone https://github.com/grpc/grpc-web +$ cd grpc-web +$ docker-compose build common node-server +$ docker run -d -p 9090:9090 --name node-server grpcweb/node-server +``` + + +## Install the gRPC PECL extension + +All the following commands are assumed to be run from this current directory. + +```sh +$ cd grpc/examples/php/echo +``` + + +In order to build a PHP gRPC client, we need to install the `grpc` extension +first. + +```sh +$ docker build -t grpc-php/base -f ./base.Dockerfile . +``` + + +## CLI + + +Let's first build a simple CLI gRPC client: + +```sh +$ docker build -t grpc-php/echo-client -f ./cli.Dockerfile . +$ docker run -it --rm --link node-server:node-server grpc-php/echo-client +$ php client.php +``` + + + +## Apache + + +Now let's see how the gRPC PHP client can run with Apache: + +```sh +$ docker build -t grpc-php/apache -f ./apache.Dockerfile . +$ docker run -it --rm --link node-server:node-server -p 80:80 grpc-php/apache +``` + +Open the browser to `http://localhost`. + + + +## Nginx + FPM + + +We can also try running PHP-FPM and put Nginx in front of it. + + +The PHP-FPM part: + +```sh +$ docker build -t grpc-php/fpm -f ./fpm.Dockerfile . +$ docker run -it --rm --link node-server:node-server -p 9000:9000 \ + --name fpm grpc-php/fpm +``` + +The Nginx part: + +```sh +$ docker run -it --rm -v $(pwd)/nginx.conf:/etc/nginx/conf.d/default.conf:ro \ + --link fpm:fpm -p 80:80 nginx:1.17.4 +``` + + +Open the browser to `http://localhost`. diff --git a/examples/php/echo/apache.Dockerfile b/examples/php/echo/apache.Dockerfile new file mode 100644 index 00000000000..bc910d45d0c --- /dev/null +++ b/examples/php/echo/apache.Dockerfile @@ -0,0 +1,49 @@ +# Copyright 2019 gRPC authors. +# +# 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. + +FROM composer:1.8.6 as composer + + +FROM grpc-php/base as grpc-base + + +FROM php:7.2-apache-stretch + +RUN apt-get -qq update && apt-get -qq install -y git + + +COPY --from=composer /usr/bin/composer /usr/bin/composer + +COPY --from=grpc-base /usr/local/bin/protoc /usr/local/bin/protoc + +COPY --from=grpc-base /github/grpc/bins/opt/grpc_php_plugin \ + /usr/local/bin/protoc-gen-grpc + +COPY --from=grpc-base \ + /usr/local/lib/php/extensions/no-debug-non-zts-20170718/grpc.so \ + /usr/local/lib/php/extensions/no-debug-non-zts-20170718/grpc.so + + +RUN docker-php-ext-enable grpc + + +WORKDIR /var/www/html + +COPY client.php ./index.php +COPY composer.json . +COPY echo.proto . + +RUN protoc -I=. echo.proto --php_out=. --grpc_out=. + +RUN composer install diff --git a/examples/php/echo/base.Dockerfile b/examples/php/echo/base.Dockerfile new file mode 100644 index 00000000000..2ca37c7bda1 --- /dev/null +++ b/examples/php/echo/base.Dockerfile @@ -0,0 +1,38 @@ +# Copyright 2019 gRPC authors. +# +# 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. + +FROM php:7.2-stretch + +RUN apt-get -qq update && apt-get -qq install -y \ + autoconf automake curl git libtool \ + pkg-config unzip zlib1g-dev + + +WORKDIR /tmp + +RUN curl -sSL https://github.com/protocolbuffers/protobuf/releases/download/v3.8.0/\ +protoc-3.8.0-linux-x86_64.zip -o /tmp/protoc.zip && \ + unzip -qq protoc.zip && \ + cp /tmp/bin/protoc /usr/local/bin/protoc + + +WORKDIR /github/grpc + +RUN git clone https://github.com/grpc/grpc . && \ + git submodule update --init && \ + cd third_party/protobuf && git submodule update --init + +RUN make grpc_php_plugin + +RUN pecl install grpc diff --git a/examples/php/echo/cli.Dockerfile b/examples/php/echo/cli.Dockerfile new file mode 100644 index 00000000000..ef3d3b3a8d8 --- /dev/null +++ b/examples/php/echo/cli.Dockerfile @@ -0,0 +1,52 @@ +# Copyright 2019 gRPC authors. +# +# 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. + +FROM composer:1.8.6 as composer + + +FROM grpc-php/base as grpc-base + + +FROM php:7.2-stretch + +RUN apt-get -qq update && apt-get -qq install -y git + + +COPY --from=composer /usr/bin/composer /usr/bin/composer + +COPY --from=grpc-base /usr/local/bin/protoc /usr/local/bin/protoc + +COPY --from=grpc-base /github/grpc/bins/opt/grpc_php_plugin \ + /usr/local/bin/protoc-gen-grpc + +COPY --from=grpc-base \ + /usr/local/lib/php/extensions/no-debug-non-zts-20170718/grpc.so \ + /usr/local/lib/php/extensions/no-debug-non-zts-20170718/grpc.so + + +RUN docker-php-ext-enable grpc + + +WORKDIR /github/grpc-php/examples/echo + +COPY client.php . +COPY composer.json . +COPY echo.proto . + +RUN protoc -I=. echo.proto --php_out=. --grpc_out=. + +RUN composer install + + +CMD ["/bin/bash"] diff --git a/examples/php/echo/client.php b/examples/php/echo/client.php new file mode 100644 index 00000000000..b4829928716 --- /dev/null +++ b/examples/php/echo/client.php @@ -0,0 +1,45 @@ + Grpc\ChannelCredentials::createInsecure(), +]); + + +// unary call +$request = new Grpc\Gateway\Testing\EchoRequest(); +$request->setMessage("Hello World!"); + +list($response, $status) = $client->Echo($request)->wait(); + +echo $response->getMessage()."\n"; + + +// server streaming call +$stream_request = new Grpc\Gateway\Testing\ServerStreamingEchoRequest(); +$stream_request->setMessage("stream message"); +$stream_request->setMessageCount(5); + +$responses = $client->ServerStreamingEcho($stream_request)->responses(); + +foreach ($responses as $response) { + echo $response->getMessage()."\n"; +} diff --git a/examples/php/echo/composer.json b/examples/php/echo/composer.json new file mode 100644 index 00000000000..c74e5527389 --- /dev/null +++ b/examples/php/echo/composer.json @@ -0,0 +1,12 @@ +{ + "name": "grpc-php/echo-example", + "require": { + "grpc/grpc": "^v1.22.0", + "google/protobuf": "^3.7.0" + }, + "autoload": { + "psr-4": { + "": "./" + } + } +} diff --git a/examples/php/echo/echo.proto b/examples/php/echo/echo.proto new file mode 100644 index 00000000000..7823f54cf0a --- /dev/null +++ b/examples/php/echo/echo.proto @@ -0,0 +1,100 @@ +// Copyright 2019 gRPC authors. +// +// 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. + +syntax = "proto3"; + +package grpc.gateway.testing; + +message Empty {} + +message EchoRequest { + string message = 1; +} + +message EchoResponse { + string message = 1; + int32 message_count = 2; +} + +// Request type for server side streaming echo. +message ServerStreamingEchoRequest { + // Message string for server streaming request. + string message = 1; + + // The total number of messages to be generated before the server + // closes the stream; default is 10. + int32 message_count = 2; + + // The interval (ms) between two server messages. The server implementation + // may enforce some minimum interval (e.g. 100ms) to avoid message overflow. + int32 message_interval = 3; +} + +// Response type for server streaming response. +message ServerStreamingEchoResponse { + // Response message. + string message = 1; +} + +// Request type for client side streaming echo. +message ClientStreamingEchoRequest { + // A special value "" indicates that there's no further messages. + string message = 1; +} + +// Response type for client side streaming echo. +message ClientStreamingEchoResponse { + // Total number of client messages that have been received. + int32 message_count = 1; +} + +// A simple echo service. +service EchoService { + // One request followed by one response + // The server returns the client message as-is. + rpc Echo(EchoRequest) returns (EchoResponse); + + // Sends back abort status. + rpc EchoAbort(EchoRequest) returns (EchoResponse) {} + + // One empty request, ZERO processing, followed by one empty response + // (minimum effort to do message serialization). + rpc NoOp(Empty) returns (Empty); + + // One request followed by a sequence of responses (streamed download). + // The server will return the same client message repeatedly. + rpc ServerStreamingEcho(ServerStreamingEchoRequest) + returns (stream ServerStreamingEchoResponse); + + // One request followed by a sequence of responses (streamed download). + // The server abort directly. + rpc ServerStreamingEchoAbort(ServerStreamingEchoRequest) + returns (stream ServerStreamingEchoResponse) {} + + // A sequence of requests followed by one response (streamed upload). + // The server returns the total number of messages as the result. + rpc ClientStreamingEcho(stream ClientStreamingEchoRequest) + returns (ClientStreamingEchoResponse); + + // A sequence of requests with each message echoed by the server immediately. + // The server returns the same client messages in order. + // E.g. this is how the speech API works. + rpc FullDuplexEcho(stream EchoRequest) returns (stream EchoResponse); + + // A sequence of requests followed by a sequence of responses. + // The server buffers all the client messages and then returns the same + // client messages one by one after the client half-closes the stream. + // This is how an image recognition API may work. + rpc HalfDuplexEcho(stream EchoRequest) returns (stream EchoResponse); +} diff --git a/examples/php/echo/fpm.Dockerfile b/examples/php/echo/fpm.Dockerfile new file mode 100644 index 00000000000..f6924eadb86 --- /dev/null +++ b/examples/php/echo/fpm.Dockerfile @@ -0,0 +1,49 @@ +# Copyright 2019 gRPC authors. +# +# 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. + +FROM composer:1.8.6 as composer + + +FROM grpc-php/base as grpc-base + + +FROM php:7.2-fpm-stretch + +RUN apt-get -qq update && apt-get -qq install -y git + + +COPY --from=composer /usr/bin/composer /usr/bin/composer + +COPY --from=grpc-base /usr/local/bin/protoc /usr/local/bin/protoc + +COPY --from=grpc-base /github/grpc/bins/opt/grpc_php_plugin \ + /usr/local/bin/protoc-gen-grpc + +COPY --from=grpc-base \ + /usr/local/lib/php/extensions/no-debug-non-zts-20170718/grpc.so \ + /usr/local/lib/php/extensions/no-debug-non-zts-20170718/grpc.so + + +RUN docker-php-ext-enable grpc + + +WORKDIR /var/www/html + +COPY client.php ./index.php +COPY composer.json . +COPY echo.proto . + +RUN protoc -I=. echo.proto --php_out=. --grpc_out=. + +RUN composer install diff --git a/examples/php/echo/nginx.conf b/examples/php/echo/nginx.conf new file mode 100644 index 00000000000..ad29815f023 --- /dev/null +++ b/examples/php/echo/nginx.conf @@ -0,0 +1,23 @@ +server { + listen 80; + server_name localhost; + root /var/www/html; + + index index.php; + + location / { + try_files $uri $uri/ /index.php?$args; + } + + location ~ [^/]\.php(/|$) { + fastcgi_split_path_info ^(.+?\.php)(/.*)$; + + include fastcgi_params; + fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; + fastcgi_param PATH_INFO $fastcgi_path_info; + fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info; + + fastcgi_pass fpm:9000; + fastcgi_index index.php; + } +} diff --git a/src/php/bin/build_all_docker_images.sh b/src/php/bin/build_all_docker_images.sh new file mode 100755 index 00000000000..3a644387173 --- /dev/null +++ b/src/php/bin/build_all_docker_images.sh @@ -0,0 +1,40 @@ +#!/bin/bash +# Copyright 2018 gRPC authors. +# +# 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. + +set -e +cd $(dirname $0)/../../.. + +ALL_IMAGES=( grpc-ext grpc-src alpine php5 php-src php-future php-zts + fork-support ) + +if [[ "$1" == "--cmds" ]]; then + for arg in "${ALL_IMAGES[@]}" + do + echo "docker build -t grpc-php/$arg -f ./src/php/docker/$arg/Dockerfile ." + done + exit 0 +fi + +if [[ $# -eq 0 ]]; then + lst=("${ALL_IMAGES[@]}") +else + lst=("$@") +fi + +set -x +for arg in "${lst[@]}" +do + docker build -t grpc-php/"$arg" -f ./src/php/docker/"$arg"/Dockerfile . +done diff --git a/src/php/bin/run_all_docker_images.sh b/src/php/bin/run_all_docker_images.sh new file mode 100755 index 00000000000..0882ecc58f9 --- /dev/null +++ b/src/php/bin/run_all_docker_images.sh @@ -0,0 +1,40 @@ +#!/bin/bash +# Copyright 2018 gRPC authors. +# +# 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. + +set -e +cd $(dirname $0)/../../.. + +ALL_IMAGES=( grpc-ext grpc-src alpine php5 php-src php-future php-zts + fork-support ) + +if [[ "$1" == "--cmds" ]]; then + for arg in "${ALL_IMAGES[@]}" + do + echo "docker run -it --rm grpc-php/$arg" + done + exit 0 +fi + +if [[ $# -eq 0 ]]; then + lst=("${ALL_IMAGES[@]}") +else + lst=("$@") +fi + +set -x +for arg in "${lst[@]}" +do + docker run -it --rm grpc-php/"$arg" +done diff --git a/src/php/docker/README.md b/src/php/docker/README.md new file mode 100644 index 00000000000..f60a86dd64c --- /dev/null +++ b/src/php/docker/README.md @@ -0,0 +1,96 @@ + +# Docker Images for Testing + +This directory contains a number of docker images to assist testing the +[gRPC PECL extension](http://pecl.php.net/package/grpc) against various +different PHP environments. + + +## Build and Run Tests + +To build all docker images: + +```sh +# cd grpc +$ ./src/php/bin/build_all_docker_images.sh + +# or to only build some selected images +$ ./src/php/bin/build_all_docker_images.sh grpc-ext php-src + +# or to only print out individual `docker build` commands +$ ./src/php/bin/build_all_docker_images.sh --cmds +``` + + +To run all tests: + +```sh +$ cd grpc +$ ./src/php/bin/run_all_docker_images.sh + +# or to only run some selected images +$ ./src/php/bin/run_all_docker_images.sh grpc-ext php-src + +# or to only print out individual `docker run` commands +$ ./src/php/bin/run_all_docker_images.sh --cmds +``` + + +## `grpc-ext` + +This image builds the full `grpc` PECL extension (effectively the current +release candidate), installs it against the current PHP version, and runs the +unit tests. + + +## `grpc-src` + +This image builds the `grpc` PECL extension in a 'thin' way, only containing +the gRPC extension source files. The gRPC C Core library is expected to be +installed separately and dynamically linked. The extension is installed +against the current PHP version. + +This also allows us to compile our `grpc` extension with some additional +configure options, like `--enable-tests`, which allows some additional unit +tests to be run. + + +## `alpine` + +This image builds the `grpc` extension against the current PHP version in an +Alpine-Linux base image. + + +## `php-src` + +Instead of using a general purpose base docker image provided by PHP, here we +compile PHP itself from +[source](https://github.com/php/php-src). This will allow us to change some +`configure` options, like `--enable-debug`. Then we proceed to build the full +`grpc` PECL extension and run the unit tests. + + +## `php-zts` + +This image builds the `grpc` extension against the current PHP version with ZTS +enabled. + + +## `php-future` + +This image builds the `grpc` extension against the next future PHP version +currently in alpha, beta or release candidate stage. + + +## `php5` + +This image builds the `grpc` extension against a PHP 5 base image with ZTS +enabled. + +NOTE: PHP 5.x has reached the end-of-life state and is no longer supported. + + +## `fork-support` + +This image tests `pcntl_fork()` support and makes sure scripts using +`pcntl_fork()` don't hang or crash. diff --git a/src/php/docker/alpine/Dockerfile b/src/php/docker/alpine/Dockerfile new file mode 100644 index 00000000000..9cfe8304a1e --- /dev/null +++ b/src/php/docker/alpine/Dockerfile @@ -0,0 +1,38 @@ +# Copyright 2019 gRPC authors. +# +# 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. + +FROM php:7.2-alpine3.9 + +RUN apk add autoconf g++ make zlib-dev git bash wget + + +WORKDIR /tmp + +RUN wget https://phar.phpunit.de/phpunit-4.8.36.phar && \ + mv phpunit-4.8.36.phar /usr/local/bin/phpunit && \ + chmod +x /usr/local/bin/phpunit + + +WORKDIR /github/grpc + +RUN git clone https://github.com/grpc/grpc . && \ + git submodule update --init + +COPY src/ ./src + +RUN pear package && \ + find . -name grpc-*.tgz | xargs -I{} pecl install {} + + +CMD ["/github/grpc/src/php/bin/run_tests.sh", "--skip-persistent-channel-tests"] diff --git a/src/php/docker/fork-support/Dockerfile b/src/php/docker/fork-support/Dockerfile new file mode 100644 index 00000000000..8907214390d --- /dev/null +++ b/src/php/docker/fork-support/Dockerfile @@ -0,0 +1,27 @@ +# Copyright 2019 gRPC authors. +# +# 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. + +FROM grpc-php/php-src + +WORKDIR /tmp + +COPY src/php/docker/fork-support/fork.php . + +RUN echo '\ +extension=grpc.so\n\ +grpc.enable_fork_support=1\n\ +grpc.poll_strategy=epoll1\n\ +' >> /usr/local/lib/php.ini + +CMD ["php", "fork.php"] diff --git a/src/php/docker/fork-support/fork.php b/src/php/docker/fork-support/fork.php new file mode 100644 index 00000000000..8b7d899f7a9 --- /dev/null +++ b/src/php/docker/fork-support/fork.php @@ -0,0 +1,35 @@ + + + RUN docker-php-ext-enable grpc + + + WORKDIR /var/www/html + + COPY client.php ./index.php + COPY composer.json . + COPY echo.proto . + + RUN protoc -I=. echo.proto --php_out=. --grpc_out=. + + RUN composer install diff --git a/templates/examples/php/echo/base.Dockerfile.template b/templates/examples/php/echo/base.Dockerfile.template new file mode 100644 index 00000000000..d56b8619483 --- /dev/null +++ b/templates/examples/php/echo/base.Dockerfile.template @@ -0,0 +1,40 @@ +%YAML 1.2 +--- | + # Copyright 2019 gRPC authors. + # + # 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. + + FROM php:${settings.php_version.php_current_version()}-${settings.php_version.php_debian_version()} + + RUN apt-get -qq update && apt-get -qq install -y ${'\\'} + autoconf automake curl git libtool ${'\\'} + pkg-config unzip zlib1g-dev + + + WORKDIR /tmp + + RUN curl -sSL https://github.com/protocolbuffers/protobuf/releases/download/v3.8.0/${'\\'} + protoc-3.8.0-linux-x86_64.zip -o /tmp/protoc.zip && ${'\\'} + unzip -qq protoc.zip && ${'\\'} + cp /tmp/bin/protoc /usr/local/bin/protoc + + + WORKDIR /github/grpc + + RUN git clone https://github.com/grpc/grpc . && ${'\\'} + git submodule update --init && ${'\\'} + cd third_party/protobuf && git submodule update --init + + RUN make grpc_php_plugin + + RUN pecl install grpc diff --git a/templates/examples/php/echo/cli.Dockerfile.template b/templates/examples/php/echo/cli.Dockerfile.template new file mode 100644 index 00000000000..f9b9f2cbfdf --- /dev/null +++ b/templates/examples/php/echo/cli.Dockerfile.template @@ -0,0 +1,44 @@ +%YAML 1.2 +--- | + # Copyright 2019 gRPC authors. + # + # 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. + + FROM composer:1.8.6 as composer + + + FROM grpc-php/base as grpc-base + + + FROM php:${settings.php_version.php_current_version()}-${settings.php_version.php_debian_version()} + + RUN apt-get -qq update && apt-get -qq install -y git + + + <%include file="copy_from_grpc_base.include" /> + + RUN docker-php-ext-enable grpc + + + WORKDIR /github/grpc-php/examples/echo + + COPY client.php . + COPY composer.json . + COPY echo.proto . + + RUN protoc -I=. echo.proto --php_out=. --grpc_out=. + + RUN composer install + + + CMD ["/bin/bash"] diff --git a/templates/examples/php/echo/copy_from_grpc_base.include b/templates/examples/php/echo/copy_from_grpc_base.include new file mode 100644 index 00000000000..5feae72ce64 --- /dev/null +++ b/templates/examples/php/echo/copy_from_grpc_base.include @@ -0,0 +1,10 @@ +COPY --from=composer /usr/bin/composer /usr/bin/composer + +COPY --from=grpc-base /usr/local/bin/protoc /usr/local/bin/protoc + +COPY --from=grpc-base /github/grpc/bins/opt/grpc_php_plugin ${'\\'} + /usr/local/bin/protoc-gen-grpc + +COPY --from=grpc-base ${'\\'} + /usr/local/lib/php/extensions/no-debug-non-zts-20170718/grpc.so ${'\\'} + /usr/local/lib/php/extensions/no-debug-non-zts-20170718/grpc.so diff --git a/templates/examples/php/echo/fpm.Dockerfile.template b/templates/examples/php/echo/fpm.Dockerfile.template new file mode 100644 index 00000000000..031dcd68bd4 --- /dev/null +++ b/templates/examples/php/echo/fpm.Dockerfile.template @@ -0,0 +1,41 @@ +%YAML 1.2 +--- | + # Copyright 2019 gRPC authors. + # + # 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. + + FROM composer:1.8.6 as composer + + + FROM grpc-php/base as grpc-base + + + FROM php:${settings.php_version.php_current_version()}-fpm-${settings.php_version.php_debian_version()} + + RUN apt-get -qq update && apt-get -qq install -y git + + + <%include file="copy_from_grpc_base.include" /> + + RUN docker-php-ext-enable grpc + + + WORKDIR /var/www/html + + COPY client.php ./index.php + COPY composer.json . + COPY echo.proto . + + RUN protoc -I=. echo.proto --php_out=. --grpc_out=. + + RUN composer install diff --git a/templates/src/php/docker/alpine/Dockerfile.template b/templates/src/php/docker/alpine/Dockerfile.template new file mode 100644 index 00000000000..8bd0ca6ac4d --- /dev/null +++ b/templates/src/php/docker/alpine/Dockerfile.template @@ -0,0 +1,28 @@ +%YAML 1.2 +--- | + # Copyright 2019 gRPC authors. + # + # 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. + + FROM php:${settings.php_version.php_current_version()}-alpine3.9 + + RUN apk add autoconf g++ make zlib-dev git bash wget + + + WORKDIR /tmp + + <%include file="../download_phpunit.include" /> + + <%include file="../pecl_ext_build_src.include" /> + + CMD ["/github/grpc/src/php/bin/run_tests.sh", "--skip-persistent-channel-tests"] diff --git a/templates/src/php/docker/download_phpunit.include b/templates/src/php/docker/download_phpunit.include new file mode 100644 index 00000000000..f8676c39305 --- /dev/null +++ b/templates/src/php/docker/download_phpunit.include @@ -0,0 +1,3 @@ +RUN wget https://phar.phpunit.de/phpunit-4.8.36.phar && ${'\\'} + mv phpunit-4.8.36.phar /usr/local/bin/phpunit && ${'\\'} + chmod +x /usr/local/bin/phpunit diff --git a/templates/src/php/docker/grpc-ext/Dockerfile.template b/templates/src/php/docker/grpc-ext/Dockerfile.template new file mode 100644 index 00000000000..23f2011d407 --- /dev/null +++ b/templates/src/php/docker/grpc-ext/Dockerfile.template @@ -0,0 +1,30 @@ +%YAML 1.2 +--- | + # Copyright 2019 gRPC authors. + # + # 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. + + FROM php:${settings.php_version.php_current_version()}-${settings.php_version.php_debian_version()} + + RUN apt-get -qq update && apt-get -qq install -y ${'\\'} + autoconf automake git libtool pkg-config ${'\\'} + valgrind wget zlib1g-dev + + + WORKDIR /tmp + + <%include file="../download_phpunit.include" /> + + <%include file="../pecl_ext_build_src.include" /> + + CMD ["/github/grpc/src/php/bin/run_tests.sh", "--skip-persistent-channel-tests"] diff --git a/templates/src/php/docker/grpc-src/Dockerfile.template b/templates/src/php/docker/grpc-src/Dockerfile.template new file mode 100644 index 00000000000..dcaf7cc8ea9 --- /dev/null +++ b/templates/src/php/docker/grpc-src/Dockerfile.template @@ -0,0 +1,47 @@ +%YAML 1.2 +--- | + # Copyright 2019 gRPC authors. + # + # 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. + + FROM php:${settings.php_version.php_current_version()}-${settings.php_version.php_debian_version()} + + RUN apt-get -qq update && apt-get -qq install -y ${'\\'} + autoconf automake git libtool pkg-config ${'\\'} + valgrind wget zlib1g-dev + + + WORKDIR /tmp + + <%include file="../download_phpunit.include" /> + + WORKDIR /github/grpc + + RUN git clone https://github.com/grpc/grpc . && ${'\\'} + git submodule update --init && ${'\\'} + make && make install + + + WORKDIR /github/grpc/src/php/ext/grpc + + COPY src/php/ext/grpc/*.c ./ + COPY src/php/ext/grpc/*.h ./ + COPY src/php/ext/grpc/config.m4 ./ + + RUN phpize && ${'\\'} + ./configure --enable-tests && ${'\\'} + make && ${'\\'} + make install + + + CMD ["/github/grpc/src/php/bin/run_tests.sh"] diff --git a/templates/src/php/docker/pecl_ext_build_src.include b/templates/src/php/docker/pecl_ext_build_src.include new file mode 100644 index 00000000000..45d2f426163 --- /dev/null +++ b/templates/src/php/docker/pecl_ext_build_src.include @@ -0,0 +1,9 @@ +WORKDIR /github/grpc + +RUN git clone https://github.com/grpc/grpc . && ${'\\'} + git submodule update --init + +COPY src/ ./src + +RUN pear package && ${'\\'} + find . -name grpc-*.tgz | xargs -I{} pecl install {} diff --git a/templates/src/php/docker/php-future/Dockerfile.template b/templates/src/php/docker/php-future/Dockerfile.template new file mode 100644 index 00000000000..4a5dfe960dc --- /dev/null +++ b/templates/src/php/docker/php-future/Dockerfile.template @@ -0,0 +1,30 @@ +%YAML 1.2 +--- | + # Copyright 2019 gRPC authors. + # + # 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. + + FROM php:7.4.0RC1-buster + + RUN apt-get -qq update && apt-get -qq install -y ${'\\'} + autoconf automake git libtool pkg-config ${'\\'} + wget zlib1g-dev + + + WORKDIR /tmp + + <%include file="../download_phpunit.include" /> + + <%include file="../pecl_ext_build_src.include" /> + + CMD ["/github/grpc/src/php/bin/run_tests.sh", "--skip-persistent-channel-tests"] diff --git a/templates/src/php/docker/php-src/Dockerfile.template b/templates/src/php/docker/php-src/Dockerfile.template new file mode 100644 index 00000000000..e5c637bcb93 --- /dev/null +++ b/templates/src/php/docker/php-src/Dockerfile.template @@ -0,0 +1,52 @@ +%YAML 1.2 +--- | + # Copyright 2019 gRPC authors. + # + # 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. + + FROM debian:${settings.php_version.php_debian_version()} + + RUN apt-get -qq update && apt-get -qq install -y ${'\\'} + autoconf build-essential git libtool ${'\\'} + libcurl4-openssl-dev libedit-dev libsodium-dev ${'\\'} + libssl-dev libxml2-dev ${'\\'} + pkg-config valgrind wget zlib1g-dev + + + WORKDIR /tmp + + <%include file="../download_phpunit.include" /> + + RUN wget http://ftp.gnu.org/gnu/bison/bison-3.4.2.tar.gz && ${'\\'} + tar -zxvf bison-3.4.2.tar.gz && ${'\\'} + cd bison-3.4.2 && ${'\\'} + ./configure && make && make install + + + WORKDIR /github/php-src + + RUN git clone https://github.com/php/php-src . + + RUN git checkout php-7.2.22 && ${'\\'} + ./buildconf --force && ${'\\'} + ./configure --build=x86_64-linux-gnu --enable-option-checking=fatal ${'\\'} + --enable-debug --enable-pcntl ${'\\'} + --enable-ftp --enable-mbstring --enable-mysqlnd ${'\\'} + --with-curl --with-libedit --with-mhash --with-openssl ${'\\'} + --with-sodium=shared --with-zlib && ${'\\'} + make && make install + + + <%include file="../pecl_ext_build_src.include" /> + + CMD ["/github/grpc/src/php/bin/run_tests.sh", "--skip-persistent-channel-tests"] diff --git a/templates/src/php/docker/php-zts/Dockerfile.template b/templates/src/php/docker/php-zts/Dockerfile.template new file mode 100644 index 00000000000..75675f08382 --- /dev/null +++ b/templates/src/php/docker/php-zts/Dockerfile.template @@ -0,0 +1,30 @@ +%YAML 1.2 +--- | + # Copyright 2019 gRPC authors. + # + # 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. + + FROM php:${settings.php_version.php_current_version()}-zts-${settings.php_version.php_debian_version()} + + RUN apt-get -qq update && apt-get -qq install -y ${'\\'} + autoconf automake git libtool pkg-config ${'\\'} + wget zlib1g-dev + + + WORKDIR /tmp + + <%include file="../download_phpunit.include" /> + + <%include file="../pecl_ext_build_src.include" /> + + CMD ["/github/grpc/src/php/bin/run_tests.sh", "--skip-persistent-channel-tests"] diff --git a/templates/src/php/docker/php5/Dockerfile.template b/templates/src/php/docker/php5/Dockerfile.template new file mode 100644 index 00000000000..e6c7b59c9e0 --- /dev/null +++ b/templates/src/php/docker/php5/Dockerfile.template @@ -0,0 +1,30 @@ +%YAML 1.2 +--- | + # Copyright 2019 gRPC authors. + # + # 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. + + FROM php:5.6-zts-stretch + + RUN apt-get -qq update && apt-get -qq install -y ${'\\'} + autoconf automake git libtool pkg-config ${'\\'} + valgrind wget zlib1g-dev + + + WORKDIR /tmp + + <%include file="../download_phpunit.include" /> + + <%include file="../pecl_ext_build_src.include" /> + + CMD ["/github/grpc/src/php/bin/run_tests.sh", "--skip-persistent-channel-tests"] diff --git a/tools/buildgen/plugins/expand_version.py b/tools/buildgen/plugins/expand_version.py index 08cc10b3c60..1ada18b82c4 100755 --- a/tools/buildgen/plugins/expand_version.py +++ b/tools/buildgen/plugins/expand_version.py @@ -100,6 +100,12 @@ class Version: """Version string for PHP Composer package""" return '%d.%d.%d' % (self.major, self.minor, self.patch) + def php_current_version(self): + return '7.2' + + def php_debian_version(self): + return 'stretch' + def mako_plugin(dictionary): """Expand version numbers: From f281c343b9b330944ccd51be02d392d06be2afa3 Mon Sep 17 00:00:00 2001 From: "Mark D. Roth" Date: Tue, 1 Oct 2019 10:19:53 -0700 Subject: [PATCH 47/60] Change HealthCheckClient to use new connectivity state API. --- .../health/health_check_client.cc | 63 ++++++------------- .../health/health_check_client.h | 18 ++---- .../ext/filters/client_channel/subchannel.cc | 41 ++++-------- test/cpp/end2end/client_lb_end2end_test.cc | 28 +++++++++ 4 files changed, 64 insertions(+), 86 deletions(-) diff --git a/src/core/ext/filters/client_channel/health/health_check_client.cc b/src/core/ext/filters/client_channel/health/health_check_client.cc index 2662d8466b6..6091184ec94 100644 --- a/src/core/ext/filters/client_channel/health/health_check_client.cc +++ b/src/core/ext/filters/client_channel/health/health_check_client.cc @@ -47,12 +47,14 @@ HealthCheckClient::HealthCheckClient( const char* service_name, RefCountedPtr connected_subchannel, grpc_pollset_set* interested_parties, - RefCountedPtr channelz_node) + RefCountedPtr channelz_node, + RefCountedPtr watcher) : InternallyRefCounted(&grpc_health_check_client_trace), service_name_(service_name), connected_subchannel_(std::move(connected_subchannel)), interested_parties_(interested_parties), channelz_node_(std::move(channelz_node)), + watcher_(std::move(watcher)), retry_backoff_( BackOff::Options() .set_initial_backoff( @@ -73,43 +75,21 @@ HealthCheckClient::~HealthCheckClient() { if (GRPC_TRACE_FLAG_ENABLED(grpc_health_check_client_trace)) { gpr_log(GPR_INFO, "destroying HealthCheckClient %p", this); } - GRPC_ERROR_UNREF(error_); -} - -void HealthCheckClient::NotifyOnHealthChange(grpc_connectivity_state* state, - grpc_closure* closure) { - MutexLock lock(&mu_); - GPR_ASSERT(notify_state_ == nullptr); - if (*state != state_) { - *state = state_; - GRPC_CLOSURE_SCHED(closure, GRPC_ERROR_REF(error_)); - return; - } - notify_state_ = state; - on_health_changed_ = closure; } void HealthCheckClient::SetHealthStatus(grpc_connectivity_state state, - grpc_error* error) { + const char* reason) { MutexLock lock(&mu_); - SetHealthStatusLocked(state, error); + SetHealthStatusLocked(state, reason); } void HealthCheckClient::SetHealthStatusLocked(grpc_connectivity_state state, - grpc_error* error) { + const char* reason) { if (GRPC_TRACE_FLAG_ENABLED(grpc_health_check_client_trace)) { - gpr_log(GPR_INFO, "HealthCheckClient %p: setting state=%d error=%s", this, - state, grpc_error_string(error)); - } - if (notify_state_ != nullptr && *notify_state_ != state) { - *notify_state_ = state; - notify_state_ = nullptr; - GRPC_CLOSURE_SCHED(on_health_changed_, GRPC_ERROR_REF(error)); - on_health_changed_ = nullptr; + gpr_log(GPR_INFO, "HealthCheckClient %p: setting state=%s reason=%s", this, + ConnectivityStateName(state), reason); } - state_ = state; - GRPC_ERROR_UNREF(error_); - error_ = error; + if (watcher_ != nullptr) watcher_->Notify(state); } void HealthCheckClient::Orphan() { @@ -118,13 +98,8 @@ void HealthCheckClient::Orphan() { } { MutexLock lock(&mu_); - if (on_health_changed_ != nullptr) { - *notify_state_ = GRPC_CHANNEL_SHUTDOWN; - notify_state_ = nullptr; - GRPC_CLOSURE_SCHED(on_health_changed_, GRPC_ERROR_NONE); - on_health_changed_ = nullptr; - } shutting_down_ = true; + watcher_.reset(); call_state_.reset(); if (retry_timer_callback_pending_) { grpc_timer_cancel(&retry_timer_); @@ -141,7 +116,7 @@ void HealthCheckClient::StartCall() { void HealthCheckClient::StartCallLocked() { if (shutting_down_) return; GPR_ASSERT(call_state_ == nullptr); - SetHealthStatusLocked(GRPC_CHANNEL_CONNECTING, GRPC_ERROR_NONE); + SetHealthStatusLocked(GRPC_CHANNEL_CONNECTING, "starting health watch"); call_state_ = MakeOrphanable(Ref(), interested_parties_); if (GRPC_TRACE_FLAG_ENABLED(grpc_health_check_client_trace)) { gpr_log(GPR_INFO, "HealthCheckClient %p: created CallState %p", this, @@ -152,10 +127,8 @@ void HealthCheckClient::StartCallLocked() { void HealthCheckClient::StartRetryTimer() { MutexLock lock(&mu_); - SetHealthStatusLocked( - GRPC_CHANNEL_TRANSIENT_FAILURE, - GRPC_ERROR_CREATE_FROM_STATIC_STRING( - "health check call failed; will retry after backoff")); + SetHealthStatusLocked(GRPC_CHANNEL_TRANSIENT_FAILURE, + "health check call failed; will retry after backoff"); grpc_millis next_try = retry_backoff_.NextAttemptTime(); if (GRPC_TRACE_FLAG_ENABLED(grpc_health_check_client_trace)) { gpr_log(GPR_INFO, "HealthCheckClient %p: health check call lost...", this); @@ -489,10 +462,10 @@ void HealthCheckClient::CallState::DoneReadingRecvMessage(grpc_error* error) { const bool healthy = DecodeResponse(&recv_message_buffer_, &error); const grpc_connectivity_state state = healthy ? GRPC_CHANNEL_READY : GRPC_CHANNEL_TRANSIENT_FAILURE; - if (error == GRPC_ERROR_NONE && !healthy) { - error = GRPC_ERROR_CREATE_FROM_STATIC_STRING("backend unhealthy"); - } - health_check_client_->SetHealthStatus(state, error); + const char* reason = error == GRPC_ERROR_NONE && !healthy + ? "backend unhealthy" + : grpc_error_string(error); + health_check_client_->SetHealthStatus(state, reason); seen_response_.Store(true, MemoryOrder::RELEASE); grpc_slice_buffer_destroy_internal(&recv_message_buffer_); // Start another recv_message batch. @@ -603,7 +576,7 @@ void HealthCheckClient::CallState::RecvTrailingMetadataReady( grpc_slice_from_static_string(kErrorMessage)); } self->health_check_client_->SetHealthStatus(GRPC_CHANNEL_READY, - GRPC_ERROR_NONE); + kErrorMessage); retry = false; } self->CallEnded(retry); diff --git a/src/core/ext/filters/client_channel/health/health_check_client.h b/src/core/ext/filters/client_channel/health/health_check_client.h index 956c1095550..f8b9ade5ab6 100644 --- a/src/core/ext/filters/client_channel/health/health_check_client.h +++ b/src/core/ext/filters/client_channel/health/health_check_client.h @@ -47,16 +47,11 @@ class HealthCheckClient : public InternallyRefCounted { HealthCheckClient(const char* service_name, RefCountedPtr connected_subchannel, grpc_pollset_set* interested_parties, - RefCountedPtr channelz_node); + RefCountedPtr channelz_node, + RefCountedPtr watcher); ~HealthCheckClient(); - // When the health state changes from *state, sets *state to the new - // value and schedules closure. - // Only one closure can be outstanding at a time. - void NotifyOnHealthChange(grpc_connectivity_state* state, - grpc_closure* closure); - void Orphan() override; private: @@ -151,9 +146,9 @@ class HealthCheckClient : public InternallyRefCounted { void StartRetryTimer(); static void OnRetryTimer(void* arg, grpc_error* error); - void SetHealthStatus(grpc_connectivity_state state, grpc_error* error); + void SetHealthStatus(grpc_connectivity_state state, const char* reason); void SetHealthStatusLocked(grpc_connectivity_state state, - grpc_error* error); // Requires holding mu_. + const char* reason); // Requires holding mu_. const char* service_name_; // Do not own. RefCountedPtr connected_subchannel_; @@ -161,10 +156,7 @@ class HealthCheckClient : public InternallyRefCounted { RefCountedPtr channelz_node_; Mutex mu_; - grpc_connectivity_state state_ = GRPC_CHANNEL_CONNECTING; - grpc_error* error_ = GRPC_ERROR_NONE; - grpc_connectivity_state* notify_state_ = nullptr; - grpc_closure* on_health_changed_ = nullptr; + RefCountedPtr watcher_; bool shutting_down_ = false; // The data associated with the current health check call. It holds a ref diff --git a/src/core/ext/filters/client_channel/subchannel.cc b/src/core/ext/filters/client_channel/subchannel.cc index 2c3f899d2a7..b762349eb62 100644 --- a/src/core/ext/filters/client_channel/subchannel.cc +++ b/src/core/ext/filters/client_channel/subchannel.cc @@ -401,7 +401,7 @@ void Subchannel::ConnectivityStateWatcherList::NotifyLocked( // State needed for tracking the connectivity state with a particular // health check service name. class Subchannel::HealthWatcherMap::HealthWatcher - : public InternallyRefCounted { + : public AsyncConnectivityStateWatcherInterface { public: HealthWatcher(Subchannel* c, UniquePtr health_check_service_name, grpc_connectivity_state subchannel_state) @@ -410,8 +410,6 @@ class Subchannel::HealthWatcherMap::HealthWatcher state_(subchannel_state == GRPC_CHANNEL_READY ? GRPC_CHANNEL_CONNECTING : subchannel_state) { GRPC_SUBCHANNEL_WEAK_REF(subchannel_, "health_watcher"); - GRPC_CLOSURE_INIT(&on_health_changed_, OnHealthChanged, this, - grpc_schedule_on_exec_ctx); // If the subchannel is already connected, start health checking. if (subchannel_state == GRPC_CHANNEL_READY) StartHealthCheckingLocked(); } @@ -428,7 +426,7 @@ class Subchannel::HealthWatcherMap::HealthWatcher void AddWatcherLocked( grpc_connectivity_state initial_state, - OrphanablePtr watcher) { + OrphanablePtr watcher) { if (state_ != initial_state) { RefCountedPtr connected_subchannel; if (state_ == GRPC_CHANNEL_READY) { @@ -440,7 +438,8 @@ class Subchannel::HealthWatcherMap::HealthWatcher watcher_list_.AddWatcherLocked(std::move(watcher)); } - void RemoveWatcherLocked(ConnectivityStateWatcherInterface* watcher) { + void RemoveWatcherLocked( + Subchannel::ConnectivityStateWatcherInterface* watcher) { watcher_list_.RemoveWatcherLocked(watcher); } @@ -473,38 +472,24 @@ class Subchannel::HealthWatcherMap::HealthWatcher } private: + void OnConnectivityStateChange(grpc_connectivity_state new_state) override { + MutexLock lock(&subchannel_->mu_); + if (new_state != GRPC_CHANNEL_SHUTDOWN && health_check_client_ != nullptr) { + state_ = new_state; + watcher_list_.NotifyLocked(subchannel_, new_state); + } + } + void StartHealthCheckingLocked() { GPR_ASSERT(health_check_client_ == nullptr); health_check_client_ = MakeOrphanable( health_check_service_name_.get(), subchannel_->connected_subchannel_, - subchannel_->pollset_set_, subchannel_->channelz_node_); - Ref().release(); // Ref for health callback tracked manually. - health_check_client_->NotifyOnHealthChange(&state_, &on_health_changed_); - } - - static void OnHealthChanged(void* arg, grpc_error* error) { - auto* self = static_cast(arg); - Subchannel* c = self->subchannel_; - { - MutexLock lock(&c->mu_); - if (self->state_ != GRPC_CHANNEL_SHUTDOWN && - self->health_check_client_ != nullptr) { - self->watcher_list_.NotifyLocked(c, self->state_); - // Renew watch. - self->health_check_client_->NotifyOnHealthChange( - &self->state_, &self->on_health_changed_); - return; // So we don't unref below. - } - } - // Don't unref until we've released the lock, because this might - // cause the subchannel (which contains the lock) to be destroyed. - self->Unref(); + subchannel_->pollset_set_, subchannel_->channelz_node_, Ref()); } Subchannel* subchannel_; UniquePtr health_check_service_name_; OrphanablePtr health_check_client_; - grpc_closure on_health_changed_; grpc_connectivity_state state_; ConnectivityStateWatcherList watcher_list_; }; diff --git a/test/cpp/end2end/client_lb_end2end_test.cc b/test/cpp/end2end/client_lb_end2end_test.cc index 5a657e15b5f..8c3ef368d58 100644 --- a/test/cpp/end2end/client_lb_end2end_test.cc +++ b/test/cpp/end2end/client_lb_end2end_test.cc @@ -1471,6 +1471,34 @@ TEST_F(ClientLbEnd2endTest, RoundRobinWithHealthChecking) { EnableDefaultHealthCheckService(false); } +TEST_F(ClientLbEnd2endTest, + RoundRobinWithHealthCheckingHandlesSubchannelFailure) { + EnableDefaultHealthCheckService(true); + // Start servers. + const int kNumServers = 3; + StartServers(kNumServers); + servers_[0]->SetServingStatus("health_check_service_name", true); + servers_[1]->SetServingStatus("health_check_service_name", true); + servers_[2]->SetServingStatus("health_check_service_name", true); + ChannelArguments args; + args.SetServiceConfigJSON( + "{\"healthCheckConfig\": " + "{\"serviceName\": \"health_check_service_name\"}}"); + auto response_generator = BuildResolverResponseGenerator(); + auto channel = BuildChannel("round_robin", response_generator, args); + auto stub = BuildStub(channel); + response_generator.SetNextResolution(GetServersPorts()); + WaitForServer(stub, 0, DEBUG_LOCATION); + // Stop server 0 and send a new resolver result to ensure that RR + // checks each subchannel's state. + servers_[0]->Shutdown(); + response_generator.SetNextResolution(GetServersPorts()); + // Send a bunch more RPCs. + for (size_t i = 0; i < 100; i++) { + SendRpc(stub); + } +} + TEST_F(ClientLbEnd2endTest, RoundRobinWithHealthCheckingInhibitPerChannel) { EnableDefaultHealthCheckService(true); // Start server. From 1743519aa900055aa6d02d5961c64ab294dc501f Mon Sep 17 00:00:00 2001 From: Esun Kim Date: Tue, 24 Sep 2019 11:32:35 -0700 Subject: [PATCH 48/60] Activate C++ stdlib --- BUILD | 6 - BUILD.gn | 2 - CMakeLists.txt | 42 -- Makefile | 48 -- bazel/grpc_build_system.bzl | 3 - build.yaml | 15 - gRPC-C++.podspec | 1 - gRPC-Core.podspec | 2 - grpc.gemspec | 1 - include/grpc/impl/codegen/port_platform.h | 8 - package.xml | 1 - .../client_channel/client_channel_factory.h | 6 +- .../ext/filters/client_channel/lb_policy.h | 52 +- .../lb_policy/subchannel_list.h | 7 +- .../lb_policy/xds/xds_client_stats.cc | 4 - .../lb_policy/xds/xds_load_balancer_api.cc | 8 - .../client_channel/lb_policy_factory.h | 9 +- .../ext/filters/client_channel/resolver.h | 13 +- .../resolver/dns/c_ares/grpc_ares_ev_driver.h | 23 +- .../filters/client_channel/resolver_factory.h | 10 +- .../filters/client_channel/service_config.h | 4 - .../ext/filters/client_channel/subchannel.h | 6 +- .../client_channel/subchannel_interface.h | 22 +- .../subchannel_pool_interface.h | 9 +- .../transport/chttp2/transport/flow_control.h | 5 - src/core/lib/channel/channelz.h | 2 +- src/core/lib/channel/handshaker.h | 7 +- src/core/lib/channel/handshaker_factory.h | 4 +- src/core/lib/gprpp/abstract.h | 47 -- src/core/lib/gprpp/map.h | 497 ----------------- src/core/lib/gprpp/orphanable.h | 7 +- src/core/lib/gprpp/ref_counted.h | 7 - src/core/lib/gprpp/thd.h | 6 +- src/core/lib/iomgr/executor/mpmcqueue.h | 9 +- src/core/lib/iomgr/executor/threadpool.h | 13 +- src/core/lib/iomgr/tcp_server.h | 5 +- src/core/lib/iomgr/udp_server.h | 16 +- .../lib/security/credentials/credentials.h | 24 +- .../credentials/oauth2/oauth2_credentials.h | 4 +- .../security_connector/security_connector.h | 26 +- src/core/lib/surface/completion_queue.h | 1 - src/core/lib/transport/byte_stream.h | 10 +- src/core/tsi/ssl/session_cache/ssl_session.h | 4 +- test/core/gprpp/BUILD | 14 - test/core/gprpp/manual_constructor_test.cc | 2 - test/core/gprpp/map_test.cc | 514 ------------------ test/cpp/qps/interarrival.h | 1 - tools/doxygen/Doxyfile.c++.internal | 1 - tools/doxygen/Doxyfile.core.internal | 1 - .../linux/grpc_bazel_build_in_docker.sh | 1 - tools/run_tests/generated/tests.json | 24 - 51 files changed, 94 insertions(+), 1460 deletions(-) delete mode 100644 src/core/lib/gprpp/abstract.h delete mode 100644 test/core/gprpp/map_test.cc diff --git a/BUILD b/BUILD index 12313bcfa34..1128f715c79 100644 --- a/BUILD +++ b/BUILD @@ -69,11 +69,6 @@ config_setting( values = {"cpu": "darwin"}, ) -config_setting( - name = "grpc_use_cpp_std_lib", - values = {"define": "GRPC_USE_CPP_STD_LIB=1"}, -) - python_config_settings() # This should be updated along with build.yaml @@ -514,7 +509,6 @@ grpc_cc_library( "src/core/lib/gpr/tls_pthread.h", "src/core/lib/gpr/tmpfile.h", "src/core/lib/gpr/useful.h", - "src/core/lib/gprpp/abstract.h", "src/core/lib/gprpp/arena.h", "src/core/lib/gprpp/atomic.h", "src/core/lib/gprpp/fork.h", diff --git a/BUILD.gn b/BUILD.gn index 7ad8f248bdf..0e3e5c51c7b 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -132,7 +132,6 @@ config("grpc_config") { "src/core/lib/gpr/tmpfile_windows.cc", "src/core/lib/gpr/useful.h", "src/core/lib/gpr/wrap_memcpy.cc", - "src/core/lib/gprpp/abstract.h", "src/core/lib/gprpp/arena.cc", "src/core/lib/gprpp/arena.h", "src/core/lib/gprpp/atomic.h", @@ -1237,7 +1236,6 @@ config("grpc_config") { "src/core/lib/gpr/tls_pthread.h", "src/core/lib/gpr/tmpfile.h", "src/core/lib/gpr/useful.h", - "src/core/lib/gprpp/abstract.h", "src/core/lib/gprpp/arena.h", "src/core/lib/gprpp/atomic.h", "src/core/lib/gprpp/debug_location.h", diff --git a/CMakeLists.txt b/CMakeLists.txt index 518ca81c664..59c575f894c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -631,7 +631,6 @@ add_dependencies(buildtests_cxx golden_file_test) add_dependencies(buildtests_cxx gprpp_mpscq_test) add_dependencies(buildtests_cxx grpc_alts_credentials_options_test) add_dependencies(buildtests_cxx grpc_cli) -add_dependencies(buildtests_cxx grpc_core_map_test) add_dependencies(buildtests_cxx grpc_fetch_oauth2) add_dependencies(buildtests_cxx grpc_linux_system_roots_test) add_dependencies(buildtests_cxx grpc_spiffe_security_connector_test) @@ -13408,47 +13407,6 @@ target_link_libraries(grpc_cli ) -endif (gRPC_BUILD_TESTS) -if (gRPC_BUILD_TESTS) - -add_executable(grpc_core_map_test - test/core/gprpp/map_test.cc - third_party/googletest/googletest/src/gtest-all.cc - third_party/googletest/googlemock/src/gmock-all.cc -) - - -target_include_directories(grpc_core_map_test - PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} - PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include - PRIVATE ${_gRPC_ADDRESS_SORTING_INCLUDE_DIR} - PRIVATE ${_gRPC_BENCHMARK_INCLUDE_DIR} - PRIVATE ${_gRPC_CARES_INCLUDE_DIR} - PRIVATE ${_gRPC_GFLAGS_INCLUDE_DIR} - PRIVATE ${_gRPC_PROTOBUF_INCLUDE_DIR} - PRIVATE ${_gRPC_SSL_INCLUDE_DIR} - PRIVATE ${_gRPC_UPB_GENERATED_DIR} - PRIVATE ${_gRPC_UPB_GRPC_GENERATED_DIR} - PRIVATE ${_gRPC_UPB_INCLUDE_DIR} - PRIVATE ${_gRPC_ZLIB_INCLUDE_DIR} - PRIVATE third_party/googletest/googletest/include - PRIVATE third_party/googletest/googletest - PRIVATE third_party/googletest/googlemock/include - PRIVATE third_party/googletest/googlemock - PRIVATE ${_gRPC_PROTO_GENS_DIR} -) - -target_link_libraries(grpc_core_map_test - ${_gRPC_PROTOBUF_LIBRARIES} - ${_gRPC_ALLTARGETS_LIBRARIES} - grpc_test_util - grpc++ - grpc - gpr - ${_gRPC_GFLAGS_LIBRARIES} -) - - endif (gRPC_BUILD_TESTS) if (gRPC_BUILD_CODEGEN) diff --git a/Makefile b/Makefile index 20e01d6c10c..9358cc3205d 100644 --- a/Makefile +++ b/Makefile @@ -1220,7 +1220,6 @@ golden_file_test: $(BINDIR)/$(CONFIG)/golden_file_test gprpp_mpscq_test: $(BINDIR)/$(CONFIG)/gprpp_mpscq_test grpc_alts_credentials_options_test: $(BINDIR)/$(CONFIG)/grpc_alts_credentials_options_test grpc_cli: $(BINDIR)/$(CONFIG)/grpc_cli -grpc_core_map_test: $(BINDIR)/$(CONFIG)/grpc_core_map_test grpc_cpp_plugin: $(BINDIR)/$(CONFIG)/grpc_cpp_plugin grpc_csharp_plugin: $(BINDIR)/$(CONFIG)/grpc_csharp_plugin grpc_fetch_oauth2: $(BINDIR)/$(CONFIG)/grpc_fetch_oauth2 @@ -1699,7 +1698,6 @@ buildtests_cxx: privatelibs_cxx \ $(BINDIR)/$(CONFIG)/gprpp_mpscq_test \ $(BINDIR)/$(CONFIG)/grpc_alts_credentials_options_test \ $(BINDIR)/$(CONFIG)/grpc_cli \ - $(BINDIR)/$(CONFIG)/grpc_core_map_test \ $(BINDIR)/$(CONFIG)/grpc_fetch_oauth2 \ $(BINDIR)/$(CONFIG)/grpc_linux_system_roots_test \ $(BINDIR)/$(CONFIG)/grpc_spiffe_security_connector_test \ @@ -1870,7 +1868,6 @@ buildtests_cxx: privatelibs_cxx \ $(BINDIR)/$(CONFIG)/gprpp_mpscq_test \ $(BINDIR)/$(CONFIG)/grpc_alts_credentials_options_test \ $(BINDIR)/$(CONFIG)/grpc_cli \ - $(BINDIR)/$(CONFIG)/grpc_core_map_test \ $(BINDIR)/$(CONFIG)/grpc_fetch_oauth2 \ $(BINDIR)/$(CONFIG)/grpc_linux_system_roots_test \ $(BINDIR)/$(CONFIG)/grpc_spiffe_security_connector_test \ @@ -2378,8 +2375,6 @@ test_cxx: buildtests_cxx $(Q) $(BINDIR)/$(CONFIG)/gprpp_mpscq_test || ( echo test gprpp_mpscq_test failed ; exit 1 ) $(E) "[RUN] Testing grpc_alts_credentials_options_test" $(Q) $(BINDIR)/$(CONFIG)/grpc_alts_credentials_options_test || ( echo test grpc_alts_credentials_options_test failed ; exit 1 ) - $(E) "[RUN] Testing grpc_core_map_test" - $(Q) $(BINDIR)/$(CONFIG)/grpc_core_map_test || ( echo test grpc_core_map_test failed ; exit 1 ) $(E) "[RUN] Testing grpc_linux_system_roots_test" $(Q) $(BINDIR)/$(CONFIG)/grpc_linux_system_roots_test || ( echo test grpc_linux_system_roots_test failed ; exit 1 ) $(E) "[RUN] Testing grpc_spiffe_security_connector_test" @@ -16803,49 +16798,6 @@ endif endif -GRPC_CORE_MAP_TEST_SRC = \ - test/core/gprpp/map_test.cc \ - -GRPC_CORE_MAP_TEST_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(GRPC_CORE_MAP_TEST_SRC)))) -ifeq ($(NO_SECURE),true) - -# You can't build secure targets if you don't have OpenSSL. - -$(BINDIR)/$(CONFIG)/grpc_core_map_test: openssl_dep_error - -else - - - - -ifeq ($(NO_PROTOBUF),true) - -# You can't build the protoc plugins or protobuf-enabled targets if you don't have protobuf 3.5.0+. - -$(BINDIR)/$(CONFIG)/grpc_core_map_test: protobuf_dep_error - -else - -$(BINDIR)/$(CONFIG)/grpc_core_map_test: $(PROTOBUF_DEP) $(GRPC_CORE_MAP_TEST_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc++.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr.a - $(E) "[LD] Linking $@" - $(Q) mkdir -p `dirname $@` - $(Q) $(LDXX) $(LDFLAGS) $(GRPC_CORE_MAP_TEST_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc++.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LDLIBSXX) $(LDLIBS_PROTOBUF) $(LDLIBS) $(LDLIBS_SECURE) $(GTEST_LIB) -o $(BINDIR)/$(CONFIG)/grpc_core_map_test - -endif - -endif - -$(OBJDIR)/$(CONFIG)/test/core/gprpp/map_test.o: $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc++.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr.a - -deps_grpc_core_map_test: $(GRPC_CORE_MAP_TEST_OBJS:.o=.dep) - -ifneq ($(NO_SECURE),true) -ifneq ($(NO_DEPS),true) --include $(GRPC_CORE_MAP_TEST_OBJS:.o=.dep) -endif -endif - - GRPC_CPP_PLUGIN_SRC = \ src/compiler/cpp_plugin.cc \ diff --git a/bazel/grpc_build_system.bzl b/bazel/grpc_build_system.bzl index ed137285334..95c639c9dbc 100644 --- a/bazel/grpc_build_system.bzl +++ b/bazel/grpc_build_system.bzl @@ -98,9 +98,6 @@ def grpc_cc_library( "//:grpc_allow_exceptions": ["GRPC_ALLOW_EXCEPTIONS=1"], "//:grpc_disallow_exceptions": ["GRPC_ALLOW_EXCEPTIONS=0"], "//conditions:default": [], - }) + select({ - "//:grpc_use_cpp_std_lib": ["GRPC_USE_CPP_STD_LIB=1"], - "//conditions:default": [], }), hdrs = hdrs + public_hdrs, deps = deps + _get_external_deps(external_deps), diff --git a/build.yaml b/build.yaml index 81058a6d1c9..285a33a0140 100644 --- a/build.yaml +++ b/build.yaml @@ -279,7 +279,6 @@ filegroups: - src/core/lib/gpr/tls_pthread.h - src/core/lib/gpr/tmpfile.h - src/core/lib/gpr/useful.h - - src/core/lib/gprpp/abstract.h - src/core/lib/gprpp/arena.h - src/core/lib/gprpp/atomic.h - src/core/lib/gprpp/fork.h @@ -5016,20 +5015,6 @@ targets: - grpc - gpr - grpc++_test_config -- name: grpc_core_map_test - gtest: true - build: test - language: c++ - headers: - - test/core/gprpp/map_tester.h - src: - - test/core/gprpp/map_test.cc - deps: - - grpc_test_util - - grpc++ - - grpc - - gpr - uses_polling: false - name: grpc_cpp_plugin build: protoc language: c++ diff --git a/gRPC-C++.podspec b/gRPC-C++.podspec index 87de0d91a81..bc844cd4517 100644 --- a/gRPC-C++.podspec +++ b/gRPC-C++.podspec @@ -299,7 +299,6 @@ Pod::Spec.new do |s| 'src/core/lib/gpr/tls_pthread.h', 'src/core/lib/gpr/tmpfile.h', 'src/core/lib/gpr/useful.h', - 'src/core/lib/gprpp/abstract.h', 'src/core/lib/gprpp/arena.h', 'src/core/lib/gprpp/atomic.h', 'src/core/lib/gprpp/fork.h', diff --git a/gRPC-Core.podspec b/gRPC-Core.podspec index da18f800006..8be7a3d7e5d 100644 --- a/gRPC-Core.podspec +++ b/gRPC-Core.podspec @@ -202,7 +202,6 @@ Pod::Spec.new do |s| 'src/core/lib/gpr/tls_pthread.h', 'src/core/lib/gpr/tmpfile.h', 'src/core/lib/gpr/useful.h', - 'src/core/lib/gprpp/abstract.h', 'src/core/lib/gprpp/arena.h', 'src/core/lib/gprpp/atomic.h', 'src/core/lib/gprpp/fork.h', @@ -978,7 +977,6 @@ Pod::Spec.new do |s| 'src/core/lib/gpr/tls_pthread.h', 'src/core/lib/gpr/tmpfile.h', 'src/core/lib/gpr/useful.h', - 'src/core/lib/gprpp/abstract.h', 'src/core/lib/gprpp/arena.h', 'src/core/lib/gprpp/atomic.h', 'src/core/lib/gprpp/fork.h', diff --git a/grpc.gemspec b/grpc.gemspec index baa52fb9830..698d9f162b5 100644 --- a/grpc.gemspec +++ b/grpc.gemspec @@ -96,7 +96,6 @@ Gem::Specification.new do |s| s.files += %w( src/core/lib/gpr/tls_pthread.h ) s.files += %w( src/core/lib/gpr/tmpfile.h ) s.files += %w( src/core/lib/gpr/useful.h ) - s.files += %w( src/core/lib/gprpp/abstract.h ) s.files += %w( src/core/lib/gprpp/arena.h ) s.files += %w( src/core/lib/gprpp/atomic.h ) s.files += %w( src/core/lib/gprpp/fork.h ) diff --git a/include/grpc/impl/codegen/port_platform.h b/include/grpc/impl/codegen/port_platform.h index d1767ab0b75..fe414023dac 100644 --- a/include/grpc/impl/codegen/port_platform.h +++ b/include/grpc/impl/codegen/port_platform.h @@ -27,14 +27,6 @@ * - some syscalls to be made directly */ -/* - * Defines GRPC_USE_CPP_STD_LIB to use standard C++ library instead of - * in-house library if possible. (e.g. std::map) - */ -#ifndef GRPC_USE_CPP_STD_LIB -#define GRPC_USE_CPP_STD_LIB 1 -#endif - /* Get windows.h included everywhere (we need it) */ #if defined(_WIN64) || defined(WIN64) || defined(_WIN32) || defined(WIN32) #ifndef WIN32_LEAN_AND_MEAN diff --git a/package.xml b/package.xml index d8633ebfde1..56807a958c7 100644 --- a/package.xml +++ b/package.xml @@ -101,7 +101,6 @@ - diff --git a/src/core/ext/filters/client_channel/client_channel_factory.h b/src/core/ext/filters/client_channel/client_channel_factory.h index 42bc7cb505f..79797bbc454 100644 --- a/src/core/ext/filters/client_channel/client_channel_factory.h +++ b/src/core/ext/filters/client_channel/client_channel_factory.h @@ -24,7 +24,6 @@ #include #include "src/core/ext/filters/client_channel/subchannel.h" -#include "src/core/lib/gprpp/abstract.h" namespace grpc_core { @@ -33,8 +32,7 @@ class ClientChannelFactory { virtual ~ClientChannelFactory() = default; // Creates a subchannel with the specified args. - virtual Subchannel* CreateSubchannel(const grpc_channel_args* args) - GRPC_ABSTRACT; + virtual Subchannel* CreateSubchannel(const grpc_channel_args* args) = 0; // Returns a channel arg containing the specified factory. static grpc_arg CreateChannelArg(ClientChannelFactory* factory); @@ -42,8 +40,6 @@ class ClientChannelFactory { // Returns the factory from args, or null if not found. static ClientChannelFactory* GetFromChannelArgs( const grpc_channel_args* args); - - GRPC_ABSTRACT_BASE_CLASS }; } // namespace grpc_core diff --git a/src/core/ext/filters/client_channel/lb_policy.h b/src/core/ext/filters/client_channel/lb_policy.h index 093d5fc30b8..d727cea7db6 100644 --- a/src/core/ext/filters/client_channel/lb_policy.h +++ b/src/core/ext/filters/client_channel/lb_policy.h @@ -24,7 +24,6 @@ #include "src/core/ext/filters/client_channel/server_address.h" #include "src/core/ext/filters/client_channel/service_config.h" #include "src/core/ext/filters/client_channel/subchannel_interface.h" -#include "src/core/lib/gprpp/abstract.h" #include "src/core/lib/gprpp/map.h" #include "src/core/lib/gprpp/orphanable.h" #include "src/core/lib/gprpp/ref_counted_ptr.h" @@ -109,13 +108,11 @@ class LoadBalancingPolicy : public InternallyRefCounted { /// automatically freed when the call is complete. /// It is more efficient to use this than to allocate memory directly /// for allocations that need to be made on a per-call basis. - virtual void* Alloc(size_t size) GRPC_ABSTRACT; + virtual void* Alloc(size_t size) = 0; /// Returns the backend metric data returned by the server for the call, /// or null if no backend metric data was returned. - virtual const BackendMetricData* GetBackendMetricData() GRPC_ABSTRACT; - - GRPC_ABSTRACT_BASE_CLASS + virtual const BackendMetricData* GetBackendMetricData() = 0; }; /// Interface for accessing metadata. @@ -134,20 +131,18 @@ class LoadBalancingPolicy : public InternallyRefCounted { /// Implementations must ensure that the key and value remain alive /// until the call ends. If desired, they may be allocated via /// CallState::Alloc(). - virtual void Add(StringView key, StringView value) GRPC_ABSTRACT; + virtual void Add(StringView key, StringView value) = 0; /// Iteration interface. - virtual Iterator Begin() const GRPC_ABSTRACT; - virtual bool IsEnd(Iterator it) const GRPC_ABSTRACT; - virtual void Next(Iterator* it) const GRPC_ABSTRACT; - virtual StringView Key(Iterator it) const GRPC_ABSTRACT; - virtual StringView Value(Iterator it) const GRPC_ABSTRACT; + virtual Iterator Begin() const = 0; + virtual bool IsEnd(Iterator it) const = 0; + virtual void Next(Iterator* it) const = 0; + virtual StringView Key(Iterator it) const = 0; + virtual StringView Value(Iterator it) const = 0; /// Removes the element pointed to by \a it, which is modified to /// point to the next element. - virtual void Erase(Iterator* it) GRPC_ABSTRACT; - - GRPC_ABSTRACT_BASE_CLASS + virtual void Erase(Iterator* it) = 0; }; /// Arguments used when picking a subchannel for a call. @@ -229,9 +224,7 @@ class LoadBalancingPolicy : public InternallyRefCounted { SubchannelPicker() = default; virtual ~SubchannelPicker() = default; - virtual PickResult Pick(PickArgs args) GRPC_ABSTRACT; - - GRPC_ABSTRACT_BASE_CLASS + virtual PickResult Pick(PickArgs args) = 0; }; /// A proxy object implemented by the client channel and used by the @@ -246,22 +239,19 @@ class LoadBalancingPolicy : public InternallyRefCounted { /// Creates a new subchannel with the specified channel args. virtual RefCountedPtr CreateSubchannel( - const grpc_channel_args& args) GRPC_ABSTRACT; + const grpc_channel_args& args) = 0; /// Sets the connectivity state and returns a new picker to be used /// by the client channel. virtual void UpdateState(grpc_connectivity_state state, - UniquePtr) GRPC_ABSTRACT; + UniquePtr) = 0; /// Requests that the resolver re-resolve. - virtual void RequestReresolution() GRPC_ABSTRACT; + virtual void RequestReresolution() = 0; /// Adds a trace message associated with the channel. enum TraceSeverity { TRACE_INFO, TRACE_WARNING, TRACE_ERROR }; - virtual void AddTraceEvent(TraceSeverity severity, - StringView message) GRPC_ABSTRACT; - - GRPC_ABSTRACT_BASE_CLASS + virtual void AddTraceEvent(TraceSeverity severity, StringView message) = 0; }; /// Interface for configuration data used by an LB policy implementation. @@ -272,9 +262,7 @@ class LoadBalancingPolicy : public InternallyRefCounted { virtual ~Config() = default; // Returns the load balancing policy name - virtual const char* name() const GRPC_ABSTRACT; - - GRPC_ABSTRACT_BASE_CLASS + virtual const char* name() const = 0; }; /// Data passed to the UpdateLocked() method when new addresses and @@ -319,12 +307,12 @@ class LoadBalancingPolicy : public InternallyRefCounted { LoadBalancingPolicy& operator=(const LoadBalancingPolicy&) = delete; /// Returns the name of the LB policy. - virtual const char* name() const GRPC_ABSTRACT; + virtual const char* name() const = 0; /// Updates the policy with new data from the resolver. Will be invoked /// immediately after LB policy is constructed, and then again whenever /// the resolver returns a new result. - virtual void UpdateLocked(UpdateArgs) GRPC_ABSTRACT; // NOLINT + virtual void UpdateLocked(UpdateArgs) = 0; // NOLINT /// Tries to enter a READY connectivity state. /// This is a no-op by default, since most LB policies never go into @@ -332,7 +320,7 @@ class LoadBalancingPolicy : public InternallyRefCounted { virtual void ExitIdleLocked() {} /// Resets connection backoff. - virtual void ResetBackoffLocked() GRPC_ABSTRACT; + virtual void ResetBackoffLocked() = 0; grpc_pollset_set* interested_parties() const { return interested_parties_; } @@ -370,8 +358,6 @@ class LoadBalancingPolicy : public InternallyRefCounted { grpc_error* error_; }; - GRPC_ABSTRACT_BASE_CLASS - protected: grpc_combiner* combiner() const { return combiner_; } @@ -382,7 +368,7 @@ class LoadBalancingPolicy : public InternallyRefCounted { } /// Shuts down the policy. - virtual void ShutdownLocked() GRPC_ABSTRACT; + virtual void ShutdownLocked() = 0; private: /// Combiner under which LB policy actions take place. diff --git a/src/core/ext/filters/client_channel/lb_policy/subchannel_list.h b/src/core/ext/filters/client_channel/lb_policy/subchannel_list.h index b4d3fab91be..5354af7acd4 100644 --- a/src/core/ext/filters/client_channel/lb_policy/subchannel_list.h +++ b/src/core/ext/filters/client_channel/lb_policy/subchannel_list.h @@ -33,7 +33,6 @@ #include "src/core/ext/filters/client_channel/subchannel_interface.h" #include "src/core/lib/channel/channel_args.h" #include "src/core/lib/debug/trace.h" -#include "src/core/lib/gprpp/abstract.h" #include "src/core/lib/gprpp/inlined_vector.h" #include "src/core/lib/gprpp/orphanable.h" #include "src/core/lib/gprpp/ref_counted.h" @@ -117,8 +116,6 @@ class SubchannelData { // Cancels any pending connectivity watch and unrefs the subchannel. void ShutdownLocked(); - GRPC_ABSTRACT_BASE_CLASS - protected: SubchannelData( SubchannelList* subchannel_list, @@ -131,7 +128,7 @@ class SubchannelData { // invoked whenever the subchannel's connectivity state changes. // To stop watching, use CancelConnectivityWatchLocked(). virtual void ProcessConnectivityChangeLocked( - grpc_connectivity_state connectivity_state) GRPC_ABSTRACT; + grpc_connectivity_state connectivity_state) = 0; private: // Watcher for subchannel connectivity state. @@ -200,8 +197,6 @@ class SubchannelList : public InternallyRefCounted { InternallyRefCounted::Unref(DEBUG_LOCATION, "shutdown"); } - GRPC_ABSTRACT_BASE_CLASS - protected: SubchannelList(LoadBalancingPolicy* policy, TraceFlag* tracer, const ServerAddressList& addresses, diff --git a/src/core/ext/filters/client_channel/lb_policy/xds/xds_client_stats.cc b/src/core/ext/filters/client_channel/lb_policy/xds/xds_client_stats.cc index a866d50b3a6..f2f06b467f2 100644 --- a/src/core/ext/filters/client_channel/lb_policy/xds/xds_client_stats.cc +++ b/src/core/ext/filters/client_channel/lb_policy/xds/xds_client_stats.cc @@ -143,15 +143,11 @@ XdsClientStats::Snapshot XdsClientStats::GetSnapshotAndReset() { } { MutexLock lock(&dropped_requests_mu_); -#if GRPC_USE_CPP_STD_LIB // This is a workaround for the case where some compilers cannot build // move-assignment of map with non-copyable but movable key. // https://stackoverflow.com/questions/36475497 std::swap(snapshot.dropped_requests, dropped_requests_); dropped_requests_.clear(); -#else - snapshot.dropped_requests = std::move(dropped_requests_); -#endif } return snapshot; } diff --git a/src/core/ext/filters/client_channel/lb_policy/xds/xds_load_balancer_api.cc b/src/core/ext/filters/client_channel/lb_policy/xds/xds_load_balancer_api.cc index a7666b34e53..9c6e4c553c7 100644 --- a/src/core/ext/filters/client_channel/lb_policy/xds/xds_load_balancer_api.cc +++ b/src/core/ext/filters/client_channel/lb_policy/xds/xds_load_balancer_api.cc @@ -346,15 +346,7 @@ grpc_slice XdsLrsRequestCreateAndEncode(const char* server_name) { namespace { void LocalityStatsPopulate(envoy_api_v2_endpoint_UpstreamLocalityStats* output, -#if GRPC_USE_CPP_STD_LIB - // TODO(veblush): Clean up this - // This is to address the difference between - // std::map and Map. #else block will be gone - // once using stdlib is enabled by default. Pair, -#else - Pair, -#endif XdsClientStats::LocalityStats::Snapshot>& input, upb_arena* arena) { // Set sub_zone. diff --git a/src/core/ext/filters/client_channel/lb_policy_factory.h b/src/core/ext/filters/client_channel/lb_policy_factory.h index 3b8c9faa180..3cd6d456714 100644 --- a/src/core/ext/filters/client_channel/lb_policy_factory.h +++ b/src/core/ext/filters/client_channel/lb_policy_factory.h @@ -22,7 +22,6 @@ #include #include "src/core/ext/filters/client_channel/lb_policy.h" -#include "src/core/lib/gprpp/abstract.h" #include "src/core/lib/gprpp/orphanable.h" namespace grpc_core { @@ -31,18 +30,16 @@ class LoadBalancingPolicyFactory { public: /// Returns a new LB policy instance. virtual OrphanablePtr CreateLoadBalancingPolicy( - LoadBalancingPolicy::Args) const GRPC_ABSTRACT; + LoadBalancingPolicy::Args) const = 0; /// Returns the LB policy name that this factory provides. /// Caller does NOT take ownership of result. - virtual const char* name() const GRPC_ABSTRACT; + virtual const char* name() const = 0; virtual RefCountedPtr ParseLoadBalancingConfig( - const grpc_json* json, grpc_error** error) const GRPC_ABSTRACT; + const grpc_json* json, grpc_error** error) const = 0; virtual ~LoadBalancingPolicyFactory() {} - - GRPC_ABSTRACT_BASE_CLASS; }; } // namespace grpc_core diff --git a/src/core/ext/filters/client_channel/resolver.h b/src/core/ext/filters/client_channel/resolver.h index 829a860040a..609d0a7a233 100644 --- a/src/core/ext/filters/client_channel/resolver.h +++ b/src/core/ext/filters/client_channel/resolver.h @@ -25,7 +25,6 @@ #include "src/core/ext/filters/client_channel/server_address.h" #include "src/core/ext/filters/client_channel/service_config.h" -#include "src/core/lib/gprpp/abstract.h" #include "src/core/lib/gprpp/orphanable.h" #include "src/core/lib/gprpp/ref_counted_ptr.h" #include "src/core/lib/iomgr/combiner.h" @@ -74,17 +73,15 @@ class Resolver : public InternallyRefCounted { /// Returns a result to the channel. /// Takes ownership of \a result.args. - virtual void ReturnResult(Result result) GRPC_ABSTRACT; // NOLINT + virtual void ReturnResult(Result result) = 0; // NOLINT /// Returns a transient error to the channel. /// If the resolver does not set the GRPC_ERROR_INT_GRPC_STATUS /// attribute on the error, calls will be failed with status UNKNOWN. - virtual void ReturnError(grpc_error* error) GRPC_ABSTRACT; + virtual void ReturnError(grpc_error* error) = 0; // TODO(yashkt): As part of the service config error handling // changes, add a method to parse the service config JSON string. - - GRPC_ABSTRACT_BASE_CLASS }; // Not copyable nor movable. @@ -92,7 +89,7 @@ class Resolver : public InternallyRefCounted { Resolver& operator=(const Resolver&) = delete; /// Starts resolving. - virtual void StartLocked() GRPC_ABSTRACT; + virtual void StartLocked() = 0; /// Asks the resolver to obtain an updated resolver result, if /// applicable. @@ -123,8 +120,6 @@ class Resolver : public InternallyRefCounted { Unref(); } - GRPC_ABSTRACT_BASE_CLASS - protected: GRPC_ALLOW_CLASS_TO_USE_NON_PUBLIC_DELETE @@ -138,7 +133,7 @@ class Resolver : public InternallyRefCounted { virtual ~Resolver(); /// Shuts down the resolver. - virtual void ShutdownLocked() GRPC_ABSTRACT; + virtual void ShutdownLocked() = 0; grpc_combiner* combiner() const { return combiner_; } diff --git a/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver.h b/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver.h index 2d172eb3d1e..fe51c34bc3e 100644 --- a/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver.h +++ b/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver.h @@ -23,7 +23,6 @@ #include #include "src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.h" -#include "src/core/lib/gprpp/abstract.h" #include "src/core/lib/iomgr/pollset_set.h" typedef struct grpc_ares_ev_driver grpc_ares_ev_driver; @@ -67,22 +66,18 @@ class GrpcPolledFd { public: virtual ~GrpcPolledFd() {} /* Called when c-ares library is interested and there's no pending callback */ - virtual void RegisterForOnReadableLocked(grpc_closure* read_closure) - GRPC_ABSTRACT; + virtual void RegisterForOnReadableLocked(grpc_closure* read_closure) = 0; /* Called when c-ares library is interested and there's no pending callback */ - virtual void RegisterForOnWriteableLocked(grpc_closure* write_closure) - GRPC_ABSTRACT; + virtual void RegisterForOnWriteableLocked(grpc_closure* write_closure) = 0; /* Indicates if there is data left even after just being read from */ - virtual bool IsFdStillReadableLocked() GRPC_ABSTRACT; + virtual bool IsFdStillReadableLocked() = 0; /* Called once and only once. Must cause cancellation of any pending * read/write callbacks. */ - virtual void ShutdownLocked(grpc_error* error) GRPC_ABSTRACT; + virtual void ShutdownLocked(grpc_error* error) = 0; /* Get the underlying ares_socket_t that this was created from */ - virtual ares_socket_t GetWrappedAresSocketLocked() GRPC_ABSTRACT; + virtual ares_socket_t GetWrappedAresSocketLocked() = 0; /* A unique name, for logging */ - virtual const char* GetName() GRPC_ABSTRACT; - - GRPC_ABSTRACT_BASE_CLASS + virtual const char* GetName() = 0; }; /* A GrpcPolledFdFactory is 1-to-1 with and owned by the @@ -95,11 +90,9 @@ class GrpcPolledFdFactory { /* Creates a new wrapped fd for the current platform */ virtual GrpcPolledFd* NewGrpcPolledFdLocked( ares_socket_t as, grpc_pollset_set* driver_pollset_set, - grpc_combiner* combiner) GRPC_ABSTRACT; + grpc_combiner* combiner) = 0; /* Optionally configures the ares channel after creation */ - virtual void ConfigureAresChannelLocked(ares_channel channel) GRPC_ABSTRACT; - - GRPC_ABSTRACT_BASE_CLASS + virtual void ConfigureAresChannelLocked(ares_channel channel) = 0; }; UniquePtr NewGrpcPolledFdFactory(grpc_combiner* combiner); diff --git a/src/core/ext/filters/client_channel/resolver_factory.h b/src/core/ext/filters/client_channel/resolver_factory.h index 7fed48b9570..7cee4879814 100644 --- a/src/core/ext/filters/client_channel/resolver_factory.h +++ b/src/core/ext/filters/client_channel/resolver_factory.h @@ -24,7 +24,6 @@ #include #include "src/core/ext/filters/client_channel/resolver.h" -#include "src/core/lib/gprpp/abstract.h" #include "src/core/lib/gprpp/memory.h" #include "src/core/lib/gprpp/orphanable.h" #include "src/core/lib/iomgr/pollset_set.h" @@ -49,11 +48,10 @@ class ResolverFactory { public: /// Returns a bool indicating whether the input uri is valid to create a /// resolver. - virtual bool IsValidUri(const grpc_uri* uri) const GRPC_ABSTRACT; + virtual bool IsValidUri(const grpc_uri* uri) const = 0; /// Returns a new resolver instance. - virtual OrphanablePtr CreateResolver(ResolverArgs args) const - GRPC_ABSTRACT; + virtual OrphanablePtr CreateResolver(ResolverArgs args) const = 0; /// Returns a string representing the default authority to use for this /// scheme. @@ -65,11 +63,9 @@ class ResolverFactory { /// Returns the URI scheme that this factory implements. /// Caller does NOT take ownership of result. - virtual const char* scheme() const GRPC_ABSTRACT; + virtual const char* scheme() const = 0; virtual ~ResolverFactory() {} - - GRPC_ABSTRACT_BASE_CLASS }; } // namespace grpc_core diff --git a/src/core/ext/filters/client_channel/service_config.h b/src/core/ext/filters/client_channel/service_config.h index 189a0b9bca2..f0206bf782e 100644 --- a/src/core/ext/filters/client_channel/service_config.h +++ b/src/core/ext/filters/client_channel/service_config.h @@ -62,8 +62,6 @@ class ServiceConfig : public RefCounted { class ParsedConfig { public: virtual ~ParsedConfig() = default; - - GRPC_ABSTRACT_BASE_CLASS; }; /// This is the base class that all service config parsers should derive from. @@ -82,8 +80,6 @@ class ServiceConfig : public RefCounted { GPR_DEBUG_ASSERT(error != nullptr); return nullptr; } - - GRPC_ABSTRACT_BASE_CLASS; }; static constexpr int kNumPreallocatedParsers = 4; diff --git a/src/core/ext/filters/client_channel/subchannel.h b/src/core/ext/filters/client_channel/subchannel.h index d6fb65814b7..7a039192085 100644 --- a/src/core/ext/filters/client_channel/subchannel.h +++ b/src/core/ext/filters/client_channel/subchannel.h @@ -192,11 +192,9 @@ class Subchannel { virtual void OnConnectivityStateChange( grpc_connectivity_state new_state, RefCountedPtr connected_subchannel) // NOLINT - GRPC_ABSTRACT; + = 0; - virtual grpc_pollset_set* interested_parties() GRPC_ABSTRACT; - - GRPC_ABSTRACT_BASE_CLASS + virtual grpc_pollset_set* interested_parties() = 0; }; // The ctor and dtor are not intended to use directly. diff --git a/src/core/ext/filters/client_channel/subchannel_interface.h b/src/core/ext/filters/client_channel/subchannel_interface.h index 2e448dc5a64..9ea3dfe4931 100644 --- a/src/core/ext/filters/client_channel/subchannel_interface.h +++ b/src/core/ext/filters/client_channel/subchannel_interface.h @@ -36,14 +36,12 @@ class SubchannelInterface : public RefCounted { // Will be invoked whenever the subchannel's connectivity state // changes. There will be only one invocation of this method on a // given watcher instance at any given time. - virtual void OnConnectivityStateChange(grpc_connectivity_state new_state) - GRPC_ABSTRACT; + virtual void OnConnectivityStateChange( + grpc_connectivity_state new_state) = 0; // TODO(roth): Remove this as soon as we move to EventManager-based // polling. - virtual grpc_pollset_set* interested_parties() GRPC_ABSTRACT; - - GRPC_ABSTRACT_BASE_CLASS + virtual grpc_pollset_set* interested_parties() = 0; }; template @@ -53,7 +51,7 @@ class SubchannelInterface : public RefCounted { virtual ~SubchannelInterface() = default; // Returns the current connectivity state of the subchannel. - virtual grpc_connectivity_state CheckConnectivityState() GRPC_ABSTRACT; + virtual grpc_connectivity_state CheckConnectivityState() = 0; // Starts watching the subchannel's connectivity state. // The first callback to the watcher will be delivered when the @@ -68,29 +66,27 @@ class SubchannelInterface : public RefCounted { // the previous watcher using CancelConnectivityStateWatch(). virtual void WatchConnectivityState( grpc_connectivity_state initial_state, - UniquePtr watcher) GRPC_ABSTRACT; + UniquePtr watcher) = 0; // Cancels a connectivity state watch. // If the watcher has already been destroyed, this is a no-op. virtual void CancelConnectivityStateWatch( - ConnectivityStateWatcherInterface* watcher) GRPC_ABSTRACT; + ConnectivityStateWatcherInterface* watcher) = 0; // Attempt to connect to the backend. Has no effect if already connected. // If the subchannel is currently in backoff delay due to a previously // failed attempt, the new connection attempt will not start until the // backoff delay has elapsed. - virtual void AttemptToConnect() GRPC_ABSTRACT; + virtual void AttemptToConnect() = 0; // Resets the subchannel's connection backoff state. If AttemptToConnect() // has been called since the subchannel entered TRANSIENT_FAILURE state, // starts a new connection attempt immediately; otherwise, a new connection // attempt will be started as soon as AttemptToConnect() is called. - virtual void ResetBackoff() GRPC_ABSTRACT; + virtual void ResetBackoff() = 0; // TODO(roth): Need a better non-grpc-specific abstraction here. - virtual const grpc_channel_args* channel_args() GRPC_ABSTRACT; - - GRPC_ABSTRACT_BASE_CLASS + virtual const grpc_channel_args* channel_args() = 0; }; } // namespace grpc_core diff --git a/src/core/ext/filters/client_channel/subchannel_pool_interface.h b/src/core/ext/filters/client_channel/subchannel_pool_interface.h index eeb56faf0c0..2fe5fa3fd05 100644 --- a/src/core/ext/filters/client_channel/subchannel_pool_interface.h +++ b/src/core/ext/filters/client_channel/subchannel_pool_interface.h @@ -23,7 +23,6 @@ #include "src/core/lib/avl/avl.h" #include "src/core/lib/channel/channel_args.h" -#include "src/core/lib/gprpp/abstract.h" #include "src/core/lib/gprpp/ref_counted.h" namespace grpc_core { @@ -70,14 +69,14 @@ class SubchannelPoolInterface : public RefCounted { // with \a key, which may be different from \a constructed because we reuse // (instead of update) any existing subchannel already registered with \a key. virtual Subchannel* RegisterSubchannel(SubchannelKey* key, - Subchannel* constructed) GRPC_ABSTRACT; + Subchannel* constructed) = 0; // Removes the registered subchannel found by \a key. - virtual void UnregisterSubchannel(SubchannelKey* key) GRPC_ABSTRACT; + virtual void UnregisterSubchannel(SubchannelKey* key) = 0; // Finds the subchannel registered for the given subchannel key. Returns NULL // if no such channel exists. Thread-safe. - virtual Subchannel* FindSubchannel(SubchannelKey* key) GRPC_ABSTRACT; + virtual Subchannel* FindSubchannel(SubchannelKey* key) = 0; // Creates a channel arg from \a subchannel pool. static grpc_arg CreateChannelArg(SubchannelPoolInterface* subchannel_pool); @@ -85,8 +84,6 @@ class SubchannelPoolInterface : public RefCounted { // Gets the subchannel pool from the channel args. static SubchannelPoolInterface* GetSubchannelPoolFromChannelArgs( const grpc_channel_args* args); - - GRPC_ABSTRACT_BASE_CLASS }; } // namespace grpc_core diff --git a/src/core/ext/transport/chttp2/transport/flow_control.h b/src/core/ext/transport/chttp2/transport/flow_control.h index 49e206fca3d..39ce1c51ec9 100644 --- a/src/core/ext/transport/chttp2/transport/flow_control.h +++ b/src/core/ext/transport/chttp2/transport/flow_control.h @@ -25,7 +25,6 @@ #include "src/core/ext/transport/chttp2/transport/http2_settings.h" #include "src/core/lib/gpr/useful.h" -#include "src/core/lib/gprpp/abstract.h" #include "src/core/lib/gprpp/manual_constructor.h" #include "src/core/lib/transport/bdp_estimator.h" #include "src/core/lib/transport/pid_controller.h" @@ -189,8 +188,6 @@ class TransportFlowControlBase { // factor virtual void TestOnlyForceHugeWindow() {} - GRPC_ABSTRACT_BASE_CLASS - protected: friend class ::grpc::testing::TrickledCHTTP2; int64_t remote_window_ = kDefaultWindow; @@ -385,8 +382,6 @@ class StreamFlowControlBase { int64_t local_window_delta() { return local_window_delta_; } int64_t announced_window_delta() { return announced_window_delta_; } - GRPC_ABSTRACT_BASE_CLASS - protected: friend class ::grpc::testing::TrickledCHTTP2; int64_t remote_window_delta_ = 0; diff --git a/src/core/lib/channel/channelz.h b/src/core/lib/channel/channelz.h index b023a5280e0..545b9ebeb88 100644 --- a/src/core/lib/channel/channelz.h +++ b/src/core/lib/channel/channelz.h @@ -88,7 +88,7 @@ class BaseNode : public RefCounted { virtual ~BaseNode(); // All children must implement this function. - virtual grpc_json* RenderJson() GRPC_ABSTRACT; + virtual grpc_json* RenderJson() = 0; // Renders the json and returns allocated string that must be freed by the // caller. diff --git a/src/core/lib/channel/handshaker.h b/src/core/lib/channel/handshaker.h index b68799b6e0e..4f064d901df 100644 --- a/src/core/lib/channel/handshaker.h +++ b/src/core/lib/channel/handshaker.h @@ -77,12 +77,11 @@ struct HandshakerArgs { class Handshaker : public RefCounted { public: virtual ~Handshaker() = default; - virtual void Shutdown(grpc_error* why) GRPC_ABSTRACT; + virtual void Shutdown(grpc_error* why) = 0; virtual void DoHandshake(grpc_tcp_server_acceptor* acceptor, grpc_closure* on_handshake_done, - HandshakerArgs* args) GRPC_ABSTRACT; - virtual const char* name() const GRPC_ABSTRACT; - GRPC_ABSTRACT_BASE_CLASS + HandshakerArgs* args) = 0; + virtual const char* name() const = 0; }; // diff --git a/src/core/lib/channel/handshaker_factory.h b/src/core/lib/channel/handshaker_factory.h index 3972af1f439..520e5e4b258 100644 --- a/src/core/lib/channel/handshaker_factory.h +++ b/src/core/lib/channel/handshaker_factory.h @@ -33,10 +33,8 @@ class HandshakerFactory { public: virtual void AddHandshakers(const grpc_channel_args* args, grpc_pollset_set* interested_parties, - HandshakeManager* handshake_mgr) GRPC_ABSTRACT; + HandshakeManager* handshake_mgr) = 0; virtual ~HandshakerFactory() = default; - - GRPC_ABSTRACT_BASE_CLASS }; } // namespace grpc_core diff --git a/src/core/lib/gprpp/abstract.h b/src/core/lib/gprpp/abstract.h deleted file mode 100644 index ea68e3ab041..00000000000 --- a/src/core/lib/gprpp/abstract.h +++ /dev/null @@ -1,47 +0,0 @@ -/* - * - * Copyright 2017 gRPC authors. - * - * 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. - * - */ - -#ifndef GRPC_CORE_LIB_GPRPP_ABSTRACT_H -#define GRPC_CORE_LIB_GPRPP_ABSTRACT_H - -#if GRPC_USE_CPP_STD_LIB - -#define GRPC_ABSTRACT_BASE_CLASS - -#define GRPC_ABSTRACT = 0 - -#else - -// This is needed to support abstract base classes in the c core. Since gRPC -// doesn't have a c++ runtime, it will hit a linker error on delete unless -// we define a virtual operator delete. See this blog for more info: -// https://eli.thegreenplace.net/2015/c-deleting-destructors-and-virtual-operator-delete/ -#define GRPC_ABSTRACT_BASE_CLASS \ - static void operator delete(void* p) { abort(); } - -// gRPC currently can't depend on libstdc++, so we can't use "= 0" for -// pure virtual methods. Instead, we use this macro. -#define GRPC_ABSTRACT \ - { \ - gpr_log(GPR_ERROR, "Function marked GRPC_ABSTRACT was not implemented"); \ - GPR_ASSERT(false); \ - } - -#endif // GRPC_USE_CPP_STD_LIB - -#endif /* GRPC_CORE_LIB_GPRPP_ABSTRACT_H */ diff --git a/src/core/lib/gprpp/map.h b/src/core/lib/gprpp/map.h index 6a41a97bec2..4537012c903 100644 --- a/src/core/lib/gprpp/map.h +++ b/src/core/lib/gprpp/map.h @@ -26,10 +26,7 @@ #include #include #include - -#if GRPC_USE_CPP_STD_LIB #include -#endif #include "src/core/lib/gpr/useful.h" #include "src/core/lib/gprpp/memory.h" @@ -62,503 +59,9 @@ struct RefCountedPtrLess { } }; -#if GRPC_USE_CPP_STD_LIB - template > using Map = std::map; -#else // GRPC_USE_CPP_STD_LIB - -namespace testing { -class MapTest; -} - -// Alternative map implementation for grpc_core -template > -class Map { - public: - typedef Key key_type; - typedef T mapped_type; - typedef Pair value_type; - typedef Compare key_compare; - class iterator; - class const_iterator; - - Map() = default; - ~Map() { clear(); } - - // Movable. - Map(Map&& other) : root_(other.root_), size_(other.size_) { - other.root_ = nullptr; - other.size_ = 0; - } - Map& operator=(Map&& other) { - if (this != &other) { - clear(); - root_ = other.root_; - size_ = other.size_; - other.root_ = nullptr; - other.size_ = 0; - } - return *this; - } - - // Copyable. - Map(const Map& other) { - for (const auto& p : other) { - emplace(p); - } - } - Map& operator=(const Map& other) { - if (this != &other) { - clear(); - for (const auto& p : other) { - emplace(p); - } - } - return *this; - } - - T& operator[](key_type&& key); - T& operator[](const key_type& key); - iterator find(const key_type& k); - size_t erase(const key_type& key); - // Removes the current entry and points to the next one - iterator erase(iterator iter); - - size_t size() const { return size_; } - - template - Pair emplace(Args&&... args); - - Pair insert(value_type&& pair) { - return emplace(std::move(pair)); - } - - Pair insert(const value_type& pair) { return emplace(pair); } - - bool empty() const { return root_ == nullptr; } - - void clear() { - auto iter = begin(); - while (!empty()) { - iter = erase(iter); - } - } - - iterator begin() { - Entry* curr = GetMinEntry(root_); - return iterator(this, curr); - } - - iterator end() { return iterator(this, nullptr); } - - const_iterator begin() const { - Entry* curr = GetMinEntry(root_); - return const_iterator(this, curr); - } - - const_iterator end() const { return const_iterator(this, nullptr); } - - iterator lower_bound(const Key& k) { - // This is a workaround for "const key_compare compare;" - // because some versions of compilers cannot build this by requiring - // a user-provided constructor. (ref: https://stackoverflow.com/q/7411515) - key_compare compare_tmp; - const key_compare& compare = compare_tmp; - return std::find_if(begin(), end(), [&k, &compare](const value_type& v) { - return !compare(v.first, k); - }); - } - - private: - friend class testing::MapTest; - struct Entry { - explicit Entry(value_type&& pair) : pair(std::move(pair)) {} - value_type pair; - Entry* left = nullptr; - Entry* right = nullptr; - int32_t height = 1; - }; - - static int32_t EntryHeight(const Entry* e) { - return e == nullptr ? 0 : e->height; - } - - static Entry* GetMinEntry(Entry* e); - Entry* InOrderSuccessor(const Entry* e) const; - static Entry* RotateLeft(Entry* e); - static Entry* RotateRight(Entry* e); - static Entry* RebalanceTreeAfterInsertion(Entry* root, const key_type& k); - static Entry* RebalanceTreeAfterDeletion(Entry* root); - // Returns a pair with the first value being an iterator pointing to the - // inserted entry and the second value being the new root of the subtree - // after a rebalance - Pair InsertRecursive(Entry* root, value_type&& p); - // Returns a pair with the first value being an iterator pointing to the - // successor of the deleted entry and the second value being the new root of - // the subtree after a rebalance - Pair RemoveRecursive(Entry* root, const key_type& k); - // Return 0 if lhs = rhs - // 1 if lhs > rhs - // -1 if lhs < rhs - static int CompareKeys(const Key& lhs, const Key& rhs); - - Entry* root_ = nullptr; - size_t size_ = 0; -}; - -template -class Map::iterator - : public std::iterator, int32_t, - Pair*, Pair&> { - public: - iterator(const iterator& iter) : curr_(iter.curr_), map_(iter.map_) {} - bool operator==(const iterator& rhs) const { return (curr_ == rhs.curr_); } - bool operator!=(const iterator& rhs) const { return (curr_ != rhs.curr_); } - - iterator& operator++() { - curr_ = map_->InOrderSuccessor(curr_); - return *this; - } - - iterator operator++(int) { - Entry* prev = curr_; - curr_ = map_->InOrderSuccessor(curr_); - return iterator(map_, prev); - } - - iterator& operator=(const iterator& other) { - if (this != &other) { - this->curr_ = other.curr_; - this->map_ = other.map_; - } - return *this; - } - - // operator*() - value_type& operator*() { return curr_->pair; } - const value_type& operator*() const { return curr_->pair; } - - // operator->() - value_type* operator->() { return &curr_->pair; } - value_type const* operator->() const { return &curr_->pair; } - - private: - friend class Map; - using GrpcMap = typename ::grpc_core::Map; - iterator(GrpcMap* map, Entry* curr) : curr_(curr), map_(map) {} - Entry* curr_; - GrpcMap* map_; -}; - -template -class Map::const_iterator - : public std::iterator, int32_t, - Pair*, Pair&> { - public: - const_iterator(const const_iterator& iter) - : curr_(iter.curr_), map_(iter.map_) {} - bool operator==(const const_iterator& rhs) const { - return (curr_ == rhs.curr_); - } - bool operator!=(const const_iterator& rhs) const { - return (curr_ != rhs.curr_); - } - - const_iterator& operator++() { - curr_ = map_->InOrderSuccessor(curr_); - return *this; - } - - const_iterator operator++(int) { - Entry* prev = curr_; - curr_ = map_->InOrderSuccessor(curr_); - return const_iterator(map_, prev); - } - - const_iterator& operator=(const const_iterator& other) { - if (this != &other) { - this->curr_ = other.curr_; - this->map_ = other.map_; - } - return *this; - } - - // operator*() - const value_type& operator*() const { return curr_->pair; } - - // operator->() - const value_type* operator->() const { return &curr_->pair; } - - private: - friend class Map; - using GrpcMap = typename ::grpc_core::Map; - const_iterator(const GrpcMap* map, Entry* curr) : curr_(curr), map_(map) {} - Entry* curr_; - const GrpcMap* map_; -}; - -template -T& Map::operator[](key_type&& key) { - auto iter = find(key); - if (iter == end()) { - return emplace(std::move(key), T()).first->second; - } - return iter->second; -} - -template -T& Map::operator[](const key_type& key) { - auto iter = find(key); - if (iter == end()) { - return emplace(key, T()).first->second; - } - return iter->second; -} - -template -typename Map::iterator Map::find( - const key_type& k) { - Entry* iter = root_; - while (iter != nullptr) { - int comp = CompareKeys(iter->pair.first, k); - if (comp == 0) { - return iterator(this, iter); - } else if (comp < 0) { - iter = iter->right; - } else { - iter = iter->left; - } - } - return end(); -} - -template -template -typename ::grpc_core::Pair::iterator, bool> -Map::emplace(Args&&... args) { - Pair pair(std::forward(args)...); - iterator ret = find(pair.first); - bool insertion = false; - if (ret == end()) { - Pair p = InsertRecursive(root_, std::move(pair)); - root_ = p.second; - ret = p.first; - insertion = true; - size_++; - } - return MakePair(ret, insertion); -} - -template -size_t Map::erase(const key_type& key) { - iterator it = find(key); - if (it == end()) return 0; - erase(it); - return 1; -} - -// TODO(mhaidry): Modify erase to use the iterator location -// to create an efficient erase method -template -typename Map::iterator Map::erase( - iterator iter) { - if (iter == end()) return iter; - key_type& del_key = iter->first; - Pair ret = RemoveRecursive(root_, del_key); - root_ = ret.second; - size_--; - return ret.first; -} - -template -typename Map::Entry* Map::InOrderSuccessor( - const Entry* e) const { - if (e->right != nullptr) { - return GetMinEntry(e->right); - } - Entry* successor = nullptr; - Entry* iter = root_; - while (iter != nullptr) { - int comp = CompareKeys(iter->pair.first, e->pair.first); - if (comp > 0) { - successor = iter; - iter = iter->left; - } else if (comp < 0) { - iter = iter->right; - } else - break; - } - return successor; -} - -// Returns a pair with the first value being an iterator pointing to the -// inserted entry and the second value being the new root of the subtree -// after a rebalance -template -typename ::grpc_core::Pair::iterator, - typename Map::Entry*> -Map::InsertRecursive(Entry* root, value_type&& p) { - if (root == nullptr) { - Entry* e = New(std::move(p)); - return MakePair(iterator(this, e), e); - } - int comp = CompareKeys(root->pair.first, p.first); - if (comp > 0) { - Pair ret = InsertRecursive(root->left, std::move(p)); - root->left = ret.second; - ret.second = RebalanceTreeAfterInsertion(root, ret.first->first); - return ret; - } else if (comp < 0) { - Pair ret = InsertRecursive(root->right, std::move(p)); - root->right = ret.second; - ret.second = RebalanceTreeAfterInsertion(root, ret.first->first); - return ret; - } else { - root->pair = std::move(p); - return MakePair(iterator(this, root), root); - } -} - -template -typename Map::Entry* Map::GetMinEntry( - Entry* e) { - if (e != nullptr) { - while (e->left != nullptr) { - e = e->left; - } - } - return e; -} - -template -typename Map::Entry* Map::RotateLeft( - Entry* e) { - Entry* rightChild = e->right; - Entry* rightLeftChild = rightChild->left; - rightChild->left = e; - e->right = rightLeftChild; - e->height = 1 + GPR_MAX(EntryHeight(e->left), EntryHeight(e->right)); - rightChild->height = 1 + GPR_MAX(EntryHeight(rightChild->left), - EntryHeight(rightChild->right)); - return rightChild; -} - -template -typename Map::Entry* Map::RotateRight( - Entry* e) { - Entry* leftChild = e->left; - Entry* leftRightChild = leftChild->right; - leftChild->right = e; - e->left = leftRightChild; - e->height = 1 + GPR_MAX(EntryHeight(e->left), EntryHeight(e->right)); - leftChild->height = - 1 + GPR_MAX(EntryHeight(leftChild->left), EntryHeight(leftChild->right)); - return leftChild; -} - -template -typename Map::Entry* -Map::RebalanceTreeAfterInsertion(Entry* root, - const key_type& k) { - root->height = 1 + GPR_MAX(EntryHeight(root->left), EntryHeight(root->right)); - int32_t heightDifference = EntryHeight(root->left) - EntryHeight(root->right); - if (heightDifference > 1 && CompareKeys(root->left->pair.first, k) > 0) { - return RotateRight(root); - } - if (heightDifference < -1 && CompareKeys(root->right->pair.first, k) < 0) { - return RotateLeft(root); - } - if (heightDifference > 1 && CompareKeys(root->left->pair.first, k) < 0) { - root->left = RotateLeft(root->left); - return RotateRight(root); - } - if (heightDifference < -1 && CompareKeys(root->right->pair.first, k) > 0) { - root->right = RotateRight(root->right); - return RotateLeft(root); - } - return root; -} - -template -typename Map::Entry* -Map::RebalanceTreeAfterDeletion(Entry* root) { - root->height = 1 + GPR_MAX(EntryHeight(root->left), EntryHeight(root->right)); - int32_t heightDifference = EntryHeight(root->left) - EntryHeight(root->right); - if (heightDifference > 1) { - int leftHeightDifference = - EntryHeight(root->left->left) - EntryHeight(root->left->right); - if (leftHeightDifference < 0) { - root->left = RotateLeft(root->left); - } - return RotateRight(root); - } - if (heightDifference < -1) { - int rightHeightDifference = - EntryHeight(root->right->left) - EntryHeight(root->right->right); - if (rightHeightDifference > 0) { - root->right = RotateRight(root->right); - } - return RotateLeft(root); - } - return root; -} - -template -typename ::grpc_core::Pair::iterator, - typename Map::Entry*> -Map::RemoveRecursive(Entry* root, const key_type& k) { - Pair ret = MakePair(end(), root); - if (root == nullptr) return ret; - int comp = CompareKeys(root->pair.first, k); - if (comp > 0) { - ret = RemoveRecursive(root->left, k); - root->left = ret.second; - } else if (comp < 0) { - ret = RemoveRecursive(root->right, k); - root->right = ret.second; - } else { - Entry* entry; - Entry* successor = InOrderSuccessor(root); - if (root->left == nullptr) { - entry = root->right; - Delete(root); - return MakePair(iterator(this, successor), entry); - } else if (root->right == nullptr) { - entry = root->left; - Delete(root); - return MakePair(iterator(this, successor), entry); - } else { - entry = successor; - root->pair.swap(entry->pair); - ret = RemoveRecursive(root->right, entry->pair.first); - root->right = ret.second; - ret.first = iterator(this, root); - } - } - return MakePair(ret.first, RebalanceTreeAfterDeletion(root)); -} - -template -int Map::CompareKeys(const key_type& lhs, - const key_type& rhs) { - // This is a workaround for "const key_compare compare;" - // because some versions of compilers cannot build this by requiring - // a user-provided constructor. (ref: https://stackoverflow.com/q/7411515) - key_compare compare_tmp; - const key_compare& compare = compare_tmp; - bool left_comparison = compare(lhs, rhs); - bool right_comparison = compare(rhs, lhs); - // Both values are equal - if (!left_comparison && !right_comparison) { - return 0; - } - return left_comparison ? -1 : 1; -} - -#endif // GRPC_USE_CPP_STD_LIB - } // namespace grpc_core #endif /* GRPC_CORE_LIB_GPRPP_MAP_H */ diff --git a/src/core/lib/gprpp/orphanable.h b/src/core/lib/gprpp/orphanable.h index ab02d80827b..03511e8a4db 100644 --- a/src/core/lib/gprpp/orphanable.h +++ b/src/core/lib/gprpp/orphanable.h @@ -28,7 +28,6 @@ #include #include "src/core/lib/debug/trace.h" -#include "src/core/lib/gprpp/abstract.h" #include "src/core/lib/gprpp/debug_location.h" #include "src/core/lib/gprpp/memory.h" #include "src/core/lib/gprpp/ref_counted.h" @@ -46,14 +45,12 @@ class Orphanable { // Gives up ownership of the object. The implementation must arrange // to eventually destroy the object without further interaction from the // caller. - virtual void Orphan() GRPC_ABSTRACT; + virtual void Orphan() = 0; // Not copyable or movable. Orphanable(const Orphanable&) = delete; Orphanable& operator=(const Orphanable&) = delete; - GRPC_ABSTRACT_BASE_CLASS - protected: Orphanable() {} virtual ~Orphanable() {} @@ -83,8 +80,6 @@ class InternallyRefCounted : public Orphanable { InternallyRefCounted(const InternallyRefCounted&) = delete; InternallyRefCounted& operator=(const InternallyRefCounted&) = delete; - GRPC_ABSTRACT_BASE_CLASS - protected: GRPC_ALLOW_CLASS_TO_USE_NON_PUBLIC_DELETE diff --git a/src/core/lib/gprpp/ref_counted.h b/src/core/lib/gprpp/ref_counted.h index 5c7a5cf0735..2ae92949128 100644 --- a/src/core/lib/gprpp/ref_counted.h +++ b/src/core/lib/gprpp/ref_counted.h @@ -30,7 +30,6 @@ #include #include "src/core/lib/debug/trace.h" -#include "src/core/lib/gprpp/abstract.h" #include "src/core/lib/gprpp/atomic.h" #include "src/core/lib/gprpp/debug_location.h" #include "src/core/lib/gprpp/memory.h" @@ -41,8 +40,6 @@ namespace grpc_core { // PolymorphicRefCount enforces polymorphic destruction of RefCounted. class PolymorphicRefCount { public: - GRPC_ABSTRACT_BASE_CLASS - protected: GRPC_ALLOW_CLASS_TO_USE_NON_PUBLIC_DELETE @@ -54,8 +51,6 @@ class PolymorphicRefCount { // when in doubt use PolymorphicRefCount. class NonPolymorphicRefCount { public: - GRPC_ABSTRACT_BASE_CLASS - protected: GRPC_ALLOW_CLASS_TO_USE_NON_PUBLIC_DELETE @@ -272,8 +267,6 @@ class RefCounted : public Impl { RefCounted(const RefCounted&) = delete; RefCounted& operator=(const RefCounted&) = delete; - GRPC_ABSTRACT_BASE_CLASS - protected: GRPC_ALLOW_CLASS_TO_USE_NON_PUBLIC_DELETE diff --git a/src/core/lib/gprpp/thd.h b/src/core/lib/gprpp/thd.h index 0af33faa119..223e4115b87 100644 --- a/src/core/lib/gprpp/thd.h +++ b/src/core/lib/gprpp/thd.h @@ -28,7 +28,6 @@ #include #include -#include "src/core/lib/gprpp/abstract.h" #include "src/core/lib/gprpp/memory.h" namespace grpc_core { @@ -38,9 +37,8 @@ namespace internal { class ThreadInternalsInterface { public: virtual ~ThreadInternalsInterface() {} - virtual void Start() GRPC_ABSTRACT; - virtual void Join() GRPC_ABSTRACT; - GRPC_ABSTRACT_BASE_CLASS + virtual void Start() = 0; + virtual void Join() = 0; }; } // namespace internal diff --git a/src/core/lib/iomgr/executor/mpmcqueue.h b/src/core/lib/iomgr/executor/mpmcqueue.h index ab5c484e094..474f40bbf87 100644 --- a/src/core/lib/iomgr/executor/mpmcqueue.h +++ b/src/core/lib/iomgr/executor/mpmcqueue.h @@ -22,7 +22,6 @@ #include #include "src/core/lib/debug/stats.h" -#include "src/core/lib/gprpp/abstract.h" #include "src/core/lib/gprpp/atomic.h" #include "src/core/lib/gprpp/sync.h" @@ -38,17 +37,15 @@ class MPMCQueueInterface { // Puts elem into queue immediately at the end of queue. // This might cause to block on full queue depending on implementation. - virtual void Put(void* elem) GRPC_ABSTRACT; + virtual void Put(void* elem) = 0; // Removes the oldest element from the queue and return it. // This might cause to block on empty queue depending on implementation. // Optional argument for collecting stats purpose. - virtual void* Get(gpr_timespec* wait_time = nullptr) GRPC_ABSTRACT; + virtual void* Get(gpr_timespec* wait_time = nullptr) = 0; // Returns number of elements in the queue currently - virtual int count() const GRPC_ABSTRACT; - - GRPC_ABSTRACT_BASE_CLASS + virtual int count() const = 0; }; class InfLenFIFOQueue : public MPMCQueueInterface { diff --git a/src/core/lib/iomgr/executor/threadpool.h b/src/core/lib/iomgr/executor/threadpool.h index 7b33fb32f36..0402c6ddf0e 100644 --- a/src/core/lib/iomgr/executor/threadpool.h +++ b/src/core/lib/iomgr/executor/threadpool.h @@ -43,22 +43,19 @@ class ThreadPoolInterface { // current thread to be blocked (in case of unable to schedule). // Closure should contain a function pointer and arguments it will take, more // details for closure struct at /grpc/include/grpc/impl/codegen/grpc_types.h - virtual void Add(grpc_experimental_completion_queue_functor* closure) - GRPC_ABSTRACT; + virtual void Add(grpc_experimental_completion_queue_functor* closure) = 0; // Returns the current number of pending closures - virtual int num_pending_closures() const GRPC_ABSTRACT; + virtual int num_pending_closures() const = 0; // Returns the capacity of pool (number of worker threads in pool) - virtual int pool_capacity() const GRPC_ABSTRACT; + virtual int pool_capacity() const = 0; // Thread option accessor - virtual const Thread::Options& thread_options() const GRPC_ABSTRACT; + virtual const Thread::Options& thread_options() const = 0; // Returns the thread name for threads in this ThreadPool. - virtual const char* thread_name() const GRPC_ABSTRACT; - - GRPC_ABSTRACT_BASE_CLASS + virtual const char* thread_name() const = 0; }; // Worker thread for threadpool. Executes closures in the queue, until getting a diff --git a/src/core/lib/iomgr/tcp_server.h b/src/core/lib/iomgr/tcp_server.h index 0d16b66230f..0af8a7953ed 100644 --- a/src/core/lib/iomgr/tcp_server.h +++ b/src/core/lib/iomgr/tcp_server.h @@ -24,7 +24,6 @@ #include #include -#include "src/core/lib/gprpp/abstract.h" #include "src/core/lib/iomgr/closure.h" #include "src/core/lib/iomgr/endpoint.h" #include "src/core/lib/iomgr/resolve_address.h" @@ -57,9 +56,7 @@ class TcpServerFdHandler { public: virtual ~TcpServerFdHandler() = default; virtual void Handle(int listener_fd, int fd, - grpc_byte_buffer* pending_read) GRPC_ABSTRACT; - - GRPC_ABSTRACT_BASE_CLASS; + grpc_byte_buffer* pending_read) = 0; }; } // namespace grpc_core diff --git a/src/core/lib/iomgr/udp_server.h b/src/core/lib/iomgr/udp_server.h index 3656791c1f8..759917ee4e4 100644 --- a/src/core/lib/iomgr/udp_server.h +++ b/src/core/lib/iomgr/udp_server.h @@ -21,7 +21,6 @@ #include -#include "src/core/lib/gprpp/abstract.h" #include "src/core/lib/iomgr/endpoint.h" #include "src/core/lib/iomgr/ev_posix.h" #include "src/core/lib/iomgr/resolve_address.h" @@ -47,18 +46,16 @@ class GrpcUdpHandler { // Called when data is available to read from the socket. Returns true if // there is more data to read after this call. - virtual bool Read() GRPC_ABSTRACT; + virtual bool Read() = 0; // Called when socket becomes write unblocked. The given closure should be // scheduled when the socket becomes blocked next time. virtual void OnCanWrite(void* user_data, - grpc_closure* notify_on_write_closure) GRPC_ABSTRACT; + grpc_closure* notify_on_write_closure) = 0; // Called before the gRPC FD is orphaned. Notify udp server to continue // orphaning fd by scheduling the given closure, afterwards the associated fd // will be closed. virtual void OnFdAboutToOrphan(grpc_closure* orphan_fd_closure, - void* user_data) GRPC_ABSTRACT; - - GRPC_ABSTRACT_BASE_CLASS + void* user_data) = 0; }; class GrpcUdpHandlerFactory { @@ -67,11 +64,8 @@ class GrpcUdpHandlerFactory { /* Called when start to listen on a socket. * Return an instance of the implementation of GrpcUdpHandler interface which * will process I/O events for this socket from now on. */ - virtual GrpcUdpHandler* CreateUdpHandler(grpc_fd* emfd, - void* user_data) GRPC_ABSTRACT; - virtual void DestroyUdpHandler(GrpcUdpHandler* handler) GRPC_ABSTRACT; - - GRPC_ABSTRACT_BASE_CLASS + virtual GrpcUdpHandler* CreateUdpHandler(grpc_fd* emfd, void* user_data) = 0; + virtual void DestroyUdpHandler(GrpcUdpHandler* handler) = 0; }; /* Create a server, initially not bound to any ports */ diff --git a/src/core/lib/security/credentials/credentials.h b/src/core/lib/security/credentials/credentials.h index b43405b0861..16f0454907b 100644 --- a/src/core/lib/security/credentials/credentials.h +++ b/src/core/lib/security/credentials/credentials.h @@ -110,17 +110,7 @@ struct grpc_channel_credentials create_security_connector( grpc_core::RefCountedPtr call_creds, const char* target, const grpc_channel_args* args, - grpc_channel_args** new_args) -#if GRPC_USE_CPP_STD_LIB - = 0; -#else - { - // Tell clang-tidy that call_creds cannot be passed as const-ref. - call_creds.reset(); - gpr_log(GPR_ERROR, "Function marked GRPC_ABSTRACT was not implemented"); - GPR_ASSERT(false); - } -#endif + grpc_channel_args** new_args) = 0; // Creates a version of the channel credentials without any attached call // credentials. This can be used in order to open a channel to a non-trusted @@ -156,8 +146,6 @@ struct grpc_channel_credentials const char* type() const { return type_; } - GRPC_ABSTRACT_BASE_CLASS - private: const char* type_; grpc_core::Map, @@ -248,18 +236,16 @@ struct grpc_call_credentials grpc_auth_metadata_context context, grpc_credentials_mdelem_array* md_array, grpc_closure* on_request_metadata, - grpc_error** error) GRPC_ABSTRACT; + grpc_error** error) = 0; // Cancels a pending asynchronous operation started by // grpc_call_credentials_get_request_metadata() with the corresponding // value of \a md_array. virtual void cancel_get_request_metadata( - grpc_credentials_mdelem_array* md_array, grpc_error* error) GRPC_ABSTRACT; + grpc_credentials_mdelem_array* md_array, grpc_error* error) = 0; const char* type() const { return type_; } - GRPC_ABSTRACT_BASE_CLASS - private: const char* type_; }; @@ -282,7 +268,7 @@ struct grpc_server_credentials virtual ~grpc_server_credentials() { DestroyProcessor(); } virtual grpc_core::RefCountedPtr - create_security_connector() GRPC_ABSTRACT; + create_security_connector() = 0; const char* type() const { return type_; } @@ -292,8 +278,6 @@ struct grpc_server_credentials void set_auth_metadata_processor( const grpc_auth_metadata_processor& processor); - GRPC_ABSTRACT_BASE_CLASS - private: void DestroyProcessor() { if (processor_.destroy != nullptr && processor_.state != nullptr) { diff --git a/src/core/lib/security/credentials/oauth2/oauth2_credentials.h b/src/core/lib/security/credentials/oauth2/oauth2_credentials.h index c9b2d1decac..ba07ee04ee7 100644 --- a/src/core/lib/security/credentials/oauth2/oauth2_credentials.h +++ b/src/core/lib/security/credentials/oauth2/oauth2_credentials.h @@ -85,13 +85,11 @@ class grpc_oauth2_token_fetcher_credentials : public grpc_call_credentials { void on_http_response(grpc_credentials_metadata_request* r, grpc_error* error); - GRPC_ABSTRACT_BASE_CLASS - protected: virtual void fetch_oauth2(grpc_credentials_metadata_request* req, grpc_httpcli_context* httpcli_context, grpc_polling_entity* pollent, grpc_iomgr_cb_func cb, - grpc_millis deadline) GRPC_ABSTRACT; + grpc_millis deadline) = 0; private: gpr_mu mu_; diff --git a/src/core/lib/security/security_connector/security_connector.h b/src/core/lib/security/security_connector/security_connector.h index 2e573d65dfe..39e56bcc59a 100644 --- a/src/core/lib/security/security_connector/security_connector.h +++ b/src/core/lib/security/security_connector/security_connector.h @@ -58,15 +58,13 @@ class grpc_security_connector virtual void check_peer( tsi_peer peer, grpc_endpoint* ep, grpc_core::RefCountedPtr* auth_context, - grpc_closure* on_peer_checked) GRPC_ABSTRACT; + grpc_closure* on_peer_checked) = 0; /* Compares two security connectors. */ - virtual int cmp(const grpc_security_connector* other) const GRPC_ABSTRACT; + virtual int cmp(const grpc_security_connector* other) const = 0; const char* url_scheme() const { return url_scheme_; } - GRPC_ABSTRACT_BASE_CLASS - private: const char* url_scheme_; }; @@ -103,16 +101,16 @@ class grpc_channel_security_connector : public grpc_security_connector { virtual bool check_call_host(grpc_core::StringView host, grpc_auth_context* auth_context, grpc_closure* on_call_host_checked, - grpc_error** error) GRPC_ABSTRACT; + grpc_error** error) = 0; /// Cancels a pending asynchronous call to /// grpc_channel_security_connector_check_call_host() with /// \a on_call_host_checked as its callback. virtual void cancel_check_call_host(grpc_closure* on_call_host_checked, - grpc_error* error) GRPC_ABSTRACT; + grpc_error* error) = 0; /// Registers handshakers with \a handshake_mgr. - virtual void add_handshakers( - const grpc_channel_args* args, grpc_pollset_set* interested_parties, - grpc_core::HandshakeManager* handshake_mgr) GRPC_ABSTRACT; + virtual void add_handshakers(const grpc_channel_args* args, + grpc_pollset_set* interested_parties, + grpc_core::HandshakeManager* handshake_mgr) = 0; const grpc_channel_credentials* channel_creds() const { return channel_creds_.get(); @@ -127,8 +125,6 @@ class grpc_channel_security_connector : public grpc_security_connector { return request_metadata_creds_.get(); } - GRPC_ABSTRACT_BASE_CLASS - protected: // Helper methods to be used in subclasses. int channel_security_connector_cmp( @@ -157,9 +153,9 @@ class grpc_server_security_connector : public grpc_security_connector { grpc_core::RefCountedPtr server_creds); ~grpc_server_security_connector() override = default; - virtual void add_handshakers( - const grpc_channel_args* args, grpc_pollset_set* interested_parties, - grpc_core::HandshakeManager* handshake_mgr) GRPC_ABSTRACT; + virtual void add_handshakers(const grpc_channel_args* args, + grpc_pollset_set* interested_parties, + grpc_core::HandshakeManager* handshake_mgr) = 0; const grpc_server_credentials* server_creds() const { return server_creds_.get(); @@ -168,8 +164,6 @@ class grpc_server_security_connector : public grpc_security_connector { return server_creds_.get(); } - GRPC_ABSTRACT_BASE_CLASS - protected: // Helper methods to be used in subclasses. int server_security_connector_cmp( diff --git a/src/core/lib/surface/completion_queue.h b/src/core/lib/surface/completion_queue.h index dc13bc50f91..4a114be8285 100644 --- a/src/core/lib/surface/completion_queue.h +++ b/src/core/lib/surface/completion_queue.h @@ -26,7 +26,6 @@ #include #include "src/core/lib/debug/trace.h" -#include "src/core/lib/gprpp/abstract.h" #include "src/core/lib/gprpp/manual_constructor.h" #include "src/core/lib/iomgr/pollset.h" diff --git a/src/core/lib/transport/byte_stream.h b/src/core/lib/transport/byte_stream.h index 06503015d2c..5ffa63bad1a 100644 --- a/src/core/lib/transport/byte_stream.h +++ b/src/core/lib/transport/byte_stream.h @@ -22,7 +22,6 @@ #include #include -#include "src/core/lib/gprpp/abstract.h" #include "src/core/lib/gprpp/orphanable.h" #include "src/core/lib/iomgr/closure.h" @@ -45,14 +44,13 @@ class ByteStream : public Orphanable { // // max_size_hint can be set as a hint as to the maximum number // of bytes that would be acceptable to read. - virtual bool Next(size_t max_size_hint, - grpc_closure* on_complete) GRPC_ABSTRACT; + virtual bool Next(size_t max_size_hint, grpc_closure* on_complete) = 0; // Returns the next slice in the byte stream when it is available, as // indicated by Next(). // // Once a slice is returned into *slice, it is owned by the caller. - virtual grpc_error* Pull(grpc_slice* slice) GRPC_ABSTRACT; + virtual grpc_error* Pull(grpc_slice* slice) = 0; // Shuts down the byte stream. // @@ -61,15 +59,13 @@ class ByteStream : public Orphanable { // // The next call to Pull() (if any) will return the error passed to // Shutdown(). - virtual void Shutdown(grpc_error* error) GRPC_ABSTRACT; + virtual void Shutdown(grpc_error* error) = 0; uint32_t length() const { return length_; } uint32_t flags() const { return flags_; } void set_flags(uint32_t flags) { flags_ = flags; } - GRPC_ABSTRACT_BASE_CLASS - protected: ByteStream(uint32_t length, uint32_t flags) : length_(length), flags_(flags) {} diff --git a/src/core/tsi/ssl/session_cache/ssl_session.h b/src/core/tsi/ssl/session_cache/ssl_session.h index e847267cb30..6188637464f 100644 --- a/src/core/tsi/ssl/session_cache/ssl_session.h +++ b/src/core/tsi/ssl/session_cache/ssl_session.h @@ -62,9 +62,7 @@ class SslCachedSession { virtual ~SslCachedSession() = default; /// Returns a copy of previously cached session. - virtual SslSessionPtr CopySession() const GRPC_ABSTRACT; - - GRPC_ABSTRACT_BASE_CLASS + virtual SslSessionPtr CopySession() const = 0; protected: SslCachedSession() = default; diff --git a/test/core/gprpp/BUILD b/test/core/gprpp/BUILD index 193ef5e410a..017a5b9fdba 100644 --- a/test/core/gprpp/BUILD +++ b/test/core/gprpp/BUILD @@ -81,20 +81,6 @@ grpc_cc_test( uses_polling = False, ) -grpc_cc_test( - name = "grpc_core_map_test", - srcs = ["map_test.cc"], - external_deps = [ - "gtest", - ], - language = "C++", - deps = [ - "//:gpr_base", - "//test/core/util:grpc_test_util", - ], - uses_polling = False, -) - grpc_cc_test( name = "memory_test", srcs = ["memory_test.cc"], diff --git a/test/core/gprpp/manual_constructor_test.cc b/test/core/gprpp/manual_constructor_test.cc index a5a45133d86..5f41920391a 100644 --- a/test/core/gprpp/manual_constructor_test.cc +++ b/test/core/gprpp/manual_constructor_test.cc @@ -26,7 +26,6 @@ #include #include -#include "src/core/lib/gprpp/abstract.h" #include "test/core/util/test_config.h" class A { @@ -35,7 +34,6 @@ class A { virtual ~A() {} virtual const char* foo() { return "A_foo"; } virtual const char* bar() { return "A_bar"; } - GRPC_ABSTRACT_BASE_CLASS }; class B : public A { diff --git a/test/core/gprpp/map_test.cc b/test/core/gprpp/map_test.cc deleted file mode 100644 index 7dc1ba636f3..00000000000 --- a/test/core/gprpp/map_test.cc +++ /dev/null @@ -1,514 +0,0 @@ -/* - * - * Copyright 2017 gRPC authors. - * - * 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. - * - */ - -#include "src/core/lib/gprpp/map.h" - -#include - -#include "include/grpc/support/string_util.h" -#include "src/core/lib/gprpp/inlined_vector.h" -#include "src/core/lib/gprpp/memory.h" -#include "src/core/lib/gprpp/orphanable.h" -#include "src/core/lib/gprpp/ref_counted_ptr.h" -#include "test/core/util/test_config.h" - -namespace grpc_core { -namespace testing { - -#if GRPC_USE_CPP_STD_LIB - -TEST(MapTest, Nop) {} - -#else - -class Payload { - public: - Payload() : data_(-1) {} - explicit Payload(int data) : data_(data) {} - Payload(const Payload& other) : data_(other.data_) {} - Payload& operator=(const Payload& other) { - if (this != &other) { - data_ = other.data_; - } - return *this; - } - int data() { return data_; } - - private: - int data_; -}; - -inline UniquePtr CopyString(const char* string) { - return UniquePtr(gpr_strdup(string)); -} - -static constexpr char kKeys[][4] = {"abc", "efg", "hij", "klm", "xyz"}; - -class MapTest : public ::testing::Test { - public: - template - typename ::grpc_core::Map::Entry* Root( - typename ::grpc_core::Map* map) { - return map->root_; - } -}; - -// Test insertion of Payload -TEST_F(MapTest, EmplaceAndFind) { - Map test_map; - for (int i = 0; i < 5; i++) { - test_map.emplace(kKeys[i], Payload(i)); - } - for (int i = 0; i < 5; i++) { - EXPECT_EQ(i, test_map.find(kKeys[i])->second.data()); - } -} - -// Test insertion of Payload Unique Ptrs -TEST_F(MapTest, EmplaceAndFindWithUniquePtrValue) { - Map, StringLess> test_map; - for (int i = 0; i < 5; i++) { - test_map.emplace(kKeys[i], MakeUnique(i)); - } - for (int i = 0; i < 5; i++) { - EXPECT_EQ(i, test_map.find(kKeys[i])->second->data()); - } -} - -// Test insertion of Unique Ptr kKeys and Payload -TEST_F(MapTest, EmplaceAndFindWithUniquePtrKey) { - Map, Payload, StringLess> test_map; - for (int i = 0; i < 5; i++) { - test_map.emplace(CopyString(kKeys[i]), Payload(i)); - } - for (int i = 0; i < 5; i++) { - EXPECT_EQ(i, test_map.find(CopyString(kKeys[i]))->second.data()); - } -} - -// Test insertion of Payload -TEST_F(MapTest, InsertAndFind) { - Map test_map; - for (int i = 0; i < 5; i++) { - test_map.insert(MakePair(kKeys[i], Payload(i))); - } - for (int i = 0; i < 5; i++) { - EXPECT_EQ(i, test_map.find(kKeys[i])->second.data()); - } -} - -// Test insertion of Payload Unique Ptrs -TEST_F(MapTest, InsertAndFindWithUniquePtrValue) { - Map, StringLess> test_map; - for (int i = 0; i < 5; i++) { - test_map.insert(MakePair(kKeys[i], MakeUnique(i))); - } - for (int i = 0; i < 5; i++) { - EXPECT_EQ(i, test_map.find(kKeys[i])->second->data()); - } -} - -// Test insertion of Unique Ptr kKeys and Payload -TEST_F(MapTest, InsertAndFindWithUniquePtrKey) { - Map, Payload, StringLess> test_map; - for (int i = 0; i < 5; i++) { - test_map.insert(MakePair(CopyString(kKeys[i]), Payload(i))); - } - for (int i = 0; i < 5; i++) { - EXPECT_EQ(i, test_map.find(CopyString(kKeys[i]))->second.data()); - } -} - -// Test bracket operators -TEST_F(MapTest, BracketOperator) { - Map test_map; - for (int i = 0; i < 5; i++) { - test_map[kKeys[i]] = Payload(i); - } - for (int i = 0; i < 5; i++) { - EXPECT_EQ(i, test_map[kKeys[i]].data()); - } -} - -// Test bracket operators with unique pointer to payload -TEST_F(MapTest, BracketOperatorWithUniquePtrValue) { - Map, StringLess> test_map; - for (int i = 0; i < 5; i++) { - test_map[kKeys[i]] = MakeUnique(i); - } - for (int i = 0; i < 5; i++) { - EXPECT_EQ(i, test_map[kKeys[i]]->data()); - } -} - -// Test bracket operators with unique pointer to payload -TEST_F(MapTest, BracketOperatorWithUniquePtrKey) { - Map, Payload, StringLess> test_map; - for (int i = 0; i < 5; i++) { - test_map[CopyString(kKeys[i])] = Payload(i); - } - for (int i = 0; i < 5; i++) { - EXPECT_EQ(i, test_map[CopyString(kKeys[i])].data()); - } -} - -// Test removal of a single value -TEST_F(MapTest, Erase) { - Map test_map; - for (int i = 0; i < 5; i++) { - test_map.emplace(kKeys[i], Payload(i)); - } - EXPECT_EQ(test_map.size(), 5UL); - EXPECT_EQ(test_map.erase(kKeys[3]), 1UL); // Remove "hij" - for (int i = 0; i < 5; i++) { - if (i == 3) { // "hij" should not be present - EXPECT_TRUE(test_map.find(kKeys[i]) == test_map.end()); - } else { - EXPECT_EQ(i, test_map.find(kKeys[i])->second.data()); - } - } - EXPECT_EQ(test_map.size(), 4UL); -} - -// Test removal of a single value with unique ptr to payload -TEST_F(MapTest, EraseWithUniquePtrValue) { - Map, StringLess> test_map; - for (int i = 0; i < 5; i++) { - test_map.emplace(kKeys[i], MakeUnique(i)); - } - EXPECT_EQ(test_map.size(), 5UL); - test_map.erase(kKeys[3]); // Remove "hij" - for (int i = 0; i < 5; i++) { - if (i == 3) { // "hij" should not be present - EXPECT_TRUE(test_map.find(kKeys[i]) == test_map.end()); - } else { - EXPECT_EQ(i, test_map.find(kKeys[i])->second->data()); - } - } - EXPECT_EQ(test_map.size(), 4UL); -} - -// Test removal of a single value -TEST_F(MapTest, EraseWithUniquePtrKey) { - Map, Payload, StringLess> test_map; - for (int i = 0; i < 5; i++) { - test_map.emplace(CopyString(kKeys[i]), Payload(i)); - } - EXPECT_EQ(test_map.size(), 5UL); - test_map.erase(CopyString(kKeys[3])); // Remove "hij" - for (int i = 0; i < 5; i++) { - if (i == 3) { // "hij" should not be present - EXPECT_TRUE(test_map.find(CopyString(kKeys[i])) == test_map.end()); - } else { - EXPECT_EQ(i, test_map.find(CopyString(kKeys[i]))->second.data()); - } - } - EXPECT_EQ(test_map.size(), 4UL); -} - -// Test clear -TEST_F(MapTest, SizeAndClear) { - Map test_map; - for (int i = 0; i < 5; i++) { - test_map.emplace(kKeys[i], Payload(i)); - } - EXPECT_EQ(test_map.size(), 5UL); - EXPECT_FALSE(test_map.empty()); - test_map.clear(); - EXPECT_EQ(test_map.size(), 0UL); - EXPECT_TRUE(test_map.empty()); -} - -// Test clear with unique ptr payload -TEST_F(MapTest, SizeAndClearWithUniquePtrValue) { - Map, StringLess> test_map; - for (int i = 0; i < 5; i++) { - test_map.emplace(kKeys[i], MakeUnique(i)); - } - EXPECT_EQ(test_map.size(), 5UL); - EXPECT_FALSE(test_map.empty()); - test_map.clear(); - EXPECT_EQ(test_map.size(), 0UL); - EXPECT_TRUE(test_map.empty()); -} - -// Test clear with unique ptr char key -TEST_F(MapTest, SizeAndClearWithUniquePtrKey) { - Map, Payload, StringLess> test_map; - for (int i = 0; i < 5; i++) { - test_map.emplace(CopyString(kKeys[i]), Payload(i)); - } - EXPECT_EQ(test_map.size(), 5UL); - EXPECT_FALSE(test_map.empty()); - test_map.clear(); - EXPECT_EQ(test_map.size(), 0UL); - EXPECT_TRUE(test_map.empty()); -} - -// Test correction of Left-Left Tree imbalance -TEST_F(MapTest, MapLL) { - Map test_map; - for (int i = 2; i >= 0; i--) { - test_map.emplace(kKeys[i], Payload(i)); - } - EXPECT_EQ(strcmp(Root(&test_map)->pair.first, kKeys[1]), 0); - EXPECT_EQ(strcmp(Root(&test_map)->left->pair.first, kKeys[0]), 0); - EXPECT_EQ(strcmp(Root(&test_map)->right->pair.first, kKeys[2]), 0); -} - -// Test correction of Left-Right tree imbalance -TEST_F(MapTest, MapLR) { - Map test_map; - int insertion_key_index[] = {2, 0, 1}; - for (int i = 0; i < 3; i++) { - int key_index = insertion_key_index[i]; - test_map.emplace(kKeys[key_index], Payload(key_index)); - } - EXPECT_EQ(strcmp(Root(&test_map)->pair.first, kKeys[1]), 0); - EXPECT_EQ(strcmp(Root(&test_map)->left->pair.first, kKeys[0]), 0); - EXPECT_EQ(strcmp(Root(&test_map)->right->pair.first, kKeys[2]), 0); -} - -// Test correction of Right-Left tree imbalance -TEST_F(MapTest, MapRL) { - Map test_map; - int insertion_key_index[] = {0, 2, 1}; - for (int i = 0; i < 3; i++) { - int key_index = insertion_key_index[i]; - test_map.emplace(kKeys[key_index], Payload(key_index)); - } - EXPECT_EQ(strcmp(Root(&test_map)->pair.first, kKeys[1]), 0); - EXPECT_EQ(strcmp(Root(&test_map)->left->pair.first, kKeys[0]), 0); - EXPECT_EQ(strcmp(Root(&test_map)->right->pair.first, kKeys[2]), 0); -} - -// Test correction of Right-Right tree imbalance -TEST_F(MapTest, MapRR) { - Map test_map; - for (int i = 0; i < 5; i++) { - test_map.emplace(kKeys[i], Payload(i)); - } - EXPECT_EQ(strcmp(Root(&test_map)->pair.first, kKeys[1]), 0); - EXPECT_EQ(strcmp(Root(&test_map)->left->pair.first, kKeys[0]), 0); - EXPECT_EQ(strcmp(Root(&test_map)->right->pair.first, kKeys[3]), 0); - EXPECT_EQ(strcmp(Root(&test_map)->right->left->pair.first, kKeys[2]), 0); - EXPECT_EQ(strcmp(Root(&test_map)->right->right->pair.first, kKeys[4]), 0); -} - -// Test correction after random insertion -TEST_F(MapTest, MapRandomInsertions) { - Map test_map; - int insertion_key_index[] = {1, 4, 3, 0, 2}; - for (int i = 0; i < 5; i++) { - int key_index = insertion_key_index[i]; - test_map.emplace(kKeys[key_index], Payload(key_index)); - } - EXPECT_EQ(strcmp(Root(&test_map)->pair.first, kKeys[3]), 0); - EXPECT_EQ(strcmp(Root(&test_map)->left->pair.first, kKeys[1]), 0); - EXPECT_EQ(strcmp(Root(&test_map)->right->pair.first, kKeys[4]), 0); - EXPECT_EQ(strcmp(Root(&test_map)->left->right->pair.first, kKeys[2]), 0); - EXPECT_EQ(strcmp(Root(&test_map)->left->left->pair.first, kKeys[0]), 0); -} - -// Test Map iterator -TEST_F(MapTest, Iteration) { - Map test_map; - for (int i = 4; i >= 0; --i) { - test_map.emplace(kKeys[i], Payload(i)); - } - auto it = test_map.begin(); - for (int i = 0; i < 5; ++i) { - ASSERT_NE(it, test_map.end()); - EXPECT_STREQ(kKeys[i], it->first); - EXPECT_EQ(i, it->second.data()); - ++it; - } - EXPECT_EQ(it, test_map.end()); -} - -// Test Map iterator with unique ptr payload -TEST_F(MapTest, IterationWithUniquePtrValue) { - Map, StringLess> test_map; - for (int i = 4; i >= 0; --i) { - test_map.emplace(kKeys[i], MakeUnique(i)); - } - auto it = test_map.begin(); - for (int i = 0; i < 5; ++i) { - ASSERT_NE(it, test_map.end()); - EXPECT_STREQ(kKeys[i], it->first); - EXPECT_EQ(i, it->second->data()); - ++it; - } - EXPECT_EQ(it, test_map.end()); -} - -// Test Map iterator with unique ptr to char key -TEST_F(MapTest, IterationWithUniquePtrKey) { - Map, Payload, StringLess> test_map; - for (int i = 4; i >= 0; --i) { - test_map.emplace(CopyString(kKeys[i]), Payload(i)); - } - auto it = test_map.begin(); - for (int i = 0; i < 5; ++i) { - ASSERT_NE(it, test_map.end()); - EXPECT_STREQ(kKeys[i], it->first.get()); - EXPECT_EQ(i, it->second.data()); - ++it; - } - EXPECT_EQ(it, test_map.end()); -} - -// Test removing entries while iterating the map -TEST_F(MapTest, EraseUsingIterator) { - Map test_map; - for (int i = 0; i < 5; i++) { - test_map.emplace(kKeys[i], Payload(i)); - } - int count = 0; - for (auto iter = test_map.begin(); iter != test_map.end();) { - EXPECT_EQ(iter->second.data(), count); - if (count % 2 == 1) { - iter = test_map.erase(iter); - } else { - ++iter; - } - ++count; - } - EXPECT_EQ(count, 5); - auto it = test_map.begin(); - for (int i = 0; i < 5; ++i) { - if (i % 2 == 0) { - EXPECT_STREQ(kKeys[i], it->first); - EXPECT_EQ(i, it->second.data()); - ++it; - } - } - EXPECT_EQ(it, test_map.end()); -} - -// Random ops on a Map with Integer key of Payload value, -// tests default comparator -TEST_F(MapTest, RandomOpsWithIntKey) { - Map test_map; - for (int i = 0; i < 5; i++) { - test_map.emplace(i, Payload(i)); - } - for (int i = 0; i < 5; i++) { - EXPECT_EQ(i, test_map.find(i)->second.data()); - } - for (int i = 0; i < 5; i++) { - test_map[i] = Payload(i + 10); - } - for (int i = 0; i < 5; i++) { - EXPECT_EQ(i + 10, test_map[i].data()); - } - EXPECT_EQ(test_map.erase(3), 1UL); - EXPECT_TRUE(test_map.find(3) == test_map.end()); - EXPECT_FALSE(test_map.empty()); - EXPECT_EQ(test_map.size(), 4UL); - test_map.clear(); - EXPECT_EQ(test_map.size(), 0UL); - EXPECT_TRUE(test_map.empty()); -} - -// Tests lower_bound(). -TEST_F(MapTest, LowerBound) { - Map test_map; - for (int i = 0; i < 10; i += 2) { - test_map.emplace(i, Payload(i)); - } - auto it = test_map.lower_bound(-1); - EXPECT_EQ(it, test_map.begin()); - it = test_map.lower_bound(0); - EXPECT_EQ(it, test_map.begin()); - it = test_map.lower_bound(2); - EXPECT_EQ(it->first, 2); - it = test_map.lower_bound(3); - EXPECT_EQ(it->first, 4); - it = test_map.lower_bound(9); - EXPECT_EQ(it, test_map.end()); -} - -// Test move ctor -TEST_F(MapTest, MoveCtor) { - Map test_map; - for (int i = 0; i < 5; i++) { - test_map.emplace(kKeys[i], Payload(i)); - } - Map test_map2 = std::move(test_map); - for (int i = 0; i < 5; i++) { - EXPECT_EQ(test_map.end(), test_map.find(kKeys[i])); - EXPECT_EQ(i, test_map2.find(kKeys[i])->second.data()); - } -} - -// Test move assignment -TEST_F(MapTest, MoveAssignment) { - Map test_map; - for (int i = 0; i < 5; i++) { - test_map.emplace(kKeys[i], Payload(i)); - } - Map test_map2; - test_map2.emplace("xxx", Payload(123)); - test_map2 = std::move(test_map); - for (int i = 0; i < 5; i++) { - EXPECT_EQ(test_map.end(), test_map.find(kKeys[i])); - EXPECT_EQ(i, test_map2.find(kKeys[i])->second.data()); - } - EXPECT_EQ(test_map2.end(), test_map2.find("xxx")); -} - -// Test copy ctor -TEST_F(MapTest, CopyCtor) { - Map test_map; - for (int i = 0; i < 5; i++) { - test_map.emplace(kKeys[i], Payload(i)); - } - Map test_map2 = test_map; - for (int i = 0; i < 5; i++) { - EXPECT_EQ(i, test_map.find(kKeys[i])->second.data()); - EXPECT_EQ(i, test_map2.find(kKeys[i])->second.data()); - } -} - -// Test copy assignment -TEST_F(MapTest, CopyAssignment) { - Map test_map; - for (int i = 0; i < 5; i++) { - test_map.emplace(kKeys[i], Payload(i)); - } - Map test_map2; - test_map2.emplace("xxx", Payload(123)); - test_map2 = test_map; - for (int i = 0; i < 5; i++) { - EXPECT_EQ(i, test_map.find(kKeys[i])->second.data()); - EXPECT_EQ(i, test_map2.find(kKeys[i])->second.data()); - } - EXPECT_EQ(test_map2.end(), test_map2.find("xxx")); -} - -#endif - -} // namespace testing -} // namespace grpc_core - -int main(int argc, char** argv) { - grpc::testing::TestEnvironment env(argc, argv); - ::testing::InitGoogleTest(&argc, argv); - return RUN_ALL_TESTS(); -} diff --git a/test/cpp/qps/interarrival.h b/test/cpp/qps/interarrival.h index ce4bf3d30c9..61a6d75a3c8 100644 --- a/test/cpp/qps/interarrival.h +++ b/test/cpp/qps/interarrival.h @@ -81,7 +81,6 @@ class InterarrivalTimer { for (int i = 0; i < entries; i++) { random_table_.push_back( static_cast(1e9 * r.transform(rando(generator)))); - ; } // Now set up the thread positions for (int i = 0; i < threads; i++) { diff --git a/tools/doxygen/Doxyfile.c++.internal b/tools/doxygen/Doxyfile.c++.internal index 5f62f39427f..fd709c70e84 100644 --- a/tools/doxygen/Doxyfile.c++.internal +++ b/tools/doxygen/Doxyfile.c++.internal @@ -1101,7 +1101,6 @@ src/core/lib/gpr/tls_msvc.h \ src/core/lib/gpr/tls_pthread.h \ src/core/lib/gpr/tmpfile.h \ src/core/lib/gpr/useful.h \ -src/core/lib/gprpp/abstract.h \ src/core/lib/gprpp/arena.h \ src/core/lib/gprpp/atomic.h \ src/core/lib/gprpp/debug_location.h \ diff --git a/tools/doxygen/Doxyfile.core.internal b/tools/doxygen/Doxyfile.core.internal index 249ec2420dd..eba49015f19 100644 --- a/tools/doxygen/Doxyfile.core.internal +++ b/tools/doxygen/Doxyfile.core.internal @@ -1232,7 +1232,6 @@ src/core/lib/gpr/tmpfile_windows.cc \ src/core/lib/gpr/useful.h \ src/core/lib/gpr/wrap_memcpy.cc \ src/core/lib/gprpp/README.md \ -src/core/lib/gprpp/abstract.h \ src/core/lib/gprpp/arena.cc \ src/core/lib/gprpp/arena.h \ src/core/lib/gprpp/atomic.h \ diff --git a/tools/internal_ci/linux/grpc_bazel_build_in_docker.sh b/tools/internal_ci/linux/grpc_bazel_build_in_docker.sh index 8487ec49bbd..24598f43f02 100755 --- a/tools/internal_ci/linux/grpc_bazel_build_in_docker.sh +++ b/tools/internal_ci/linux/grpc_bazel_build_in_docker.sh @@ -25,4 +25,3 @@ git clone /var/local/jenkins/grpc /var/local/git/grpc ${name}') cd /var/local/git/grpc bazel build --spawn_strategy=standalone --genrule_strategy=standalone :all test/... examples/... -bazel build --spawn_strategy=standalone --genrule_strategy=standalone --define=GRPC_USE_CPP_STD_LIB=1 :grpc diff --git a/tools/run_tests/generated/tests.json b/tools/run_tests/generated/tests.json index b4b3822bde5..54d6594704d 100644 --- a/tools/run_tests/generated/tests.json +++ b/tools/run_tests/generated/tests.json @@ -4739,30 +4739,6 @@ ], "uses_polling": true }, - { - "args": [], - "benchmark": false, - "ci_platforms": [ - "linux", - "mac", - "posix", - "windows" - ], - "cpu_cost": 1.0, - "exclude_configs": [], - "exclude_iomgrs": [], - "flaky": false, - "gtest": true, - "language": "c++", - "name": "grpc_core_map_test", - "platforms": [ - "linux", - "mac", - "posix", - "windows" - ], - "uses_polling": false - }, { "args": [], "benchmark": false, From 90e5ade73b3b042344a8822268269521766c4d16 Mon Sep 17 00:00:00 2001 From: Esun Kim Date: Tue, 24 Sep 2019 14:49:09 -0700 Subject: [PATCH 49/60] Remove unnecessary public: --- src/core/lib/gprpp/ref_counted.h | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/core/lib/gprpp/ref_counted.h b/src/core/lib/gprpp/ref_counted.h index 2ae92949128..086156f2d74 100644 --- a/src/core/lib/gprpp/ref_counted.h +++ b/src/core/lib/gprpp/ref_counted.h @@ -39,7 +39,6 @@ namespace grpc_core { // PolymorphicRefCount enforces polymorphic destruction of RefCounted. class PolymorphicRefCount { - public: protected: GRPC_ALLOW_CLASS_TO_USE_NON_PUBLIC_DELETE @@ -50,7 +49,6 @@ class PolymorphicRefCount { // RefCounted. Please refer to grpc_core::RefCounted for more details, and // when in doubt use PolymorphicRefCount. class NonPolymorphicRefCount { - public: protected: GRPC_ALLOW_CLASS_TO_USE_NON_PUBLIC_DELETE From 2a8de59fb071aa7997f3ab451e43bdabb15db2bc Mon Sep 17 00:00:00 2001 From: Esun Kim Date: Tue, 24 Sep 2019 16:18:18 -0700 Subject: [PATCH 50/60] Replace Map with std::map --- .../ext/filters/client_channel/backend_metric.cc | 4 ++-- .../ext/filters/client_channel/client_channel.cc | 12 ++++++------ src/core/ext/filters/client_channel/lb_policy.h | 4 ++-- .../filters/client_channel/lb_policy/xds/xds.cc | 4 ++-- .../lb_policy/xds/xds_client_stats.h | 14 +++++++------- .../lb_policy/xds/xds_load_balancer_api.h | 2 +- src/core/ext/filters/client_channel/subchannel.h | 6 +++--- src/core/lib/channel/channelz.h | 8 ++++---- src/core/lib/channel/channelz_registry.h | 2 +- src/core/lib/gprpp/map.h | 3 --- src/core/lib/security/credentials/credentials.cc | 12 ++++++------ src/core/lib/security/credentials/credentials.h | 6 +++--- src/core/lib/transport/connectivity_state.h | 11 ++++------- 13 files changed, 41 insertions(+), 47 deletions(-) diff --git a/src/core/ext/filters/client_channel/backend_metric.cc b/src/core/ext/filters/client_channel/backend_metric.cc index 0d6aa2f6e2c..b36614f5b80 100644 --- a/src/core/ext/filters/client_channel/backend_metric.cc +++ b/src/core/ext/filters/client_channel/backend_metric.cc @@ -26,12 +26,12 @@ namespace grpc_core { namespace { template -Map ParseMap( +std::map ParseMap( udpa_data_orca_v1_OrcaLoadReport* msg, EntryType** (*entry_func)(udpa_data_orca_v1_OrcaLoadReport*, size_t*), upb_strview (*key_func)(const EntryType*), double (*value_func)(const EntryType*), Arena* arena) { - Map result; + std::map result; size_t size; const auto* const* entries = entry_func(msg, &size); for (size_t i = 0; i < size; ++i) { diff --git a/src/core/ext/filters/client_channel/client_channel.cc b/src/core/ext/filters/client_channel/client_channel.cc index af2425a6faa..70746f4783f 100644 --- a/src/core/ext/filters/client_channel/client_channel.cc +++ b/src/core/ext/filters/client_channel/client_channel.cc @@ -282,18 +282,18 @@ class ChannelData { RefCountedPtr saved_service_config_; bool received_first_resolver_result_ = false; // The number of SubchannelWrapper instances referencing a given Subchannel. - Map subchannel_refcount_map_; + std::map subchannel_refcount_map_; // The set of SubchannelWrappers that currently exist. // No need to hold a ref, since the map is updated in the control-plane // combiner when the SubchannelWrappers are created and destroyed. // TODO(roth): We really want to use a set here, not a map. Since we don't // currently have a set implementation, we use a map and ignore the value. - Map subchannel_wrappers_; + std::map subchannel_wrappers_; // Pending ConnectedSubchannel updates for each SubchannelWrapper. // Updates are queued here in the control plane combiner and then applied // in the data plane mutex when the picker is updated. - Map, RefCountedPtr, - RefCountedPtrLess> + std::map, RefCountedPtr, + RefCountedPtrLess> pending_subchannel_updates_; // @@ -314,7 +314,7 @@ class ChannelData { // synchronously via grpc_channel_num_external_connectivity_watchers(). // mutable Mutex external_watchers_mu_; - Map external_watchers_; + std::map external_watchers_; }; // @@ -1107,7 +1107,7 @@ class ChannelData::SubchannelWrapper : public SubchannelInterface { // subchannel. This is needed so that when the LB policy calls // CancelConnectivityStateWatch() with its watcher, we know the // corresponding WrapperWatcher to cancel on the underlying subchannel. - Map watcher_map_; + std::map watcher_map_; // To be accessed only in the control plane combiner. RefCountedPtr connected_subchannel_; // To be accessed only in the data plane mutex. diff --git a/src/core/ext/filters/client_channel/lb_policy.h b/src/core/ext/filters/client_channel/lb_policy.h index d727cea7db6..20957c3daaf 100644 --- a/src/core/ext/filters/client_channel/lb_policy.h +++ b/src/core/ext/filters/client_channel/lb_policy.h @@ -90,11 +90,11 @@ class LoadBalancingPolicy : public InternallyRefCounted { /// Application-specific requests cost metrics. Metric names are /// determined by the application. Each value is an absolute cost /// (e.g. 3487 bytes of storage) associated with the request. - Map request_cost; + std::map request_cost; /// Application-specific resource utilization metrics. Metric names /// are determined by the application. Each value is expressed as a /// fraction of total resources available. - Map utilization; + std::map utilization; }; /// Interface for accessing per-call state. diff --git a/src/core/ext/filters/client_channel/lb_policy/xds/xds.cc b/src/core/ext/filters/client_channel/lb_policy/xds/xds.cc index c148023bf5b..e0fa6c31dcd 100644 --- a/src/core/ext/filters/client_channel/lb_policy/xds/xds.cc +++ b/src/core/ext/filters/client_channel/lb_policy/xds/xds.cc @@ -576,8 +576,8 @@ class XdsLb : public LoadBalancingPolicy { RefCountedPtr xds_policy_; - Map, OrphanablePtr, - XdsLocalityName::Less> + std::map, OrphanablePtr, + XdsLocalityName::Less> localities_; const uint32_t priority_; grpc_connectivity_state connectivity_state_ = GRPC_CHANNEL_IDLE; diff --git a/src/core/ext/filters/client_channel/lb_policy/xds/xds_client_stats.h b/src/core/ext/filters/client_channel/lb_policy/xds/xds_client_stats.h index 6e8dd961ea9..8a8af4426b4 100644 --- a/src/core/ext/filters/client_channel/lb_policy/xds/xds_client_stats.h +++ b/src/core/ext/filters/client_channel/lb_policy/xds/xds_client_stats.h @@ -111,9 +111,9 @@ class XdsClientStats { double total_metric_value_{0}; }; - using LoadMetricMap = Map, LoadMetric, StringLess>; + using LoadMetricMap = std::map, LoadMetric, StringLess>; using LoadMetricSnapshotMap = - Map, LoadMetric::Snapshot, StringLess>; + std::map, LoadMetric::Snapshot, StringLess>; struct Snapshot { // TODO(juanlishen): Change this to const method when const_iterator is @@ -180,12 +180,12 @@ class XdsClientStats { // UniquePtr<>. We should remove this wrapper if the value type of Map<> // doesn't have to be movable. using LocalityStatsMap = - Map, RefCountedPtr, - XdsLocalityName::Less>; + std::map, RefCountedPtr, + XdsLocalityName::Less>; using LocalityStatsSnapshotMap = - Map, LocalityStats::Snapshot, - XdsLocalityName::Less>; - using DroppedRequestsMap = Map, uint64_t, StringLess>; + std::map, LocalityStats::Snapshot, + XdsLocalityName::Less>; + using DroppedRequestsMap = std::map, uint64_t, StringLess>; using DroppedRequestsSnapshotMap = DroppedRequestsMap; struct Snapshot { diff --git a/src/core/ext/filters/client_channel/lb_policy/xds/xds_load_balancer_api.h b/src/core/ext/filters/client_channel/lb_policy/xds/xds_load_balancer_api.h index 1b56bef7d81..25396682bbd 100644 --- a/src/core/ext/filters/client_channel/lb_policy/xds/xds_load_balancer_api.h +++ b/src/core/ext/filters/client_channel/lb_policy/xds/xds_load_balancer_api.h @@ -57,7 +57,7 @@ class XdsPriorityListUpdate { size_t size() const { return localities.size(); } - Map, Locality, XdsLocalityName::Less> + std::map, Locality, XdsLocalityName::Less> localities; }; diff --git a/src/core/ext/filters/client_channel/subchannel.h b/src/core/ext/filters/client_channel/subchannel.h index 7a039192085..d7912a00c77 100644 --- a/src/core/ext/filters/client_channel/subchannel.h +++ b/src/core/ext/filters/client_channel/subchannel.h @@ -294,8 +294,8 @@ class Subchannel { private: // TODO(roth): This could be a set instead of a map if we had a set // implementation. - Map> + std::map> watchers_; }; @@ -328,7 +328,7 @@ class Subchannel { private: class HealthWatcher; - Map, StringLess> map_; + std::map, StringLess> map_; }; class ConnectedSubchannelStateWatcher; diff --git a/src/core/lib/channel/channelz.h b/src/core/lib/channel/channelz.h index 545b9ebeb88..5a063b4df96 100644 --- a/src/core/lib/channel/channelz.h +++ b/src/core/lib/channel/channelz.h @@ -221,8 +221,8 @@ class ChannelNode : public BaseNode { // TODO(roth): We don't actually use the values here, only the keys, so // these should be sets instead of maps, but we don't currently have a set // implementation. Change this if/when we have one. - Map child_channels_; - Map child_subchannels_; + std::map child_channels_; + std::map child_subchannels_; }; // Handles channelz bookkeeping for servers @@ -262,8 +262,8 @@ class ServerNode : public BaseNode { CallCountingHelper call_counter_; ChannelTrace trace_; Mutex child_mu_; // Guards child maps below. - Map> child_sockets_; - Map> child_listen_sockets_; + std::map> child_sockets_; + std::map> child_listen_sockets_; }; // Handles channelz bookkeeping for sockets diff --git a/src/core/lib/channel/channelz_registry.h b/src/core/lib/channel/channelz_registry.h index e04d7c44888..c60a5554fb9 100644 --- a/src/core/lib/channel/channelz_registry.h +++ b/src/core/lib/channel/channelz_registry.h @@ -87,7 +87,7 @@ class ChannelzRegistry { // protects members Mutex mu_; - Map node_map_; + std::map node_map_; intptr_t uuid_generator_ = 0; }; diff --git a/src/core/lib/gprpp/map.h b/src/core/lib/gprpp/map.h index 4537012c903..0d61f902757 100644 --- a/src/core/lib/gprpp/map.h +++ b/src/core/lib/gprpp/map.h @@ -59,9 +59,6 @@ struct RefCountedPtrLess { } }; -template > -using Map = std::map; - } // namespace grpc_core #endif /* GRPC_CORE_LIB_GPRPP_MAP_H */ diff --git a/src/core/lib/security/credentials/credentials.cc b/src/core/lib/security/credentials/credentials.cc index f2ec9b7f2f2..37678715704 100644 --- a/src/core/lib/security/credentials/credentials.cc +++ b/src/core/lib/security/credentials/credentials.cc @@ -45,18 +45,18 @@ void grpc_channel_credentials_release(grpc_channel_credentials* creds) { if (creds) creds->Unref(); } -static grpc_core::Map, - grpc_core::RefCountedPtr, - grpc_core::StringLess>* g_grpc_control_plane_creds; +static std::map, + grpc_core::RefCountedPtr, + grpc_core::StringLess>* g_grpc_control_plane_creds; static gpr_mu g_control_plane_creds_mu; static void do_control_plane_creds_init() { gpr_mu_init(&g_control_plane_creds_mu); GPR_ASSERT(g_grpc_control_plane_creds == nullptr); g_grpc_control_plane_creds = grpc_core::New< - grpc_core::Map, - grpc_core::RefCountedPtr, - grpc_core::StringLess>>(); + std::map, + grpc_core::RefCountedPtr, + grpc_core::StringLess>>(); } void grpc_control_plane_credentials_init() { diff --git a/src/core/lib/security/credentials/credentials.h b/src/core/lib/security/credentials/credentials.h index 16f0454907b..e0700c41a92 100644 --- a/src/core/lib/security/credentials/credentials.h +++ b/src/core/lib/security/credentials/credentials.h @@ -148,9 +148,9 @@ struct grpc_channel_credentials private: const char* type_; - grpc_core::Map, - grpc_core::RefCountedPtr, - grpc_core::StringLess> + std::map, + grpc_core::RefCountedPtr, + grpc_core::StringLess> local_control_plane_creds_; }; diff --git a/src/core/lib/transport/connectivity_state.h b/src/core/lib/transport/connectivity_state.h index 25b43561364..cefd1b88a02 100644 --- a/src/core/lib/transport/connectivity_state.h +++ b/src/core/lib/transport/connectivity_state.h @@ -47,11 +47,9 @@ class ConnectivityStateWatcherInterface virtual ~ConnectivityStateWatcherInterface() = default; // Notifies the watcher that the state has changed to new_state. - virtual void Notify(grpc_connectivity_state new_state) GRPC_ABSTRACT; + virtual void Notify(grpc_connectivity_state new_state) = 0; void Orphan() override { Unref(); } - - GRPC_ABSTRACT_BASE_CLASS }; // An alternative watcher interface that performs notifications via an @@ -70,8 +68,7 @@ class AsyncConnectivityStateWatcherInterface class Notifier; // Invoked asynchronously when Notify() is called. - virtual void OnConnectivityStateChange(grpc_connectivity_state new_state) - GRPC_ABSTRACT; + virtual void OnConnectivityStateChange(grpc_connectivity_state new_state) = 0; }; // Tracks connectivity state. Maintains a list of watchers that are @@ -113,8 +110,8 @@ class ConnectivityStateTracker { Atomic state_; // TODO(roth): This could be a set instead of a map if we had a set // implementation. - Map> + std::map> watchers_; }; From c5b5840707279d36ebecdd3a2d6852c0470a7bad Mon Sep 17 00:00:00 2001 From: Jan Tattermusch Date: Wed, 2 Oct 2019 09:28:32 +0200 Subject: [PATCH 51/60] Revert "Chttp2combiner" --- .../chttp2/transport/chttp2_transport.cc | 739 +++++++++--------- .../chttp2/transport/hpack_parser.cc | 23 +- .../ext/transport/chttp2/transport/internal.h | 31 +- .../ext/transport/chttp2/transport/writing.cc | 4 +- src/core/lib/iomgr/closure.h | 39 - src/core/lib/iomgr/executor.cc | 4 - 6 files changed, 405 insertions(+), 435 deletions(-) diff --git a/src/core/ext/transport/chttp2/transport/chttp2_transport.cc b/src/core/ext/transport/chttp2/transport/chttp2_transport.cc index acb3b4c2ddd..aeb7389ca21 100644 --- a/src/core/ext/transport/chttp2/transport/chttp2_transport.cc +++ b/src/core/ext/transport/chttp2/transport/chttp2_transport.cc @@ -102,14 +102,14 @@ grpc_core::DebugOnlyTraceFlag grpc_trace_chttp2_refcount(false, "chttp2_refcount"); /* forward declarations of various callbacks that we'll build closures around */ -static void write_action_begin(void* t, grpc_error* error); +static void write_action_begin_locked(void* t, grpc_error* error); static void write_action(void* t, grpc_error* error); -static void write_action_end(void* t, grpc_error* error); +static void write_action_end_locked(void* t, grpc_error* error); -static void read_action(void* t, grpc_error* error); +static void read_action_locked(void* t, grpc_error* error); static void continue_read_action_locked(grpc_chttp2_transport* t); -static void complete_fetch(void* gs, grpc_error* error); +static void complete_fetch_locked(void* gs, grpc_error* error); /** Set a transport level setting, and push it to our peer */ static void queue_setting_update(grpc_chttp2_transport* t, grpc_chttp2_setting_id id, uint32_t value); @@ -124,8 +124,8 @@ static void connectivity_state_set(grpc_chttp2_transport* t, grpc_connectivity_state state, const char* reason); -static void benign_reclaimer(void* t, grpc_error* error); -static void destructive_reclaimer(void* t, grpc_error* error); +static void benign_reclaimer_locked(void* t, grpc_error* error); +static void destructive_reclaimer_locked(void* t, grpc_error* error); static void post_benign_reclaimer(grpc_chttp2_transport* t); static void post_destructive_reclaimer(grpc_chttp2_transport* t); @@ -135,20 +135,20 @@ static void end_all_the_calls(grpc_chttp2_transport* t, grpc_error* error); static void schedule_bdp_ping_locked(grpc_chttp2_transport* t); static void start_bdp_ping_locked(void* tp, grpc_error* error); -static void finish_bdp_ping(void* tp, grpc_error* error); -static void next_bdp_ping_timer_expired(void* tp, grpc_error* error); +static void finish_bdp_ping_locked(void* tp, grpc_error* error); +static void next_bdp_ping_timer_expired_locked(void* tp, grpc_error* error); static void cancel_pings(grpc_chttp2_transport* t, grpc_error* error); static void send_ping_locked(grpc_chttp2_transport* t, grpc_closure* on_initiate, grpc_closure* on_complete); -static void retry_initiate_ping(void* tp, grpc_error* error); +static void retry_initiate_ping_locked(void* tp, grpc_error* error); /** keepalive-relevant functions */ -static void init_keepalive_ping(void* arg, grpc_error* error); +static void init_keepalive_ping_locked(void* arg, grpc_error* error); static void start_keepalive_ping_locked(void* arg, grpc_error* error); -static void finish_keepalive_ping(void* arg, grpc_error* error); -static void keepalive_watchdog_fired(void* arg, grpc_error* error); +static void finish_keepalive_ping_locked(void* arg, grpc_error* error); +static void keepalive_watchdog_fired_locked(void* arg, grpc_error* error); static void reset_byte_stream(void* arg, grpc_error* error); @@ -197,6 +197,8 @@ grpc_chttp2_transport::~grpc_chttp2_transport() { grpc_chttp2_stream_map_destroy(&stream_map); + GRPC_COMBINER_UNREF(combiner, "chttp2_transport"); + cancel_pings(this, GRPC_ERROR_CREATE_FROM_STATIC_STRING("Transport destroyed")); @@ -390,27 +392,33 @@ static bool read_channel_args(grpc_chttp2_transport* t, } static void init_transport_closures(grpc_chttp2_transport* t) { - GRPC_CLOSURE_INIT(&t->read_action, read_action, t, grpc_schedule_on_exec_ctx); - GRPC_CLOSURE_INIT(&t->benign_reclaimer, benign_reclaimer, t, - grpc_schedule_on_exec_ctx); - GRPC_CLOSURE_INIT(&t->destructive_reclaimer, destructive_reclaimer, t, - grpc_schedule_on_exec_ctx); - GRPC_CLOSURE_INIT(&t->retry_initiate_ping, retry_initiate_ping, t, - grpc_schedule_on_exec_ctx); + GRPC_CLOSURE_INIT(&t->read_action_locked, read_action_locked, t, + grpc_combiner_scheduler(t->combiner)); + GRPC_CLOSURE_INIT(&t->benign_reclaimer_locked, benign_reclaimer_locked, t, + grpc_combiner_scheduler(t->combiner)); + GRPC_CLOSURE_INIT(&t->destructive_reclaimer_locked, + destructive_reclaimer_locked, t, + grpc_combiner_scheduler(t->combiner)); + GRPC_CLOSURE_INIT(&t->retry_initiate_ping_locked, retry_initiate_ping_locked, + t, grpc_combiner_scheduler(t->combiner)); GRPC_CLOSURE_INIT(&t->start_bdp_ping_locked, start_bdp_ping_locked, t, - grpc_schedule_on_exec_ctx); - GRPC_CLOSURE_INIT(&t->finish_bdp_ping, finish_bdp_ping, t, - grpc_schedule_on_exec_ctx); - GRPC_CLOSURE_INIT(&t->next_bdp_ping_timer_expired, - next_bdp_ping_timer_expired, t, grpc_schedule_on_exec_ctx); - GRPC_CLOSURE_INIT(&t->init_keepalive_ping, init_keepalive_ping, t, - grpc_schedule_on_exec_ctx); + grpc_combiner_scheduler(t->combiner)); + GRPC_CLOSURE_INIT(&t->finish_bdp_ping_locked, finish_bdp_ping_locked, t, + grpc_combiner_scheduler(t->combiner)); + GRPC_CLOSURE_INIT(&t->next_bdp_ping_timer_expired_locked, + next_bdp_ping_timer_expired_locked, t, + grpc_combiner_scheduler(t->combiner)); + GRPC_CLOSURE_INIT(&t->init_keepalive_ping_locked, init_keepalive_ping_locked, + t, grpc_combiner_scheduler(t->combiner)); GRPC_CLOSURE_INIT(&t->start_keepalive_ping_locked, - start_keepalive_ping_locked, t, grpc_schedule_on_exec_ctx); - GRPC_CLOSURE_INIT(&t->finish_keepalive_ping, finish_keepalive_ping, t, - grpc_schedule_on_exec_ctx); - GRPC_CLOSURE_INIT(&t->keepalive_watchdog_fired, keepalive_watchdog_fired, t, - grpc_schedule_on_exec_ctx); + start_keepalive_ping_locked, t, + grpc_combiner_scheduler(t->combiner)); + GRPC_CLOSURE_INIT(&t->finish_keepalive_ping_locked, + finish_keepalive_ping_locked, t, + grpc_combiner_scheduler(t->combiner)); + GRPC_CLOSURE_INIT(&t->keepalive_watchdog_fired_locked, + keepalive_watchdog_fired_locked, t, + grpc_combiner_scheduler(t->combiner)); } static void init_transport_keepalive_settings(grpc_chttp2_transport* t) { @@ -450,7 +458,7 @@ static void init_keepalive_pings_if_enabled(grpc_chttp2_transport* t) { GRPC_CHTTP2_REF_TRANSPORT(t, "init keepalive ping"); grpc_timer_init(&t->keepalive_ping_timer, grpc_core::ExecCtx::Get()->Now() + t->keepalive_time, - &t->init_keepalive_ping); + &t->init_keepalive_ping_locked); } else { /* Use GRPC_CHTTP2_KEEPALIVE_STATE_DISABLED to indicate there are no inflight keeaplive timers */ @@ -465,6 +473,7 @@ grpc_chttp2_transport::grpc_chttp2_transport( ep(ep), peer_string(grpc_endpoint_get_peer(ep)), resource_user(resource_user), + combiner(grpc_combiner_create()), state_tracker(is_client ? "client_transport" : "server_transport", GRPC_CHANNEL_READY), is_client(is_client), @@ -548,20 +557,24 @@ grpc_chttp2_transport::grpc_chttp2_transport( post_benign_reclaimer(this); } -static void destroy_transport(grpc_transport* gt) { - grpc_chttp2_transport* t = reinterpret_cast(gt); - { - grpc_core::MutexLock lock(&t->mu); - t->destroying = 1; - close_transport_locked( - t, grpc_error_set_int( - GRPC_ERROR_CREATE_FROM_STATIC_STRING("Transport destroyed"), - GRPC_ERROR_INT_OCCURRED_DURING_WRITE, t->write_state)); - } +static void destroy_transport_locked(void* tp, grpc_error* error) { + grpc_chttp2_transport* t = static_cast(tp); + t->destroying = 1; + close_transport_locked( + t, grpc_error_set_int( + GRPC_ERROR_CREATE_FROM_STATIC_STRING("Transport destroyed"), + GRPC_ERROR_INT_OCCURRED_DURING_WRITE, t->write_state)); // Must be the last line. GRPC_CHTTP2_UNREF_TRANSPORT(t, "destroy"); } +static void destroy_transport(grpc_transport* gt) { + grpc_chttp2_transport* t = reinterpret_cast(gt); + GRPC_CLOSURE_SCHED(GRPC_CLOSURE_CREATE(destroy_transport_locked, t, + grpc_combiner_scheduler(t->combiner)), + GRPC_ERROR_NONE); +} + static void close_transport_locked(grpc_chttp2_transport* t, grpc_error* error) { end_all_the_calls(t, GRPC_ERROR_REF(error)); @@ -671,67 +684,64 @@ grpc_chttp2_stream::grpc_chttp2_stream(grpc_chttp2_transport* t, grpc_slice_buffer_init(&unprocessed_incoming_frames_buffer); grpc_slice_buffer_init(&flow_controlled_buffer); - GRPC_CLOSURE_INIT(&complete_fetch, ::complete_fetch, this, - grpc_schedule_on_exec_ctx); + GRPC_CLOSURE_INIT(&complete_fetch_locked, ::complete_fetch_locked, this, + grpc_combiner_scheduler(t->combiner)); GRPC_CLOSURE_INIT(&reset_byte_stream, ::reset_byte_stream, this, - grpc_schedule_on_exec_ctx); + grpc_combiner_scheduler(t->combiner)); } grpc_chttp2_stream::~grpc_chttp2_stream() { - { - grpc_core::MutexLock lock(&t->mu); - if (t->channelz_socket != nullptr) { - if ((t->is_client && eos_received) || (!t->is_client && eos_sent)) { - t->channelz_socket->RecordStreamSucceeded(); - } else { - t->channelz_socket->RecordStreamFailed(); - } + if (t->channelz_socket != nullptr) { + if ((t->is_client && eos_received) || (!t->is_client && eos_sent)) { + t->channelz_socket->RecordStreamSucceeded(); + } else { + t->channelz_socket->RecordStreamFailed(); } + } - GPR_ASSERT((write_closed && read_closed) || id == 0); - if (id != 0) { - GPR_ASSERT(grpc_chttp2_stream_map_find(&t->stream_map, id) == nullptr); - } + GPR_ASSERT((write_closed && read_closed) || id == 0); + if (id != 0) { + GPR_ASSERT(grpc_chttp2_stream_map_find(&t->stream_map, id) == nullptr); + } - grpc_slice_buffer_destroy_internal(&unprocessed_incoming_frames_buffer); - grpc_slice_buffer_destroy_internal(&frame_storage); - if (stream_compression_method != - GRPC_STREAM_COMPRESSION_IDENTITY_COMPRESS) { - grpc_slice_buffer_destroy_internal(&compressed_data_buffer); - } - if (stream_decompression_method != - GRPC_STREAM_COMPRESSION_IDENTITY_DECOMPRESS) { - grpc_slice_buffer_destroy_internal(&decompressed_data_buffer); - } + grpc_slice_buffer_destroy_internal(&unprocessed_incoming_frames_buffer); + grpc_slice_buffer_destroy_internal(&frame_storage); + if (stream_compression_method != GRPC_STREAM_COMPRESSION_IDENTITY_COMPRESS) { + grpc_slice_buffer_destroy_internal(&compressed_data_buffer); + } + if (stream_decompression_method != + GRPC_STREAM_COMPRESSION_IDENTITY_DECOMPRESS) { + grpc_slice_buffer_destroy_internal(&decompressed_data_buffer); + } - grpc_chttp2_list_remove_stalled_by_transport(t, this); - grpc_chttp2_list_remove_stalled_by_stream(t, this); + grpc_chttp2_list_remove_stalled_by_transport(t, this); + grpc_chttp2_list_remove_stalled_by_stream(t, this); - for (int i = 0; i < STREAM_LIST_COUNT; i++) { - if (GPR_UNLIKELY(included[i])) { - gpr_log(GPR_ERROR, "%s stream %d still included in list %d", - t->is_client ? "client" : "server", id, i); - abort(); - } + for (int i = 0; i < STREAM_LIST_COUNT; i++) { + if (GPR_UNLIKELY(included[i])) { + gpr_log(GPR_ERROR, "%s stream %d still included in list %d", + t->is_client ? "client" : "server", id, i); + abort(); } + } - GPR_ASSERT(send_initial_metadata_finished == nullptr); - GPR_ASSERT(fetching_send_message == nullptr); - GPR_ASSERT(send_trailing_metadata_finished == nullptr); - GPR_ASSERT(recv_initial_metadata_ready == nullptr); - GPR_ASSERT(recv_message_ready == nullptr); - GPR_ASSERT(recv_trailing_metadata_finished == nullptr); - grpc_slice_buffer_destroy_internal(&flow_controlled_buffer); - GRPC_ERROR_UNREF(read_closed_error); - GRPC_ERROR_UNREF(write_closed_error); - GRPC_ERROR_UNREF(byte_stream_error); + GPR_ASSERT(send_initial_metadata_finished == nullptr); + GPR_ASSERT(fetching_send_message == nullptr); + GPR_ASSERT(send_trailing_metadata_finished == nullptr); + GPR_ASSERT(recv_initial_metadata_ready == nullptr); + GPR_ASSERT(recv_message_ready == nullptr); + GPR_ASSERT(recv_trailing_metadata_finished == nullptr); + grpc_slice_buffer_destroy_internal(&flow_controlled_buffer); + GRPC_ERROR_UNREF(read_closed_error); + GRPC_ERROR_UNREF(write_closed_error); + GRPC_ERROR_UNREF(byte_stream_error); - flow_control.Destroy(); + flow_control.Destroy(); - if (t->resource_user != nullptr) { - grpc_resource_user_free(t->resource_user, GRPC_RESOURCE_QUOTA_CALL_SIZE); - } + if (t->resource_user != nullptr) { + grpc_resource_user_free(t->resource_user, GRPC_RESOURCE_QUOTA_CALL_SIZE); } + GRPC_CHTTP2_UNREF_TRANSPORT(t, "stream"); GRPC_CLOSURE_SCHED(destroy_stream_arg, GRPC_ERROR_NONE); } @@ -745,9 +755,16 @@ static int init_stream(grpc_transport* gt, grpc_stream* gs, return 0; } +static void destroy_stream_locked(void* sp, grpc_error* error) { + GPR_TIMER_SCOPE("destroy_stream", 0); + grpc_chttp2_stream* s = static_cast(sp); + s->~grpc_chttp2_stream(); +} + static void destroy_stream(grpc_transport* gt, grpc_stream* gs, grpc_closure* then_schedule_closure) { GPR_TIMER_SCOPE("destroy_stream", 0); + grpc_chttp2_transport* t = reinterpret_cast(gt); grpc_chttp2_stream* s = reinterpret_cast(gs); if (s->stream_compression_method != GRPC_STREAM_COMPRESSION_IDENTITY_COMPRESS && @@ -763,7 +780,10 @@ static void destroy_stream(grpc_transport* gt, grpc_stream* gs, } s->destroy_stream_arg = then_schedule_closure; - s->~grpc_chttp2_stream(); + GRPC_CLOSURE_SCHED( + GRPC_CLOSURE_INIT(&s->destroy_stream, destroy_stream_locked, s, + grpc_combiner_scheduler(t->combiner)), + GRPC_ERROR_NONE); } grpc_chttp2_stream* grpc_chttp2_parsing_accept_stream(grpc_chttp2_transport* t, @@ -908,29 +928,26 @@ void grpc_chttp2_initiate_write(grpc_chttp2_transport* t, grpc_chttp2_initiate_write_reason_string(reason)); t->is_first_write_in_batch = true; GRPC_CHTTP2_REF_TRANSPORT(t, "writing"); - // TODO(yashykt) : When we were using combiners, we were using the finally - // version, so that the write action would happen after we were done - // queueing up all the writes that we wanted. Maybe do something similar? - // Keeping the earlier comment for posterity - - /* Note that the 'write_action_begin' closure is being scheduled + /* Note that the 'write_action_begin_locked' closure is being scheduled * on the 'finally_scheduler' of t->combiner. This means that - * 'write_action_begin' is called only *after* all the other + * 'write_action_begin_locked' is called only *after* all the other * closures (some of which are potentially initiating more writes on the * transport) are executed on the t->combiner. * * The reason for scheduling on finally_scheduler is to make sure we batch - * as many writes as possible. 'write_action_begin' is the function + * as many writes as possible. 'write_action_begin_locked' is the function * that gathers all the relevant bytes (which are at various places in the * grpc_chttp2_transport structure) and append them to 'outbuf' field in * grpc_chttp2_transport thereby batching what would have been potentially * multiple write operations. * - * Also, 'write_action_begin' only gathers the bytes into outbuf. + * Also, 'write_action_begin_locked' only gathers the bytes into outbuf. * It does not call the endpoint to write the bytes. That is done by the - * 'write_action' (which is scheduled by 'write_action_begin') */ + * 'write_action' (which is scheduled by 'write_action_begin_locked') */ GRPC_CLOSURE_SCHED( - GRPC_CLOSURE_INIT(&t->write_action_begin, write_action_begin, t, - grpc_schedule_on_exec_ctx), + GRPC_CLOSURE_INIT(&t->write_action_begin_locked, + write_action_begin_locked, t, + grpc_combiner_finally_scheduler(t->combiner)), GRPC_ERROR_NONE); break; case GRPC_CHTTP2_WRITE_STATE_WRITING: @@ -996,10 +1013,9 @@ static const char* begin_writing_desc(bool partial, bool inlined) { GPR_UNREACHABLE_CODE(return "bad state tuple"); } -static void write_action_begin(void* gt, grpc_error* error_ignored) { - GPR_TIMER_SCOPE("write_action_begin", 0); +static void write_action_begin_locked(void* gt, grpc_error* error_ignored) { + GPR_TIMER_SCOPE("write_action_begin_locked", 0); grpc_chttp2_transport* t = static_cast(gt); - grpc_core::ReleasableMutexLock lock(&t->mu); GPR_ASSERT(t->write_state != GRPC_CHTTP2_WRITE_STATE_IDLE); grpc_chttp2_begin_write_result r; if (t->closed_with_error != GRPC_ERROR_NONE) { @@ -1040,11 +1056,9 @@ static void write_action_begin(void* gt, grpc_error* error_ignored) { t->reading_paused_on_pending_induced_frames = false; continue_read_action_locked(t); } - lock.Unlock(); } else { GRPC_STATS_INC_HTTP2_SPURIOUS_WRITES_BEGUN(); set_write_state(t, GRPC_CHTTP2_WRITE_STATE_IDLE, "begin writing nothing"); - lock.Unlock(); GRPC_CHTTP2_UNREF_TRANSPORT(t, "writing"); } } @@ -1054,67 +1068,63 @@ static void write_action(void* gt, grpc_error* error) { grpc_chttp2_transport* t = static_cast(gt); void* cl = t->cl; t->cl = nullptr; - grpc_endpoint_write(t->ep, &t->outbuf, - GRPC_CLOSURE_INIT(&t->write_action_end, write_action_end, - t, grpc_schedule_on_exec_ctx), - cl); + grpc_endpoint_write( + t->ep, &t->outbuf, + GRPC_CLOSURE_INIT(&t->write_action_end_locked, write_action_end_locked, t, + grpc_combiner_scheduler(t->combiner)), + cl); } /* Callback from the grpc_endpoint after bytes have been written by calling * sendmsg */ -static void write_action_end(void* tp, grpc_error* error) { +static void write_action_end_locked(void* tp, grpc_error* error) { GPR_TIMER_SCOPE("terminate_writing_with_lock", 0); grpc_chttp2_transport* t = static_cast(tp); - { - grpc_core::MutexLock lock(&t->mu); - bool closed = false; - if (error != GRPC_ERROR_NONE) { - close_transport_locked(t, GRPC_ERROR_REF(error)); - closed = true; - } - if (t->sent_goaway_state == GRPC_CHTTP2_GOAWAY_SEND_SCHEDULED) { - t->sent_goaway_state = GRPC_CHTTP2_GOAWAY_SENT; - closed = true; - if (grpc_chttp2_stream_map_size(&t->stream_map) == 0) { - close_transport_locked( - t, GRPC_ERROR_CREATE_FROM_STATIC_STRING("goaway sent")); - } - } + bool closed = false; + if (error != GRPC_ERROR_NONE) { + close_transport_locked(t, GRPC_ERROR_REF(error)); + closed = true; + } - switch (t->write_state) { - case GRPC_CHTTP2_WRITE_STATE_IDLE: - GPR_UNREACHABLE_CODE(break); - case GRPC_CHTTP2_WRITE_STATE_WRITING: - GPR_TIMER_MARK("state=writing", 0); - set_write_state(t, GRPC_CHTTP2_WRITE_STATE_IDLE, "finish writing"); - break; - case GRPC_CHTTP2_WRITE_STATE_WRITING_WITH_MORE: - GPR_TIMER_MARK("state=writing_stale_no_poller", 0); - set_write_state(t, GRPC_CHTTP2_WRITE_STATE_WRITING, "continue writing"); - t->is_first_write_in_batch = false; - GRPC_CHTTP2_REF_TRANSPORT(t, "writing"); - // If the transport is closed, we will retry writing on the endpoint - // and next write may contain part of the currently serialized frames. - // So, we should only call the run_after_write callbacks when the next - // write finishes, or the callbacks will be invoked when the stream is - // closed. - if (!closed) { - GRPC_CLOSURE_LIST_SCHED(&t->run_after_write); - } - // TODO(yashykt) : When we were using combiners, we were using the - // finally version, so that the write action would happen after we were - // done queueing up all the writes that we wanted. Maybe do something - // similar? - GRPC_CLOSURE_SCHED( - GRPC_CLOSURE_INIT(&t->write_action_begin, write_action_begin, t, - grpc_schedule_on_exec_ctx), - GRPC_ERROR_NONE); - break; + if (t->sent_goaway_state == GRPC_CHTTP2_GOAWAY_SEND_SCHEDULED) { + t->sent_goaway_state = GRPC_CHTTP2_GOAWAY_SENT; + closed = true; + if (grpc_chttp2_stream_map_size(&t->stream_map) == 0) { + close_transport_locked( + t, GRPC_ERROR_CREATE_FROM_STATIC_STRING("goaway sent")); } + } - grpc_chttp2_end_write(t, GRPC_ERROR_REF(error)); + switch (t->write_state) { + case GRPC_CHTTP2_WRITE_STATE_IDLE: + GPR_UNREACHABLE_CODE(break); + case GRPC_CHTTP2_WRITE_STATE_WRITING: + GPR_TIMER_MARK("state=writing", 0); + set_write_state(t, GRPC_CHTTP2_WRITE_STATE_IDLE, "finish writing"); + break; + case GRPC_CHTTP2_WRITE_STATE_WRITING_WITH_MORE: + GPR_TIMER_MARK("state=writing_stale_no_poller", 0); + set_write_state(t, GRPC_CHTTP2_WRITE_STATE_WRITING, "continue writing"); + t->is_first_write_in_batch = false; + GRPC_CHTTP2_REF_TRANSPORT(t, "writing"); + // If the transport is closed, we will retry writing on the endpoint + // and next write may contain part of the currently serialized frames. + // So, we should only call the run_after_write callbacks when the next + // write finishes, or the callbacks will be invoked when the stream is + // closed. + if (!closed) { + GRPC_CLOSURE_LIST_SCHED(&t->run_after_write); + } + GRPC_CLOSURE_RUN( + GRPC_CLOSURE_INIT(&t->write_action_begin_locked, + write_action_begin_locked, t, + grpc_combiner_finally_scheduler(t->combiner)), + GRPC_ERROR_NONE); + break; } + + grpc_chttp2_end_write(t, GRPC_ERROR_REF(error)); GRPC_CHTTP2_UNREF_TRANSPORT(t, "writing"); } @@ -1360,7 +1370,8 @@ static void continue_fetching_send_locked(grpc_chttp2_transport* t, } s->fetching_send_message.reset(); return; /* early out */ - } else if (s->fetching_send_message->Next(UINT32_MAX, &s->complete_fetch)) { + } else if (s->fetching_send_message->Next(UINT32_MAX, + &s->complete_fetch_locked)) { grpc_error* error = s->fetching_send_message->Pull(&s->fetching_slice); if (error != GRPC_ERROR_NONE) { s->fetching_send_message.reset(); @@ -1372,10 +1383,9 @@ static void continue_fetching_send_locked(grpc_chttp2_transport* t, } } -static void complete_fetch(void* gs, grpc_error* error) { +static void complete_fetch_locked(void* gs, grpc_error* error) { grpc_chttp2_stream* s = static_cast(gs); grpc_chttp2_transport* t = s->t; - grpc_core::MutexLock lock(&t->mu); if (error == GRPC_ERROR_NONE) { error = s->fetching_send_message->Pull(&s->fetching_slice); if (error == GRPC_ERROR_NONE) { @@ -1402,40 +1412,24 @@ static void log_metadata(const grpc_metadata_batch* md_batch, uint32_t id, } } -static void perform_stream_op(grpc_transport* gt, grpc_stream* gs, - grpc_transport_stream_op_batch* op) { - GPR_TIMER_SCOPE("perform_stream_op", 0); - grpc_chttp2_transport* t = reinterpret_cast(gt); - grpc_chttp2_stream* s = reinterpret_cast(gs); - grpc_transport_stream_op_batch_payload* op_payload = op->payload; - - if (!t->is_client) { - if (op->send_initial_metadata) { - grpc_millis deadline = - op_payload->send_initial_metadata.send_initial_metadata->deadline; - GPR_ASSERT(deadline == GRPC_MILLIS_INF_FUTURE); - } - if (op->send_trailing_metadata) { - grpc_millis deadline = - op_payload->send_trailing_metadata.send_trailing_metadata->deadline; - GPR_ASSERT(deadline == GRPC_MILLIS_INF_FUTURE); - } - } +static void perform_stream_op_locked(void* stream_op, + grpc_error* error_ignored) { + GPR_TIMER_SCOPE("perform_stream_op_locked", 0); - if (GRPC_TRACE_FLAG_ENABLED(grpc_http_trace)) { - char* str = grpc_transport_stream_op_batch_string(op); - gpr_log(GPR_INFO, "perform_stream_op[s=%p]: %s", s, str); - gpr_free(str); - } + grpc_transport_stream_op_batch* op = + static_cast(stream_op); + grpc_chttp2_stream* s = + static_cast(op->handler_private.extra_arg); + grpc_transport_stream_op_batch_payload* op_payload = op->payload; + grpc_chttp2_transport* t = s->t; - grpc_core::MutexLock lock(&t->mu); GRPC_STATS_INC_HTTP2_OP_BATCHES(); - s->context = op_payload->context; + s->context = op->payload->context; s->traced = op->is_traced; if (GRPC_TRACE_FLAG_ENABLED(grpc_http_trace)) { char* str = grpc_transport_stream_op_batch_string(op); - gpr_log(GPR_INFO, "perform_stream_op: %s; on_complete = %p", str, + gpr_log(GPR_INFO, "perform_stream_op_locked: %s; on_complete = %p", str, op->on_complete); gpr_free(str); if (op->send_initial_metadata) { @@ -1708,6 +1702,41 @@ static void perform_stream_op(grpc_transport* gt, grpc_stream* gs, grpc_chttp2_complete_closure_step(t, s, &on_complete, GRPC_ERROR_NONE, "op->on_complete"); } + + GRPC_CHTTP2_STREAM_UNREF(s, "perform_stream_op"); +} + +static void perform_stream_op(grpc_transport* gt, grpc_stream* gs, + grpc_transport_stream_op_batch* op) { + GPR_TIMER_SCOPE("perform_stream_op", 0); + grpc_chttp2_transport* t = reinterpret_cast(gt); + grpc_chttp2_stream* s = reinterpret_cast(gs); + + if (!t->is_client) { + if (op->send_initial_metadata) { + grpc_millis deadline = + op->payload->send_initial_metadata.send_initial_metadata->deadline; + GPR_ASSERT(deadline == GRPC_MILLIS_INF_FUTURE); + } + if (op->send_trailing_metadata) { + grpc_millis deadline = + op->payload->send_trailing_metadata.send_trailing_metadata->deadline; + GPR_ASSERT(deadline == GRPC_MILLIS_INF_FUTURE); + } + } + + if (GRPC_TRACE_FLAG_ENABLED(grpc_http_trace)) { + char* str = grpc_transport_stream_op_batch_string(op); + gpr_log(GPR_INFO, "perform_stream_op[s=%p]: %s", s, str); + gpr_free(str); + } + + GRPC_CHTTP2_STREAM_REF(s, "perform_stream_op"); + op->handler_private.extra_arg = gs; + GRPC_CLOSURE_SCHED( + GRPC_CLOSURE_INIT(&op->handler_private.closure, perform_stream_op_locked, + op, grpc_combiner_scheduler(t->combiner)), + GRPC_ERROR_NONE); } static void cancel_pings(grpc_chttp2_transport* t, grpc_error* error) { @@ -1717,12 +1746,7 @@ static void cancel_pings(grpc_chttp2_transport* t, grpc_error* error) { GPR_ASSERT(error != GRPC_ERROR_NONE); for (size_t j = 0; j < GRPC_CHTTP2_PCL_COUNT; j++) { grpc_closure_list_fail_all(&pq->lists[j], GRPC_ERROR_REF(error)); - if (j == GRPC_CHTTP2_PCL_INITIATE) { - GRPC_CLOSURE_LIST_RUN(&pq->lists[j]); - } else { - // TODO(yashykt) : Use GRPC_CLOSURE_LIST_RUN for this too. - GRPC_CLOSURE_LIST_SCHED(&pq->lists[j]); - } + GRPC_CLOSURE_LIST_SCHED(&pq->lists[j]); } GRPC_ERROR_UNREF(error); } @@ -1750,9 +1774,8 @@ static void send_keepalive_ping_locked(grpc_chttp2_transport* t) { if (t->closed_with_error != GRPC_ERROR_NONE) { GRPC_CLOSURE_RUN(&t->start_keepalive_ping_locked, GRPC_ERROR_REF(t->closed_with_error)); - // TODO(yashykt) : Change this to GRPC_CLOSURE_RUN too - GRPC_CLOSURE_SCHED(&t->finish_keepalive_ping, - GRPC_ERROR_REF(t->closed_with_error)); + GRPC_CLOSURE_RUN(&t->finish_keepalive_ping_locked, + GRPC_ERROR_REF(t->closed_with_error)); return; } grpc_chttp2_ping_queue* pq = &t->ping_queue; @@ -1760,25 +1783,22 @@ static void send_keepalive_ping_locked(grpc_chttp2_transport* t) { /* There is a ping in flight. Add yourself to the inflight closure list. */ GRPC_CLOSURE_RUN(&t->start_keepalive_ping_locked, GRPC_ERROR_NONE); grpc_closure_list_append(&pq->lists[GRPC_CHTTP2_PCL_INFLIGHT], - &t->finish_keepalive_ping, GRPC_ERROR_NONE); + &t->finish_keepalive_ping_locked, GRPC_ERROR_NONE); return; } grpc_closure_list_append(&pq->lists[GRPC_CHTTP2_PCL_INITIATE], &t->start_keepalive_ping_locked, GRPC_ERROR_NONE); grpc_closure_list_append(&pq->lists[GRPC_CHTTP2_PCL_NEXT], - &t->finish_keepalive_ping, GRPC_ERROR_NONE); + &t->finish_keepalive_ping_locked, GRPC_ERROR_NONE); } -static void retry_initiate_ping(void* tp, grpc_error* error) { +static void retry_initiate_ping_locked(void* tp, grpc_error* error) { grpc_chttp2_transport* t = static_cast(tp); - { - grpc_core::MutexLock lock(&t->mu); - t->ping_state.is_delayed_ping_timer_set = false; - if (error == GRPC_ERROR_NONE) { - grpc_chttp2_initiate_write(t, GRPC_CHTTP2_INITIATE_WRITE_RETRY_SEND_PING); - } + t->ping_state.is_delayed_ping_timer_set = false; + if (error == GRPC_ERROR_NONE) { + grpc_chttp2_initiate_write(t, GRPC_CHTTP2_INITIATE_WRITE_RETRY_SEND_PING); } - GRPC_CHTTP2_UNREF_TRANSPORT(t, "retry_initiate_ping"); + GRPC_CHTTP2_UNREF_TRANSPORT(t, "retry_initiate_ping_locked"); } void grpc_chttp2_ack_ping(grpc_chttp2_transport* t, uint64_t id) { @@ -1789,7 +1809,6 @@ void grpc_chttp2_ack_ping(grpc_chttp2_transport* t, uint64_t id) { gpr_free(from); return; } - // TODO(yashkt) : Change this to GRPC_CLOSURE_LIST_RUN GRPC_CLOSURE_LIST_SCHED(&pq->lists[GRPC_CHTTP2_PCL_INFLIGHT]); if (!grpc_closure_list_empty(pq->lists[GRPC_CHTTP2_PCL_NEXT])) { grpc_chttp2_initiate_write(t, GRPC_CHTTP2_INITIATE_WRITE_CONTINUE_PINGS); @@ -1827,14 +1846,12 @@ void grpc_chttp2_add_ping_strike(grpc_chttp2_transport* t) { } } -static void perform_transport_op(grpc_transport* gt, grpc_transport_op* op) { - grpc_chttp2_transport* t = reinterpret_cast(gt); - if (GRPC_TRACE_FLAG_ENABLED(grpc_http_trace)) { - char* msg = grpc_transport_op_string(op); - gpr_log(GPR_INFO, "perform_transport_op[t=%p]: %s", t, msg); - gpr_free(msg); - } - grpc_core::MutexLock lock(&t->mu); +static void perform_transport_op_locked(void* stream_op, + grpc_error* error_ignored) { + grpc_transport_op* op = static_cast(stream_op); + grpc_chttp2_transport* t = + static_cast(op->handler_private.extra_arg); + if (op->goaway_error) { send_goaway(t, op->goaway_error); } @@ -1869,7 +1886,24 @@ static void perform_transport_op(grpc_transport* gt, grpc_transport_op* op) { close_transport_locked(t, op->disconnect_with_error); } - GRPC_CLOSURE_SCHED(op->on_consumed, GRPC_ERROR_NONE); + GRPC_CLOSURE_RUN(op->on_consumed, GRPC_ERROR_NONE); + + GRPC_CHTTP2_UNREF_TRANSPORT(t, "transport_op"); +} + +static void perform_transport_op(grpc_transport* gt, grpc_transport_op* op) { + grpc_chttp2_transport* t = reinterpret_cast(gt); + if (GRPC_TRACE_FLAG_ENABLED(grpc_http_trace)) { + char* msg = grpc_transport_op_string(op); + gpr_log(GPR_INFO, "perform_transport_op[t=%p]: %s", t, msg); + gpr_free(msg); + } + op->handler_private.extra_arg = gt; + GRPC_CHTTP2_REF_TRANSPORT(t, "transport_op"); + GRPC_CLOSURE_SCHED(GRPC_CLOSURE_INIT(&op->handler_private.closure, + perform_transport_op_locked, op, + grpc_combiner_scheduler(t->combiner)), + GRPC_ERROR_NONE); } /******************************************************************************* @@ -2510,11 +2544,11 @@ static grpc_error* try_http_parsing(grpc_chttp2_transport* t) { return error; } -static void read_action(void* tp, grpc_error* error) { +static void read_action_locked(void* tp, grpc_error* error) { GPR_TIMER_SCOPE("reading_action_locked", 0); grpc_chttp2_transport* t = static_cast(tp); - grpc_core::ReleasableMutexLock lock(&t->mu); + GRPC_ERROR_REF(error); grpc_error* err = error; @@ -2598,9 +2632,7 @@ static void read_action(void* tp, grpc_error* error) { } else { continue_read_action_locked(t); } - lock.Unlock(); } else { - lock.Unlock(); GRPC_CHTTP2_UNREF_TRANSPORT(t, "reading_action"); } @@ -2609,7 +2641,7 @@ static void read_action(void* tp, grpc_error* error) { static void continue_read_action_locked(grpc_chttp2_transport* t) { const bool urgent = t->goaway_error != GRPC_ERROR_NONE; - grpc_endpoint_read(t->ep, &t->read_buffer, &t->read_action, urgent); + grpc_endpoint_read(t->ep, &t->read_buffer, &t->read_action_locked, urgent); grpc_chttp2_act_on_flowctl_action(t->flow_control->MakeAction(), t, nullptr); } @@ -2617,13 +2649,11 @@ static void continue_read_action_locked(grpc_chttp2_transport* t) { // that kicks off finishes, it's unreffed static void schedule_bdp_ping_locked(grpc_chttp2_transport* t) { t->flow_control->bdp_estimator()->SchedulePing(); - send_ping_locked(t, &t->start_bdp_ping_locked, &t->finish_bdp_ping); + send_ping_locked(t, &t->start_bdp_ping_locked, &t->finish_bdp_ping_locked); } static void start_bdp_ping_locked(void* tp, grpc_error* error) { grpc_chttp2_transport* t = static_cast(tp); - // No need to take a lock. This closure will always be run while already - // holding the lock. if (GRPC_TRACE_FLAG_ENABLED(grpc_http_trace)) { gpr_log(GPR_INFO, "%s: Start BDP ping err=%s", t->peer_string, grpc_error_string(error)); @@ -2638,15 +2668,13 @@ static void start_bdp_ping_locked(void* tp, grpc_error* error) { t->flow_control->bdp_estimator()->StartPing(); } -static void finish_bdp_ping(void* tp, grpc_error* error) { +static void finish_bdp_ping_locked(void* tp, grpc_error* error) { grpc_chttp2_transport* t = static_cast(tp); - grpc_core::ReleasableMutexLock lock(&t->mu); if (GRPC_TRACE_FLAG_ENABLED(grpc_http_trace)) { gpr_log(GPR_INFO, "%s: Complete BDP ping err=%s", t->peer_string, grpc_error_string(error)); } if (error != GRPC_ERROR_NONE || t->closed_with_error != GRPC_ERROR_NONE) { - lock.Unlock(); GRPC_CHTTP2_UNREF_TRANSPORT(t, "bdp_ping"); return; } @@ -2656,16 +2684,14 @@ static void finish_bdp_ping(void* tp, grpc_error* error) { GPR_ASSERT(!t->have_next_bdp_ping_timer); t->have_next_bdp_ping_timer = true; grpc_timer_init(&t->next_bdp_ping_timer, next_ping, - &t->next_bdp_ping_timer_expired); + &t->next_bdp_ping_timer_expired_locked); } -static void next_bdp_ping_timer_expired(void* tp, grpc_error* error) { +static void next_bdp_ping_timer_expired_locked(void* tp, grpc_error* error) { grpc_chttp2_transport* t = static_cast(tp); - grpc_core::ReleasableMutexLock lock(&t->mu); GPR_ASSERT(t->have_next_bdp_ping_timer); t->have_next_bdp_ping_timer = false; if (error != GRPC_ERROR_NONE) { - lock.Unlock(); GRPC_CHTTP2_UNREF_TRANSPORT(t, "bdp_ping"); return; } @@ -2739,35 +2765,31 @@ void grpc_chttp2_config_default_keepalive_args(grpc_channel_args* args, } } -static void init_keepalive_ping(void* arg, grpc_error* error) { +static void init_keepalive_ping_locked(void* arg, grpc_error* error) { grpc_chttp2_transport* t = static_cast(arg); - { - grpc_core::MutexLock lock(&t->mu); - GPR_ASSERT(t->keepalive_state == GRPC_CHTTP2_KEEPALIVE_STATE_WAITING); - if (t->destroying || t->closed_with_error != GRPC_ERROR_NONE) { - t->keepalive_state = GRPC_CHTTP2_KEEPALIVE_STATE_DYING; - } else if (error == GRPC_ERROR_NONE) { - if (t->keepalive_permit_without_calls || - grpc_chttp2_stream_map_size(&t->stream_map) > 0) { - t->keepalive_state = GRPC_CHTTP2_KEEPALIVE_STATE_PINGING; - GRPC_CHTTP2_REF_TRANSPORT(t, "keepalive ping end"); - grpc_timer_init_unset(&t->keepalive_watchdog_timer); - send_keepalive_ping_locked(t); - grpc_chttp2_initiate_write(t, - GRPC_CHTTP2_INITIATE_WRITE_KEEPALIVE_PING); - } else { - GRPC_CHTTP2_REF_TRANSPORT(t, "init keepalive ping"); - grpc_timer_init(&t->keepalive_ping_timer, - grpc_core::ExecCtx::Get()->Now() + t->keepalive_time, - &t->init_keepalive_ping); - } - } else if (error == GRPC_ERROR_CANCELLED) { - /* The keepalive ping timer may be cancelled by bdp */ + GPR_ASSERT(t->keepalive_state == GRPC_CHTTP2_KEEPALIVE_STATE_WAITING); + if (t->destroying || t->closed_with_error != GRPC_ERROR_NONE) { + t->keepalive_state = GRPC_CHTTP2_KEEPALIVE_STATE_DYING; + } else if (error == GRPC_ERROR_NONE) { + if (t->keepalive_permit_without_calls || + grpc_chttp2_stream_map_size(&t->stream_map) > 0) { + t->keepalive_state = GRPC_CHTTP2_KEEPALIVE_STATE_PINGING; + GRPC_CHTTP2_REF_TRANSPORT(t, "keepalive ping end"); + grpc_timer_init_unset(&t->keepalive_watchdog_timer); + send_keepalive_ping_locked(t); + grpc_chttp2_initiate_write(t, GRPC_CHTTP2_INITIATE_WRITE_KEEPALIVE_PING); + } else { GRPC_CHTTP2_REF_TRANSPORT(t, "init keepalive ping"); grpc_timer_init(&t->keepalive_ping_timer, grpc_core::ExecCtx::Get()->Now() + t->keepalive_time, - &t->init_keepalive_ping); + &t->init_keepalive_ping_locked); } + } else if (error == GRPC_ERROR_CANCELLED) { + /* The keepalive ping timer may be cancelled by bdp */ + GRPC_CHTTP2_REF_TRANSPORT(t, "init keepalive ping"); + grpc_timer_init(&t->keepalive_ping_timer, + grpc_core::ExecCtx::Get()->Now() + t->keepalive_time, + &t->init_keepalive_ping_locked); } GRPC_CHTTP2_UNREF_TRANSPORT(t, "init keepalive ping"); } @@ -2777,8 +2799,6 @@ static void start_keepalive_ping_locked(void* arg, grpc_error* error) { if (error != GRPC_ERROR_NONE) { return; } - // No need to take a lock. This closure will always be run while already - // holding the lock. if (t->channelz_socket != nullptr) { t->channelz_socket->RecordKeepaliveSent(); } @@ -2788,52 +2808,46 @@ static void start_keepalive_ping_locked(void* arg, grpc_error* error) { GRPC_CHTTP2_REF_TRANSPORT(t, "keepalive watchdog"); grpc_timer_init(&t->keepalive_watchdog_timer, grpc_core::ExecCtx::Get()->Now() + t->keepalive_timeout, - &t->keepalive_watchdog_fired); + &t->keepalive_watchdog_fired_locked); } -static void finish_keepalive_ping(void* arg, grpc_error* error) { +static void finish_keepalive_ping_locked(void* arg, grpc_error* error) { grpc_chttp2_transport* t = static_cast(arg); - { - grpc_core::MutexLock lock(&t->mu); - if (t->keepalive_state == GRPC_CHTTP2_KEEPALIVE_STATE_PINGING) { - if (error == GRPC_ERROR_NONE) { - if (GRPC_TRACE_FLAG_ENABLED(grpc_http_trace)) { - gpr_log(GPR_INFO, "%s: Finish keepalive ping", t->peer_string); - } - t->keepalive_state = GRPC_CHTTP2_KEEPALIVE_STATE_WAITING; - grpc_timer_cancel(&t->keepalive_watchdog_timer); - GRPC_CHTTP2_REF_TRANSPORT(t, "init keepalive ping"); - grpc_timer_init(&t->keepalive_ping_timer, - grpc_core::ExecCtx::Get()->Now() + t->keepalive_time, - &t->init_keepalive_ping); + if (t->keepalive_state == GRPC_CHTTP2_KEEPALIVE_STATE_PINGING) { + if (error == GRPC_ERROR_NONE) { + if (GRPC_TRACE_FLAG_ENABLED(grpc_http_trace)) { + gpr_log(GPR_INFO, "%s: Finish keepalive ping", t->peer_string); } + t->keepalive_state = GRPC_CHTTP2_KEEPALIVE_STATE_WAITING; + grpc_timer_cancel(&t->keepalive_watchdog_timer); + GRPC_CHTTP2_REF_TRANSPORT(t, "init keepalive ping"); + grpc_timer_init(&t->keepalive_ping_timer, + grpc_core::ExecCtx::Get()->Now() + t->keepalive_time, + &t->init_keepalive_ping_locked); } } GRPC_CHTTP2_UNREF_TRANSPORT(t, "keepalive ping end"); } -static void keepalive_watchdog_fired(void* arg, grpc_error* error) { +static void keepalive_watchdog_fired_locked(void* arg, grpc_error* error) { grpc_chttp2_transport* t = static_cast(arg); - { - grpc_core::MutexLock lock(&t->mu); - if (t->keepalive_state == GRPC_CHTTP2_KEEPALIVE_STATE_PINGING) { - if (error == GRPC_ERROR_NONE) { - gpr_log(GPR_ERROR, "%s: Keepalive watchdog fired. Closing transport.", - t->peer_string); - t->keepalive_state = GRPC_CHTTP2_KEEPALIVE_STATE_DYING; - close_transport_locked( - t, grpc_error_set_int(GRPC_ERROR_CREATE_FROM_STATIC_STRING( - "keepalive watchdog timeout"), - GRPC_ERROR_INT_GRPC_STATUS, - GRPC_STATUS_UNAVAILABLE)); - } - } else { - /* The watchdog timer should have been cancelled by - * finish_keepalive_ping. */ - if (GPR_UNLIKELY(error != GRPC_ERROR_CANCELLED)) { - gpr_log(GPR_ERROR, "keepalive_ping_end state error: %d (expect: %d)", - t->keepalive_state, GRPC_CHTTP2_KEEPALIVE_STATE_PINGING); - } + if (t->keepalive_state == GRPC_CHTTP2_KEEPALIVE_STATE_PINGING) { + if (error == GRPC_ERROR_NONE) { + gpr_log(GPR_ERROR, "%s: Keepalive watchdog fired. Closing transport.", + t->peer_string); + t->keepalive_state = GRPC_CHTTP2_KEEPALIVE_STATE_DYING; + close_transport_locked( + t, grpc_error_set_int(GRPC_ERROR_CREATE_FROM_STATIC_STRING( + "keepalive watchdog timeout"), + GRPC_ERROR_INT_GRPC_STATUS, + GRPC_STATUS_UNAVAILABLE)); + } + } else { + /* The watchdog timer should have been cancelled by + * finish_keepalive_ping_locked. */ + if (GPR_UNLIKELY(error != GRPC_ERROR_CANCELLED)) { + gpr_log(GPR_ERROR, "keepalive_ping_end state error: %d (expect: %d)", + t->keepalive_state, GRPC_CHTTP2_KEEPALIVE_STATE_PINGING); } } GRPC_CHTTP2_UNREF_TRANSPORT(t, "keepalive watchdog"); @@ -2873,7 +2887,6 @@ static void set_pollset_set(grpc_transport* gt, grpc_stream* gs, static void reset_byte_stream(void* arg, grpc_error* error) { grpc_chttp2_stream* s = static_cast(arg); - grpc_core::MutexLock lock(&s->t->mu); s->pending_byte_stream = false; if (error == GRPC_ERROR_NONE) { grpc_chttp2_maybe_complete_recv_message(s->t, s); @@ -2903,23 +2916,30 @@ Chttp2IncomingByteStream::Chttp2IncomingByteStream( stream->byte_stream_error = GRPC_ERROR_NONE; } -void Chttp2IncomingByteStream::Orphan() { - GPR_TIMER_SCOPE("incoming_byte_stream_destroy", 0); - grpc_chttp2_stream* s = stream_; +void Chttp2IncomingByteStream::OrphanLocked(void* arg, + grpc_error* error_ignored) { + Chttp2IncomingByteStream* bs = static_cast(arg); + grpc_chttp2_stream* s = bs->stream_; grpc_chttp2_transport* t = s->t; - grpc_core::MutexLock lock(&t->mu); - Unref(); + bs->Unref(); s->pending_byte_stream = false; grpc_chttp2_maybe_complete_recv_message(t, s); grpc_chttp2_maybe_complete_recv_trailing_metadata(t, s); } -// TODO(yashykt) : Merge this with Next +void Chttp2IncomingByteStream::Orphan() { + GPR_TIMER_SCOPE("incoming_byte_stream_destroy", 0); + GRPC_CLOSURE_SCHED( + GRPC_CLOSURE_INIT(&destroy_action_, + &Chttp2IncomingByteStream::OrphanLocked, this, + grpc_combiner_scheduler(transport_->combiner)), + GRPC_ERROR_NONE); +} + void Chttp2IncomingByteStream::NextLocked(void* arg, grpc_error* error_ignored) { Chttp2IncomingByteStream* bs = static_cast(arg); grpc_chttp2_transport* t = bs->transport_; - grpc_core::MutexLock lock(&t->mu); grpc_chttp2_stream* s = bs->stream_; size_t cur_length = s->frame_storage.length; if (!s->read_closed) { @@ -2969,10 +2989,11 @@ bool Chttp2IncomingByteStream::Next(size_t max_size_hint, Ref(); next_action_.max_size_hint = max_size_hint; next_action_.on_complete = on_complete; - GRPC_CLOSURE_SCHED(GRPC_CLOSURE_INIT(&next_action_.closure, - &Chttp2IncomingByteStream::NextLocked, - this, grpc_schedule_on_exec_ctx), - GRPC_ERROR_NONE); + GRPC_CLOSURE_SCHED( + GRPC_CLOSURE_INIT(&next_action_.closure, + &Chttp2IncomingByteStream::NextLocked, this, + grpc_combiner_scheduler(transport_->combiner)), + GRPC_ERROR_NONE); return false; } } @@ -3085,7 +3106,7 @@ static void post_benign_reclaimer(grpc_chttp2_transport* t) { t->benign_reclaimer_registered = true; GRPC_CHTTP2_REF_TRANSPORT(t, "benign_reclaimer"); grpc_resource_user_post_reclaimer(grpc_endpoint_get_resource_user(t->ep), - false, &t->benign_reclaimer); + false, &t->benign_reclaimer_locked); } } @@ -3094,72 +3115,66 @@ static void post_destructive_reclaimer(grpc_chttp2_transport* t) { t->destructive_reclaimer_registered = true; GRPC_CHTTP2_REF_TRANSPORT(t, "destructive_reclaimer"); grpc_resource_user_post_reclaimer(grpc_endpoint_get_resource_user(t->ep), - true, &t->destructive_reclaimer); + true, &t->destructive_reclaimer_locked); } } -static void benign_reclaimer(void* arg, grpc_error* error) { +static void benign_reclaimer_locked(void* arg, grpc_error* error) { grpc_chttp2_transport* t = static_cast(arg); - { - grpc_core::MutexLock lock(&t->mu); - if (error == GRPC_ERROR_NONE && - grpc_chttp2_stream_map_size(&t->stream_map) == 0) { - /* Channel with no active streams: send a goaway to try and make it - * disconnect cleanly */ - if (GRPC_TRACE_FLAG_ENABLED(grpc_resource_quota_trace)) { - gpr_log(GPR_INFO, "HTTP2: %s - send goaway to free memory", - t->peer_string); - } - send_goaway( - t, grpc_error_set_int( - GRPC_ERROR_CREATE_FROM_STATIC_STRING("Buffers full"), - GRPC_ERROR_INT_HTTP2_ERROR, GRPC_HTTP2_ENHANCE_YOUR_CALM)); - } else if (error == GRPC_ERROR_NONE && - GRPC_TRACE_FLAG_ENABLED(grpc_resource_quota_trace)) { - gpr_log(GPR_INFO, - "HTTP2: %s - skip benign reclamation, there are still %" PRIdPTR - " streams", - t->peer_string, grpc_chttp2_stream_map_size(&t->stream_map)); - } - t->benign_reclaimer_registered = false; - if (error != GRPC_ERROR_CANCELLED) { - grpc_resource_user_finish_reclamation( - grpc_endpoint_get_resource_user(t->ep)); + if (error == GRPC_ERROR_NONE && + grpc_chttp2_stream_map_size(&t->stream_map) == 0) { + /* Channel with no active streams: send a goaway to try and make it + * disconnect cleanly */ + if (GRPC_TRACE_FLAG_ENABLED(grpc_resource_quota_trace)) { + gpr_log(GPR_INFO, "HTTP2: %s - send goaway to free memory", + t->peer_string); } + send_goaway(t, + grpc_error_set_int( + GRPC_ERROR_CREATE_FROM_STATIC_STRING("Buffers full"), + GRPC_ERROR_INT_HTTP2_ERROR, GRPC_HTTP2_ENHANCE_YOUR_CALM)); + } else if (error == GRPC_ERROR_NONE && + GRPC_TRACE_FLAG_ENABLED(grpc_resource_quota_trace)) { + gpr_log(GPR_INFO, + "HTTP2: %s - skip benign reclamation, there are still %" PRIdPTR + " streams", + t->peer_string, grpc_chttp2_stream_map_size(&t->stream_map)); + } + t->benign_reclaimer_registered = false; + if (error != GRPC_ERROR_CANCELLED) { + grpc_resource_user_finish_reclamation( + grpc_endpoint_get_resource_user(t->ep)); } GRPC_CHTTP2_UNREF_TRANSPORT(t, "benign_reclaimer"); } -static void destructive_reclaimer(void* arg, grpc_error* error) { +static void destructive_reclaimer_locked(void* arg, grpc_error* error) { grpc_chttp2_transport* t = static_cast(arg); - { - grpc_core::MutexLock lock(&t->mu); - size_t n = grpc_chttp2_stream_map_size(&t->stream_map); - t->destructive_reclaimer_registered = false; - if (error == GRPC_ERROR_NONE && n > 0) { - grpc_chttp2_stream* s = static_cast( - grpc_chttp2_stream_map_rand(&t->stream_map)); - if (GRPC_TRACE_FLAG_ENABLED(grpc_resource_quota_trace)) { - gpr_log(GPR_INFO, "HTTP2: %s - abandon stream id %d", t->peer_string, - s->id); - } - grpc_chttp2_cancel_stream( - t, s, - grpc_error_set_int( - GRPC_ERROR_CREATE_FROM_STATIC_STRING("Buffers full"), - GRPC_ERROR_INT_HTTP2_ERROR, GRPC_HTTP2_ENHANCE_YOUR_CALM)); - if (n > 1) { - /* Since we cancel one stream per destructive reclamation, if - there are more streams left, we can immediately post a new - reclaimer in case the resource quota needs to free more - memory */ - post_destructive_reclaimer(t); - } - } - if (error != GRPC_ERROR_CANCELLED) { - grpc_resource_user_finish_reclamation( - grpc_endpoint_get_resource_user(t->ep)); - } + size_t n = grpc_chttp2_stream_map_size(&t->stream_map); + t->destructive_reclaimer_registered = false; + if (error == GRPC_ERROR_NONE && n > 0) { + grpc_chttp2_stream* s = static_cast( + grpc_chttp2_stream_map_rand(&t->stream_map)); + if (GRPC_TRACE_FLAG_ENABLED(grpc_resource_quota_trace)) { + gpr_log(GPR_INFO, "HTTP2: %s - abandon stream id %d", t->peer_string, + s->id); + } + grpc_chttp2_cancel_stream( + t, s, + grpc_error_set_int(GRPC_ERROR_CREATE_FROM_STATIC_STRING("Buffers full"), + GRPC_ERROR_INT_HTTP2_ERROR, + GRPC_HTTP2_ENHANCE_YOUR_CALM)); + if (n > 1) { + /* Since we cancel one stream per destructive reclamation, if + there are more streams left, we can immediately post a new + reclaimer in case the resource quota needs to free more + memory */ + post_destructive_reclaimer(t); + } + } + if (error != GRPC_ERROR_CANCELLED) { + grpc_resource_user_finish_reclamation( + grpc_endpoint_get_resource_user(t->ep)); } GRPC_CHTTP2_UNREF_TRANSPORT(t, "destructive_reclaimer"); } @@ -3259,5 +3274,5 @@ void grpc_chttp2_transport_start_reading( gpr_free(read_buffer); } t->notify_on_receive_settings = notify_on_receive_settings; - GRPC_CLOSURE_SCHED(&t->read_action, GRPC_ERROR_NONE); + GRPC_CLOSURE_SCHED(&t->read_action_locked, GRPC_ERROR_NONE); } diff --git a/src/core/ext/transport/chttp2/transport/hpack_parser.cc b/src/core/ext/transport/chttp2/transport/hpack_parser.cc index fb33c841428..a5142ffd96f 100644 --- a/src/core/ext/transport/chttp2/transport/hpack_parser.cc +++ b/src/core/ext/transport/chttp2/transport/hpack_parser.cc @@ -1669,15 +1669,11 @@ static const maybe_complete_func_type maybe_complete_funcs[] = { static void force_client_rst_stream(void* sp, grpc_error* error) { grpc_chttp2_stream* s = static_cast(sp); grpc_chttp2_transport* t = s->t; - { - grpc_core::MutexLock lock(&t->mu); - if (!s->write_closed) { - grpc_chttp2_add_rst_stream_to_next_write(t, s->id, GRPC_HTTP2_NO_ERROR, - &s->stats.outgoing); - grpc_chttp2_initiate_write(t, - GRPC_CHTTP2_INITIATE_WRITE_FORCE_RST_STREAM); - grpc_chttp2_mark_stream_closed(t, s, true, true, GRPC_ERROR_NONE); - } + if (!s->write_closed) { + grpc_chttp2_add_rst_stream_to_next_write(t, s->id, GRPC_HTTP2_NO_ERROR, + &s->stats.outgoing); + grpc_chttp2_initiate_write(t, GRPC_CHTTP2_INITIATE_WRITE_FORCE_RST_STREAM); + grpc_chttp2_mark_stream_closed(t, s, true, true, GRPC_ERROR_NONE); } GRPC_CHTTP2_STREAM_UNREF(s, "final_rst"); } @@ -1744,12 +1740,11 @@ grpc_error* grpc_chttp2_header_parser_parse(void* hpack_parser, the stream. Wait until the combiner lock is ready to be released however -- it might be that we receive a RST_STREAM following this and can avoid the extra write */ - // TODO(yashykt) : When we were using combiners, we were using the - // finally version. Maybe do something similar? GRPC_CHTTP2_STREAM_REF(s, "final_rst"); - GRPC_CLOSURE_SCHED(GRPC_CLOSURE_CREATE(force_client_rst_stream, s, - grpc_schedule_on_exec_ctx), - GRPC_ERROR_NONE); + GRPC_CLOSURE_SCHED( + GRPC_CLOSURE_CREATE(force_client_rst_stream, s, + grpc_combiner_finally_scheduler(t->combiner)), + GRPC_ERROR_NONE); } grpc_chttp2_mark_stream_closed(t, s, true, false, GRPC_ERROR_NONE); } diff --git a/src/core/ext/transport/chttp2/transport/internal.h b/src/core/ext/transport/chttp2/transport/internal.h index 6d13d368be7..8ef26cd7981 100644 --- a/src/core/ext/transport/chttp2/transport/internal.h +++ b/src/core/ext/transport/chttp2/transport/internal.h @@ -39,7 +39,6 @@ #include "src/core/lib/channel/channelz.h" #include "src/core/lib/compression/stream_compression.h" #include "src/core/lib/gprpp/manual_constructor.h" -#include "src/core/lib/gprpp/sync.h" #include "src/core/lib/iomgr/combiner.h" #include "src/core/lib/iomgr/endpoint.h" #include "src/core/lib/iomgr/timer.h" @@ -254,6 +253,7 @@ class Chttp2IncomingByteStream : public ByteStream { private: static void NextLocked(void* arg, grpc_error* error_ignored); + static void OrphanLocked(void* arg, grpc_error* error_ignored); void MaybeCreateStreamDecompressionCtx(); @@ -275,6 +275,7 @@ class Chttp2IncomingByteStream : public ByteStream { size_t max_size_hint; grpc_closure* on_complete; } next_action_; + grpc_closure destroy_action_; }; } // namespace grpc_core @@ -293,13 +294,14 @@ struct grpc_chttp2_transport { ~grpc_chttp2_transport(); grpc_transport base; /* must be first */ - grpc_core::Mutex mu; grpc_core::RefCount refs; grpc_endpoint* ep; char* peer_string; grpc_resource_user* resource_user; + grpc_combiner* combiner; + grpc_closure* notify_on_receive_settings = nullptr; /** write execution state of the transport */ @@ -325,11 +327,11 @@ struct grpc_chttp2_transport { /** maps stream id to grpc_chttp2_stream objects */ grpc_chttp2_stream_map stream_map; - grpc_closure write_action_begin; + grpc_closure write_action_begin_locked; grpc_closure write_action; - grpc_closure write_action_end; + grpc_closure write_action_end_locked; - grpc_closure read_action; + grpc_closure read_action_locked; /** incoming read bytes */ grpc_slice_buffer read_buffer; @@ -390,7 +392,7 @@ struct grpc_chttp2_transport { grpc_chttp2_repeated_ping_policy ping_policy; grpc_chttp2_repeated_ping_state ping_state; uint64_t ping_ctr = 0; /* unique id for pings */ - grpc_closure retry_initiate_ping; + grpc_closure retry_initiate_ping_locked; /** ping acks */ size_t ping_ack_count = 0; @@ -440,9 +442,9 @@ struct grpc_chttp2_transport { grpc_chttp2_write_cb* write_cb_pool = nullptr; /* bdp estimator */ - grpc_closure next_bdp_ping_timer_expired; + grpc_closure next_bdp_ping_timer_expired_locked; grpc_closure start_bdp_ping_locked; - grpc_closure finish_bdp_ping; + grpc_closure finish_bdp_ping_locked; /* if non-NULL, close the transport with this error when writes are finished */ @@ -457,9 +459,9 @@ struct grpc_chttp2_transport { /** have we scheduled a destructive cleanup? */ bool destructive_reclaimer_registered = false; /** benign cleanup closure */ - grpc_closure benign_reclaimer; + grpc_closure benign_reclaimer_locked; /** destructive cleanup closure */ - grpc_closure destructive_reclaimer; + grpc_closure destructive_reclaimer_locked; /* next bdp ping timer */ bool have_next_bdp_ping_timer = false; @@ -467,13 +469,13 @@ struct grpc_chttp2_transport { /* keep-alive ping support */ /** Closure to initialize a keepalive ping */ - grpc_closure init_keepalive_ping; + grpc_closure init_keepalive_ping_locked; /** Closure to run when the keepalive ping is sent */ grpc_closure start_keepalive_ping_locked; /** Cousure to run when the keepalive ping ack is received */ - grpc_closure finish_keepalive_ping; + grpc_closure finish_keepalive_ping_locked; /** Closrue to run when the keepalive ping timeouts */ - grpc_closure keepalive_watchdog_fired; + grpc_closure keepalive_watchdog_fired_locked; /** timer to initiate ping events */ grpc_timer keepalive_ping_timer; /** watchdog to kill the transport when waiting for the keepalive ping */ @@ -520,6 +522,7 @@ struct grpc_chttp2_stream { explicit Reffer(grpc_chttp2_stream* s); } reffer; + grpc_closure destroy_stream; grpc_closure* destroy_stream_arg; grpc_chttp2_stream_link links[STREAM_LIST_COUNT]; @@ -540,7 +543,7 @@ struct grpc_chttp2_stream { int64_t next_message_end_offset; int64_t flow_controlled_bytes_written = 0; int64_t flow_controlled_bytes_flowed = 0; - grpc_closure complete_fetch; + grpc_closure complete_fetch_locked; grpc_closure* fetching_send_message_finished = nullptr; grpc_metadata_batch* recv_initial_metadata; diff --git a/src/core/ext/transport/chttp2/transport/writing.cc b/src/core/ext/transport/chttp2/transport/writing.cc index 4796dee4cf6..d6d9e4521f6 100644 --- a/src/core/ext/transport/chttp2/transport/writing.cc +++ b/src/core/ext/transport/chttp2/transport/writing.cc @@ -97,14 +97,14 @@ static void maybe_initiate_ping(grpc_chttp2_transport* t) { t->ping_state.is_delayed_ping_timer_set = true; GRPC_CHTTP2_REF_TRANSPORT(t, "retry_initiate_ping_locked"); grpc_timer_init(&t->ping_state.delayed_ping_timer, next_allowed_ping, - &t->retry_initiate_ping); + &t->retry_initiate_ping_locked); } return; } pq->inflight_id = t->ping_ctr; t->ping_ctr++; - GRPC_CLOSURE_LIST_RUN(&pq->lists[GRPC_CHTTP2_PCL_INITIATE]); + GRPC_CLOSURE_LIST_SCHED(&pq->lists[GRPC_CHTTP2_PCL_INITIATE]); grpc_closure_list_move(&pq->lists[GRPC_CHTTP2_PCL_NEXT], &pq->lists[GRPC_CHTTP2_PCL_INFLIGHT]); grpc_slice_buffer_add(&t->outbuf, diff --git a/src/core/lib/iomgr/closure.h b/src/core/lib/iomgr/closure.h index 94667ae0a69..c7b2e8299b9 100644 --- a/src/core/lib/iomgr/closure.h +++ b/src/core/lib/iomgr/closure.h @@ -355,43 +355,4 @@ inline void grpc_closure_list_sched(grpc_closure_list* list) { grpc_closure_list_sched(closure_list) #endif -#ifndef NDEBUG -inline void grpc_closure_list_run(const char* file, int line, - grpc_closure_list* list) { -#else -inline void grpc_closure_list_run(grpc_closure_list* list) { -#endif - grpc_closure* c = list->head; - while (c != nullptr) { - grpc_closure* next = c->next_data.next; -#ifndef NDEBUG - if (c->scheduled) { - gpr_log(GPR_ERROR, - "Closure already scheduled. (closure: %p, created: [%s:%d], " - "previously scheduled at: [%s: %d] run?: %s", - c, c->file_created, c->line_created, c->file_initiated, - c->line_initiated, c->run ? "true" : "false"); - abort(); - } - c->scheduled = true; - c->file_initiated = file; - c->line_initiated = line; - c->run = false; - GPR_ASSERT(c->cb != nullptr); -#endif - c->scheduler->vtable->run(c, c->error_data.error); - c = next; - } - list->head = list->tail = nullptr; -} - -/** Schedule all closures in a list to be run. Does not need to be run from a - * safe point. */ -#ifndef NDEBUG -#define GRPC_CLOSURE_LIST_RUN(closure_list) \ - grpc_closure_list_run(__FILE__, __LINE__, closure_list) -#else -#define GRPC_CLOSURE_LIST_RUN(closure_list) grpc_closure_list_run(closure_list) -#endif - #endif /* GRPC_CORE_LIB_IOMGR_CLOSURE_H */ diff --git a/src/core/lib/iomgr/executor.cc b/src/core/lib/iomgr/executor.cc index c855d1535a9..721542544cd 100644 --- a/src/core/lib/iomgr/executor.cc +++ b/src/core/lib/iomgr/executor.cc @@ -465,10 +465,6 @@ void Executor::ShutdownAll() { bool Executor::IsThreaded(ExecutorType executor_type) { GPR_ASSERT(executor_type < ExecutorType::NUM_EXECUTORS); - Executor* executor = executors[static_cast(executor_type)]; - if (executor == nullptr) { - return false; - } return executors[static_cast(executor_type)]->IsThreaded(); } From 69a91b82e171beb8d1728dce053f3c91024c83d8 Mon Sep 17 00:00:00 2001 From: Esun Kim Date: Tue, 24 Sep 2019 14:48:12 -0700 Subject: [PATCH 52/60] Update C++ doc --- doc/core/moving-to-c++.md | 45 ++++++++++++++++----------------------- 1 file changed, 18 insertions(+), 27 deletions(-) diff --git a/doc/core/moving-to-c++.md b/doc/core/moving-to-c++.md index 717e2267b33..37251cd5ff6 100644 --- a/doc/core/moving-to-c++.md +++ b/doc/core/moving-to-c++.md @@ -1,8 +1,8 @@ # Moving gRPC core to C++ -October 2017 +Originally written by ctiller, markdroth, and vjpai in October 2017 -ctiller, markdroth, vjpai +Revised by veblush in October 2019 ## Background and Goal @@ -10,10 +10,14 @@ gRPC core was originally written in C89 for several reasons (possibility of kernel integration, ease of wrapping, compiler support, etc). Over time, this was changed to C99 as all relevant compilers in active use came to support C99 effectively. -[Now, gRPC core is C++](https://github.com/grpc/proposal/blob/master/L6-allow-c%2B%2B-in-grpc-core.md) -(although the code is still idiomatically C code) with C linkage for -public functions. Throughout all of these transitions, the public -header files are committed to remain in C89. + +gRPC started allowing to use C++ with a couple of exceptions not to +have C++ library linked such as `libstdc++.so`. +(For more detail, see the [proposal](https://github.com/grpc/proposal/blob/master/L6-core-allow-cpp.md)) + +Finally gRPC became ready to use full C++11 with the standard library by the [proposal](https://github.com[/grpc/proposal/blob/master/L59-core-allow-cppstdlib.md). + +Throughout all of these transitions, the public header files are committed to remain in C89. The goal now is to make the gRPC core implementation true idiomatic C++ compatible with @@ -21,24 +25,14 @@ C++ compatible with ## Constraints -- No use of standard library if it requires link-time dependency - - Standard library makes wrapping difficult/impossible and also reduces platform portability - - This takes precedence over using C++ style guide -- Limited use of standard library if it does not require link-time dependency - - We can use things from `std::` as long as they are header-only implementations. - - Since the standard library API does not specify whether any given part of the API is implemented header-only, the only way to know is to try using something and see if our tests fail. - - Since there is no guarantee that some header-only implementation in the standard library will remain header-only in the future, we should define our own API in lib/gprpp that is an alias for the thing we want to use in `std::` and use the gprpp API in core. That way, if we later need to stop using the thing from `std::`, we can replace the alias with our own implementation. -- But lambdas are ok -- As are third-party libraries that meet our build requirements (such as many parts of abseil) -- There will be some C++ features that don't work - - `new` and `delete` - - pure virtual functions are not allowed because the message that prints out "Pure Virtual Function called" is part of the standard library - - Make a `#define GRPC_ABSTRACT {GPR_ASSERT(false);}` instead of `= 0;` -- The sanity for making sure that we don't depend on libstdc++ is that at least some tests should explicitly not include it - - Most tests can migrate to use gtest - - There are tremendous # of code paths that can now be exposed to unit tests because of the use of gtest and C++ - - But at least some tests should not use gtest - +- Most of features available in C++11 are allowed to use but there are some exceptions + because gRPC should support old systems. + - Should be built with gcc 4.8, clang 3.3, and Visual C++ 2015. + - Should be run on Linux system with libstdc++ 6.0.9 to support + [manylinux1](https://www.python.org/dev/peps/pep-0513). +- This would limit us not to use modern C++11 standard library such as `filesystem`. + You can easily see whether PR is free from this issue by checking the result of + `Artifact Build Linux` test. ## Roadmap @@ -59,6 +53,3 @@ C++ compatible with ByteBuffer, ...) - The C++ API implementation might directly start using `grpc_transport_stream_op_batch` rather than the core surface `grpc_op`. -- Can we get wrapped languages to a point where we can statically link C++? This will take a year in probability but that would allow the use of `std::` - - Are there other environments that don't support std library, like maybe Android NDK? - - Probably, that might push things out to 18 months From 0ed1202f84d474f8dbb8685c7d60d3e259e2e6a8 Mon Sep 17 00:00:00 2001 From: "Mark D. Roth" Date: Wed, 2 Oct 2019 08:39:55 -0700 Subject: [PATCH 53/60] Use std::set<> where appropriate. --- .../ext/filters/client_channel/client_channel.cc | 13 +++++++------ src/core/ext/filters/client_channel/subchannel.h | 4 ++-- src/core/lib/transport/connectivity_state.h | 4 ++-- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/src/core/ext/filters/client_channel/client_channel.cc b/src/core/ext/filters/client_channel/client_channel.cc index 70746f4783f..29d093a0666 100644 --- a/src/core/ext/filters/client_channel/client_channel.cc +++ b/src/core/ext/filters/client_channel/client_channel.cc @@ -26,6 +26,9 @@ #include #include +#include +#include + #include #include #include @@ -286,9 +289,7 @@ class ChannelData { // The set of SubchannelWrappers that currently exist. // No need to hold a ref, since the map is updated in the control-plane // combiner when the SubchannelWrappers are created and destroyed. - // TODO(roth): We really want to use a set here, not a map. Since we don't - // currently have a set implementation, we use a map and ignore the value. - std::map subchannel_wrappers_; + std::set subchannel_wrappers_; // Pending ConnectedSubchannel updates for each SubchannelWrapper. // Updates are queued here in the control plane combiner and then applied // in the data plane mutex when the picker is updated. @@ -852,7 +853,7 @@ class ChannelData::SubchannelWrapper : public SubchannelInterface { } ++it->second; } - chand_->subchannel_wrappers_[this] = true; + chand_->subchannel_wrappers_.insert(this); } ~SubchannelWrapper() { @@ -1668,8 +1669,8 @@ bool ChannelData::ProcessResolverResultLocked( chand->health_check_service_name_.reset(); } // Update health check service name used by existing subchannel wrappers. - for (const auto& p : chand->subchannel_wrappers_) { - p.first->UpdateHealthCheckServiceName( + for (auto* subchannel_wrapper : chand->subchannel_wrappers_) { + subchannel_wrapper->UpdateHealthCheckServiceName( UniquePtr(gpr_strdup(chand->health_check_service_name_.get()))); } // Save service config. diff --git a/src/core/ext/filters/client_channel/subchannel.h b/src/core/ext/filters/client_channel/subchannel.h index d7912a00c77..f7387b26266 100644 --- a/src/core/ext/filters/client_channel/subchannel.h +++ b/src/core/ext/filters/client_channel/subchannel.h @@ -292,8 +292,8 @@ class Subchannel { bool empty() const { return watchers_.empty(); } private: - // TODO(roth): This could be a set instead of a map if we had a set - // implementation. + // TODO(roth): Once we can use C++-14 heterogenous lookups, this can + // be a set instead of a map. std::map> watchers_; diff --git a/src/core/lib/transport/connectivity_state.h b/src/core/lib/transport/connectivity_state.h index cefd1b88a02..a888e4a9b5b 100644 --- a/src/core/lib/transport/connectivity_state.h +++ b/src/core/lib/transport/connectivity_state.h @@ -108,8 +108,8 @@ class ConnectivityStateTracker { private: const char* name_; Atomic state_; - // TODO(roth): This could be a set instead of a map if we had a set - // implementation. + // TODO(roth): Once we can use C++-14 heterogenous lookups, this can + // be a set instead of a map. std::map> watchers_; From 019b82ca34cc625c5fdaf07cd616cee69be3cfa6 Mon Sep 17 00:00:00 2001 From: Esun Kim Date: Wed, 2 Oct 2019 08:46:30 -0700 Subject: [PATCH 54/60] Add note about thread_local --- doc/core/moving-to-c++.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/doc/core/moving-to-c++.md b/doc/core/moving-to-c++.md index 37251cd5ff6..40701f3fb57 100644 --- a/doc/core/moving-to-c++.md +++ b/doc/core/moving-to-c++.md @@ -33,6 +33,8 @@ C++ compatible with - This would limit us not to use modern C++11 standard library such as `filesystem`. You can easily see whether PR is free from this issue by checking the result of `Artifact Build Linux` test. +- `thread_local` is not allowed to use on Apple's products because their old OSes + (e.g. ios < 9.0) don't support `thread_local`. ## Roadmap From 2274ca22f4d3717fa716cce97865e166a5b18a1b Mon Sep 17 00:00:00 2001 From: Esun Kim Date: Wed, 2 Oct 2019 09:00:12 -0700 Subject: [PATCH 55/60] Use std::pair --- BUILD | 1 - BUILD.gn | 2 - build.yaml | 1 - gRPC-C++.podspec | 1 - gRPC-Core.podspec | 2 - grpc.gemspec | 1 - package.xml | 1 - .../client_channel/lb_policy/xds/xds.cc | 4 +- .../lb_policy/xds/xds_load_balancer_api.cc | 9 +++-- .../ext/filters/client_channel/subchannel.cc | 2 +- src/core/lib/channel/channelz.cc | 8 ++-- src/core/lib/gprpp/arena.cc | 6 +-- src/core/lib/gprpp/arena.h | 5 +-- src/core/lib/gprpp/map.h | 1 - src/core/lib/gprpp/pair.h | 38 ------------------- src/core/lib/transport/connectivity_state.cc | 2 +- tools/doxygen/Doxyfile.c++.internal | 1 - tools/doxygen/Doxyfile.core.internal | 1 - 18 files changed, 18 insertions(+), 68 deletions(-) delete mode 100644 src/core/lib/gprpp/pair.h diff --git a/BUILD b/BUILD index 1128f715c79..46db2e490ac 100644 --- a/BUILD +++ b/BUILD @@ -521,7 +521,6 @@ grpc_cc_library( "src/core/lib/gprpp/map.h", "src/core/lib/gprpp/memory.h", "src/core/lib/gprpp/mpscq.h", - "src/core/lib/gprpp/pair.h", "src/core/lib/gprpp/string_view.h", "src/core/lib/gprpp/sync.h", "src/core/lib/gprpp/thd.h", diff --git a/BUILD.gn b/BUILD.gn index 0e3e5c51c7b..88bf0e632e2 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -149,7 +149,6 @@ config("grpc_config") { "src/core/lib/gprpp/memory.h", "src/core/lib/gprpp/mpscq.cc", "src/core/lib/gprpp/mpscq.h", - "src/core/lib/gprpp/pair.h", "src/core/lib/gprpp/sync.h", "src/core/lib/gprpp/thd.h", "src/core/lib/gprpp/thd_posix.cc", @@ -1252,7 +1251,6 @@ config("grpc_config") { "src/core/lib/gprpp/mpscq.h", "src/core/lib/gprpp/optional.h", "src/core/lib/gprpp/orphanable.h", - "src/core/lib/gprpp/pair.h", "src/core/lib/gprpp/ref_counted.h", "src/core/lib/gprpp/ref_counted_ptr.h", "src/core/lib/gprpp/string_view.h", diff --git a/build.yaml b/build.yaml index 285a33a0140..ed11a9ac3ec 100644 --- a/build.yaml +++ b/build.yaml @@ -291,7 +291,6 @@ filegroups: - src/core/lib/gprpp/map.h - src/core/lib/gprpp/memory.h - src/core/lib/gprpp/mpscq.h - - src/core/lib/gprpp/pair.h - src/core/lib/gprpp/sync.h - src/core/lib/gprpp/thd.h - src/core/lib/profiling/timers.h diff --git a/gRPC-C++.podspec b/gRPC-C++.podspec index bc844cd4517..9aa8d215cc0 100644 --- a/gRPC-C++.podspec +++ b/gRPC-C++.podspec @@ -311,7 +311,6 @@ Pod::Spec.new do |s| 'src/core/lib/gprpp/map.h', 'src/core/lib/gprpp/memory.h', 'src/core/lib/gprpp/mpscq.h', - 'src/core/lib/gprpp/pair.h', 'src/core/lib/gprpp/sync.h', 'src/core/lib/gprpp/thd.h', 'src/core/lib/profiling/timers.h', diff --git a/gRPC-Core.podspec b/gRPC-Core.podspec index 8be7a3d7e5d..e144acb6331 100644 --- a/gRPC-Core.podspec +++ b/gRPC-Core.podspec @@ -214,7 +214,6 @@ Pod::Spec.new do |s| 'src/core/lib/gprpp/map.h', 'src/core/lib/gprpp/memory.h', 'src/core/lib/gprpp/mpscq.h', - 'src/core/lib/gprpp/pair.h', 'src/core/lib/gprpp/sync.h', 'src/core/lib/gprpp/thd.h', 'src/core/lib/profiling/timers.h', @@ -989,7 +988,6 @@ Pod::Spec.new do |s| 'src/core/lib/gprpp/map.h', 'src/core/lib/gprpp/memory.h', 'src/core/lib/gprpp/mpscq.h', - 'src/core/lib/gprpp/pair.h', 'src/core/lib/gprpp/sync.h', 'src/core/lib/gprpp/thd.h', 'src/core/lib/profiling/timers.h', diff --git a/grpc.gemspec b/grpc.gemspec index 698d9f162b5..ef79e0cedea 100644 --- a/grpc.gemspec +++ b/grpc.gemspec @@ -108,7 +108,6 @@ Gem::Specification.new do |s| s.files += %w( src/core/lib/gprpp/map.h ) s.files += %w( src/core/lib/gprpp/memory.h ) s.files += %w( src/core/lib/gprpp/mpscq.h ) - s.files += %w( src/core/lib/gprpp/pair.h ) s.files += %w( src/core/lib/gprpp/sync.h ) s.files += %w( src/core/lib/gprpp/thd.h ) s.files += %w( src/core/lib/profiling/timers.h ) diff --git a/package.xml b/package.xml index 56807a958c7..b9ad2970e50 100644 --- a/package.xml +++ b/package.xml @@ -113,7 +113,6 @@ - diff --git a/src/core/ext/filters/client_channel/lb_policy/xds/xds.cc b/src/core/ext/filters/client_channel/lb_policy/xds/xds.cc index e0fa6c31dcd..2d5637e1229 100644 --- a/src/core/ext/filters/client_channel/lb_policy/xds/xds.cc +++ b/src/core/ext/filters/client_channel/lb_policy/xds/xds.cc @@ -407,7 +407,7 @@ class XdsLb : public LoadBalancingPolicy { // proportional to the locality's weight. The start of the range is the // previous value in the vector and is 0 for the first element. using PickerList = - InlinedVector>, 1>; + InlinedVector>, 1>; Picker(RefCountedPtr xds_policy, PickerList pickers) : xds_policy_(std::move(xds_policy)), pickers_(std::move(pickers)), @@ -2343,7 +2343,7 @@ void XdsLb::PriorityList::LocalityMap::UpdateXdsPickerLocked() { if (!locality_map_update()->Contains(locality_name)) continue; if (locality->connectivity_state() != GRPC_CHANNEL_READY) continue; end += locality->weight(); - picker_list.push_back(MakePair(end, locality->picker_wrapper())); + picker_list.push_back(std::make_pair(end, locality->picker_wrapper())); } xds_policy()->channel_control_helper()->UpdateState( GRPC_CHANNEL_READY, diff --git a/src/core/ext/filters/client_channel/lb_policy/xds/xds_load_balancer_api.cc b/src/core/ext/filters/client_channel/lb_policy/xds/xds_load_balancer_api.cc index 9c6e4c553c7..ec006b16bfd 100644 --- a/src/core/ext/filters/client_channel/lb_policy/xds/xds_load_balancer_api.cc +++ b/src/core/ext/filters/client_channel/lb_policy/xds/xds_load_balancer_api.cc @@ -345,10 +345,11 @@ grpc_slice XdsLrsRequestCreateAndEncode(const char* server_name) { namespace { -void LocalityStatsPopulate(envoy_api_v2_endpoint_UpstreamLocalityStats* output, - Pair, - XdsClientStats::LocalityStats::Snapshot>& input, - upb_arena* arena) { +void LocalityStatsPopulate( + envoy_api_v2_endpoint_UpstreamLocalityStats* output, + std::pair, + XdsClientStats::LocalityStats::Snapshot>& input, + upb_arena* arena) { // Set sub_zone. envoy_api_v2_core_Locality* locality = envoy_api_v2_endpoint_UpstreamLocalityStats_mutable_locality(output, diff --git a/src/core/ext/filters/client_channel/subchannel.cc b/src/core/ext/filters/client_channel/subchannel.cc index c1b33183d9f..be2d5558571 100644 --- a/src/core/ext/filters/client_channel/subchannel.cc +++ b/src/core/ext/filters/client_channel/subchannel.cc @@ -367,7 +367,7 @@ class Subchannel::ConnectedSubchannelStateWatcher void Subchannel::ConnectivityStateWatcherList::AddWatcherLocked( OrphanablePtr watcher) { - watchers_.insert(MakePair(watcher.get(), std::move(watcher))); + watchers_.insert(std::make_pair(watcher.get(), std::move(watcher))); } void Subchannel::ConnectivityStateWatcherList::RemoveWatcherLocked( diff --git a/src/core/lib/channel/channelz.cc b/src/core/lib/channel/channelz.cc index 24746e70d0b..d8a0aa4d068 100644 --- a/src/core/lib/channel/channelz.cc +++ b/src/core/lib/channel/channelz.cc @@ -293,7 +293,7 @@ void ChannelNode::SetConnectivityState(grpc_connectivity_state state) { void ChannelNode::AddChildChannel(intptr_t child_uuid) { MutexLock lock(&child_mu_); - child_channels_.insert(MakePair(child_uuid, true)); + child_channels_.insert(std::make_pair(child_uuid, true)); } void ChannelNode::RemoveChildChannel(intptr_t child_uuid) { @@ -303,7 +303,7 @@ void ChannelNode::RemoveChildChannel(intptr_t child_uuid) { void ChannelNode::AddChildSubchannel(intptr_t child_uuid) { MutexLock lock(&child_mu_); - child_subchannels_.insert(MakePair(child_uuid, true)); + child_subchannels_.insert(std::make_pair(child_uuid, true)); } void ChannelNode::RemoveChildSubchannel(intptr_t child_uuid) { @@ -323,7 +323,7 @@ ServerNode::~ServerNode() {} void ServerNode::AddChildSocket(RefCountedPtr node) { MutexLock lock(&child_mu_); - child_sockets_.insert(MakePair(node->uuid(), std::move(node))); + child_sockets_.insert(std::make_pair(node->uuid(), std::move(node))); } void ServerNode::RemoveChildSocket(intptr_t child_uuid) { @@ -333,7 +333,7 @@ void ServerNode::RemoveChildSocket(intptr_t child_uuid) { void ServerNode::AddChildListenSocket(RefCountedPtr node) { MutexLock lock(&child_mu_); - child_listen_sockets_.insert(MakePair(node->uuid(), std::move(node))); + child_listen_sockets_.insert(std::make_pair(node->uuid(), std::move(node))); } void ServerNode::RemoveChildListenSocket(intptr_t child_uuid) { diff --git a/src/core/lib/gprpp/arena.cc b/src/core/lib/gprpp/arena.cc index 5c344db4e35..61688258a1c 100644 --- a/src/core/lib/gprpp/arena.cc +++ b/src/core/lib/gprpp/arena.cc @@ -64,14 +64,14 @@ Arena* Arena::Create(size_t initial_size) { return new (ArenaStorage(initial_size)) Arena(initial_size); } -Pair Arena::CreateWithAlloc(size_t initial_size, - size_t alloc_size) { +std::pair Arena::CreateWithAlloc(size_t initial_size, + size_t alloc_size) { static constexpr size_t base_size = GPR_ROUND_UP_TO_ALIGNMENT_SIZE(sizeof(Arena)); auto* new_arena = new (ArenaStorage(initial_size)) Arena(initial_size, alloc_size); void* first_alloc = reinterpret_cast(new_arena) + base_size; - return MakePair(new_arena, first_alloc); + return std::make_pair(new_arena, first_alloc); } size_t Arena::Destroy() { diff --git a/src/core/lib/gprpp/arena.h b/src/core/lib/gprpp/arena.h index b1b0c4a85cb..67c91d9f490 100644 --- a/src/core/lib/gprpp/arena.h +++ b/src/core/lib/gprpp/arena.h @@ -36,7 +36,6 @@ #include "src/core/lib/gpr/alloc.h" #include "src/core/lib/gpr/spinlock.h" #include "src/core/lib/gprpp/atomic.h" -#include "src/core/lib/gprpp/pair.h" #include @@ -50,8 +49,8 @@ class Arena { // Create an arena, with \a initial_size bytes in the first allocated buffer, // and return both a void pointer to the returned arena and a void* with the // first allocation. - static Pair CreateWithAlloc(size_t initial_size, - size_t alloc_size); + static std::pair CreateWithAlloc(size_t initial_size, + size_t alloc_size); // Destroy an arena, returning the total number of bytes allocated. size_t Destroy(); diff --git a/src/core/lib/gprpp/map.h b/src/core/lib/gprpp/map.h index 0d61f902757..7e954cc2be8 100644 --- a/src/core/lib/gprpp/map.h +++ b/src/core/lib/gprpp/map.h @@ -30,7 +30,6 @@ #include "src/core/lib/gpr/useful.h" #include "src/core/lib/gprpp/memory.h" -#include "src/core/lib/gprpp/pair.h" #include "src/core/lib/gprpp/ref_counted_ptr.h" #include "src/core/lib/gprpp/string_view.h" diff --git a/src/core/lib/gprpp/pair.h b/src/core/lib/gprpp/pair.h deleted file mode 100644 index ca8294cc7bb..00000000000 --- a/src/core/lib/gprpp/pair.h +++ /dev/null @@ -1,38 +0,0 @@ -/* - * - * Copyright 2017 gRPC authors. - * - * 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. - * - */ - -#ifndef GRPC_CORE_LIB_GPRPP_PAIR_H -#define GRPC_CORE_LIB_GPRPP_PAIR_H - -#include - -#include - -namespace grpc_core { -template -using Pair = std::pair; - -template -inline Pair::type, typename std::decay::type> -MakePair(T1&& u, T2&& v) { - typedef typename std::decay::type V1; - typedef typename std::decay::type V2; - return Pair(std::forward(u), std::forward(v)); -} -} // namespace grpc_core -#endif /* GRPC_CORE_LIB_GPRPP_PAIR_H */ diff --git a/src/core/lib/transport/connectivity_state.cc b/src/core/lib/transport/connectivity_state.cc index 32aa99306be..3edb5148d1d 100644 --- a/src/core/lib/transport/connectivity_state.cc +++ b/src/core/lib/transport/connectivity_state.cc @@ -123,7 +123,7 @@ void ConnectivityStateTracker::AddWatcher( // If we're in state SHUTDOWN, don't add the watcher, so that it will // be orphaned immediately. if (current_state != GRPC_CHANNEL_SHUTDOWN) { - watchers_.insert(MakePair(watcher.get(), std::move(watcher))); + watchers_.insert(std::make_pair(watcher.get(), std::move(watcher))); } } diff --git a/tools/doxygen/Doxyfile.c++.internal b/tools/doxygen/Doxyfile.c++.internal index fd709c70e84..ada328dd92f 100644 --- a/tools/doxygen/Doxyfile.c++.internal +++ b/tools/doxygen/Doxyfile.c++.internal @@ -1117,7 +1117,6 @@ src/core/lib/gprpp/memory.h \ src/core/lib/gprpp/mpscq.h \ src/core/lib/gprpp/optional.h \ src/core/lib/gprpp/orphanable.h \ -src/core/lib/gprpp/pair.h \ src/core/lib/gprpp/ref_counted.h \ src/core/lib/gprpp/ref_counted_ptr.h \ src/core/lib/gprpp/string_view.h \ diff --git a/tools/doxygen/Doxyfile.core.internal b/tools/doxygen/Doxyfile.core.internal index eba49015f19..bc199120f00 100644 --- a/tools/doxygen/Doxyfile.core.internal +++ b/tools/doxygen/Doxyfile.core.internal @@ -1253,7 +1253,6 @@ src/core/lib/gprpp/mpscq.cc \ src/core/lib/gprpp/mpscq.h \ src/core/lib/gprpp/optional.h \ src/core/lib/gprpp/orphanable.h \ -src/core/lib/gprpp/pair.h \ src/core/lib/gprpp/ref_counted.h \ src/core/lib/gprpp/ref_counted_ptr.h \ src/core/lib/gprpp/string_view.h \ From 206c11f017d3443798fac08140b14eda55b12584 Mon Sep 17 00:00:00 2001 From: "Mark D. Roth" Date: Wed, 2 Oct 2019 09:24:05 -0700 Subject: [PATCH 56/60] Use std::function<> for recv_trailing_metadata callback in LB policy API. --- .../filters/client_channel/client_channel.cc | 15 ++++------ .../ext/filters/client_channel/lb_policy.h | 22 +++++--------- .../client_channel/lb_policy/xds/xds.cc | 30 +++++++------------ test/core/util/test_lb_policies.cc | 19 ++++++------ 4 files changed, 33 insertions(+), 53 deletions(-) diff --git a/src/core/ext/filters/client_channel/client_channel.cc b/src/core/ext/filters/client_channel/client_channel.cc index 70746f4783f..d049f4dd8a5 100644 --- a/src/core/ext/filters/client_channel/client_channel.cc +++ b/src/core/ext/filters/client_channel/client_channel.cc @@ -753,11 +753,9 @@ class CallData { LbCallState lb_call_state_; const LoadBalancingPolicy::BackendMetricData* backend_metric_data_ = nullptr; RefCountedPtr connected_subchannel_; - void (*lb_recv_trailing_metadata_ready_)( - void* user_data, grpc_error* error, - LoadBalancingPolicy::MetadataInterface* recv_trailing_metadata, - LoadBalancingPolicy::CallState* call_state) = nullptr; - void* lb_recv_trailing_metadata_ready_user_data_ = nullptr; + std::function + lb_recv_trailing_metadata_ready_; grpc_closure pick_closure_; // For intercepting recv_trailing_metadata_ready for the LB policy. @@ -2176,9 +2174,8 @@ void CallData::RecvTrailingMetadataReadyForLoadBalancingPolicy( CallData* calld = static_cast(arg); // Invoke callback to LB policy. Metadata trailing_metadata(calld, calld->recv_trailing_metadata_); - calld->lb_recv_trailing_metadata_ready_( - calld->lb_recv_trailing_metadata_ready_user_data_, error, - &trailing_metadata, &calld->lb_call_state_); + calld->lb_recv_trailing_metadata_ready_(error, &trailing_metadata, + &calld->lb_call_state_); // Chain to original callback. GRPC_CLOSURE_RUN(calld->original_recv_trailing_metadata_ready_, GRPC_ERROR_REF(error)); @@ -3877,8 +3874,6 @@ bool CallData::PickSubchannelLocked(grpc_call_element* elem, GPR_ASSERT(connected_subchannel_ != nullptr); } lb_recv_trailing_metadata_ready_ = result.recv_trailing_metadata_ready; - lb_recv_trailing_metadata_ready_user_data_ = - result.recv_trailing_metadata_ready_user_data; *error = result.error; return true; } diff --git a/src/core/ext/filters/client_channel/lb_policy.h b/src/core/ext/filters/client_channel/lb_policy.h index 20957c3daaf..dc4bf51cfce 100644 --- a/src/core/ext/filters/client_channel/lb_policy.h +++ b/src/core/ext/filters/client_channel/lb_policy.h @@ -189,20 +189,14 @@ class LoadBalancingPolicy : public InternallyRefCounted { /// Used only if type is PICK_COMPLETE. /// Callback set by LB policy to be notified of trailing metadata. - /// The user_data argument will be set to the - /// recv_trailing_metadata_ready_user_data field. - /// recv_trailing_metadata will be set to the metadata, which may be - /// modified by the callback. The callback does not take ownership, - /// however, so any data that needs to be used after returning must - /// be copied. - /// call_state can be used to obtain backend metric data. - // TODO(roth): Replace grpc_error with something better before we allow - // people outside of gRPC team to use this API. - void (*recv_trailing_metadata_ready)( - void* user_data, grpc_error* error, - MetadataInterface* recv_trailing_metadata, - CallState* call_state) = nullptr; - void* recv_trailing_metadata_ready_user_data = nullptr; + /// If set by LB policy, the client channel will invoke the callback + /// when trailing metadata is returned. + /// The metadata may be modified by the callback. However, the callback + /// does not take ownership, so any data that needs to be used after + /// returning must be copied. + /// The call state can be used to obtain backend metric data. + std::function + recv_trailing_metadata_ready; }; /// A subchannel picker is the object used to pick the subchannel to diff --git a/src/core/ext/filters/client_channel/lb_policy/xds/xds.cc b/src/core/ext/filters/client_channel/lb_policy/xds/xds.cc index e0fa6c31dcd..7474530daaa 100644 --- a/src/core/ext/filters/client_channel/lb_policy/xds/xds.cc +++ b/src/core/ext/filters/client_channel/lb_policy/xds/xds.cc @@ -389,11 +389,6 @@ class XdsLb : public LoadBalancingPolicy { PickResult Pick(PickArgs args); private: - static void RecordCallCompletion( - void* arg, grpc_error* error, - LoadBalancingPolicy::MetadataInterface* recv_trailing_metadata, - LoadBalancingPolicy::CallState* call_state); - UniquePtr picker_; RefCountedPtr locality_stats_; }; @@ -728,25 +723,20 @@ LoadBalancingPolicy::PickResult XdsLb::PickerWrapper::Pick( // Record a call started. locality_stats_->AddCallStarted(); // Intercept the recv_trailing_metadata op to record call completion. - result.recv_trailing_metadata_ready = RecordCallCompletion; - result.recv_trailing_metadata_ready_user_data = + XdsClientStats::LocalityStats* locality_stats = locality_stats_->Ref(DEBUG_LOCATION, "LocalityStats+call").release(); + result.recv_trailing_metadata_ready = + // Note: This callback does not run in either the control plane + // combiner or in the data plane mutex. + [locality_stats](grpc_error* error, MetadataInterface* metadata, + CallState* call_state) { + const bool call_failed = error != GRPC_ERROR_NONE; + locality_stats->AddCallFinished(call_failed); + locality_stats->Unref(DEBUG_LOCATION, "LocalityStats+call"); + }; return result; } -// Note that the following callback does not run in either the control plane -// combiner or the data plane combiner. -void XdsLb::PickerWrapper::RecordCallCompletion( - void* arg, grpc_error* error, - LoadBalancingPolicy::MetadataInterface* recv_trailing_metadata, - LoadBalancingPolicy::CallState* call_state) { - XdsClientStats::LocalityStats* locality_stats = - static_cast(arg); - const bool call_failed = error != GRPC_ERROR_NONE; - locality_stats->AddCallFinished(call_failed); - locality_stats->Unref(DEBUG_LOCATION, "LocalityStats+call"); -} - // // XdsLb::Picker // diff --git a/test/core/util/test_lb_policies.cc b/test/core/util/test_lb_policies.cc index 8330c47ac46..c4aab3fc3ac 100644 --- a/test/core/util/test_lb_policies.cc +++ b/test/core/util/test_lb_policies.cc @@ -177,22 +177,23 @@ class InterceptRecvTrailingMetadataLoadBalancingPolicy InterceptRecvTrailingMetadataCallback cb, void* user_data) : cb_(cb), user_data_(user_data) { - result->recv_trailing_metadata_ready = &RecordRecvTrailingMetadata; - result->recv_trailing_metadata_ready_user_data = this; + result->recv_trailing_metadata_ready = [this](grpc_error* error, + MetadataInterface* metadata, + CallState* call_state) { + RecordRecvTrailingMetadata(error, metadata, call_state); + }; } private: - static void RecordRecvTrailingMetadata( - void* arg, grpc_error* error, MetadataInterface* recv_trailing_metadata, - CallState* call_state) { - TrailingMetadataHandler* self = - static_cast(arg); + void RecordRecvTrailingMetadata(grpc_error* error, + MetadataInterface* recv_trailing_metadata, + CallState* call_state) { GPR_ASSERT(recv_trailing_metadata != nullptr); gpr_log(GPR_INFO, "trailing metadata:"); InterceptRecvTrailingMetadataLoadBalancingPolicy::LogMetadata( recv_trailing_metadata); - self->cb_(self->user_data_, call_state->GetBackendMetricData()); - self->~TrailingMetadataHandler(); + cb_(user_data_, call_state->GetBackendMetricData()); + this->~TrailingMetadataHandler(); } InterceptRecvTrailingMetadataCallback cb_; From e12ff9cd58f1f6cfdb51d538be43b4378e48b159 Mon Sep 17 00:00:00 2001 From: Esun Kim Date: Wed, 2 Oct 2019 09:48:53 -0700 Subject: [PATCH 57/60] Remove third_party/libcxx[abi] --- .gitmodules | 8 ---- Makefile | 46 +--------------------- build.yaml | 31 --------------- grpc.gyp | 26 ------------ third_party/libcxx | 1 - third_party/libcxxabi | 1 - tools/run_tests/run_performance_tests.py | 8 +--- tools/run_tests/sanity/check_submodules.sh | 2 - 8 files changed, 2 insertions(+), 121 deletions(-) delete mode 160000 third_party/libcxx delete mode 160000 third_party/libcxxabi diff --git a/.gitmodules b/.gitmodules index 2b085e15059..e40c3362830 100644 --- a/.gitmodules +++ b/.gitmodules @@ -34,14 +34,6 @@ [submodule "third_party/abseil-cpp"] path = third_party/abseil-cpp url = https://github.com/abseil/abseil-cpp -[submodule "third_party/libcxxabi"] - path = third_party/libcxxabi - url = https://github.com/llvm-mirror/libcxxabi.git - branch = release_60 -[submodule "third_party/libcxx"] - path = third_party/libcxx - url = https://github.com/llvm-mirror/libcxx.git - branch = release_60 [submodule "third_party/envoy-api"] path = third_party/envoy-api url = https://github.com/envoyproxy/data-plane-api.git diff --git a/Makefile b/Makefile index 9358cc3205d..fb283e0c902 100644 --- a/Makefile +++ b/Makefile @@ -1416,7 +1416,7 @@ plugins: $(PROTOC_PLUGINS) privatelibs: privatelibs_c privatelibs_cxx -privatelibs_c: $(LIBDIR)/$(CONFIG)/libalts_test_util.a $(LIBDIR)/$(CONFIG)/libcxxabi.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libreconnect_server.a $(LIBDIR)/$(CONFIG)/libtest_tcp_server.a $(LIBDIR)/$(CONFIG)/libz.a $(LIBDIR)/$(CONFIG)/libares.a $(LIBDIR)/$(CONFIG)/libbad_ssl_test_server.a $(LIBDIR)/$(CONFIG)/libend2end_tests.a $(LIBDIR)/$(CONFIG)/libend2end_nosec_tests.a +privatelibs_c: $(LIBDIR)/$(CONFIG)/libalts_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util_unsecure.a $(LIBDIR)/$(CONFIG)/libreconnect_server.a $(LIBDIR)/$(CONFIG)/libtest_tcp_server.a $(LIBDIR)/$(CONFIG)/libz.a $(LIBDIR)/$(CONFIG)/libares.a $(LIBDIR)/$(CONFIG)/libbad_ssl_test_server.a $(LIBDIR)/$(CONFIG)/libend2end_tests.a $(LIBDIR)/$(CONFIG)/libend2end_nosec_tests.a pc_c: $(LIBDIR)/$(CONFIG)/pkgconfig/grpc.pc $(LIBDIR)/$(CONFIG)/pkgconfig/gpr.pc pc_c_unsecure: $(LIBDIR)/$(CONFIG)/pkgconfig/grpc_unsecure.pc $(LIBDIR)/$(CONFIG)/pkgconfig/gpr.pc @@ -3395,50 +3395,6 @@ endif endif -LIBCXXABI_SRC = \ - third_party/libcxxabi/src/abort_message.cpp \ - third_party/libcxxabi/src/cxa_aux_runtime.cpp \ - third_party/libcxxabi/src/cxa_default_handlers.cpp \ - third_party/libcxxabi/src/cxa_demangle.cpp \ - third_party/libcxxabi/src/cxa_exception_storage.cpp \ - third_party/libcxxabi/src/cxa_guard.cpp \ - third_party/libcxxabi/src/cxa_handlers.cpp \ - third_party/libcxxabi/src/cxa_noexception.cpp \ - third_party/libcxxabi/src/cxa_thread_atexit.cpp \ - third_party/libcxxabi/src/cxa_unexpected.cpp \ - third_party/libcxxabi/src/cxa_vector.cpp \ - third_party/libcxxabi/src/cxa_virtual.cpp \ - third_party/libcxxabi/src/fallback_malloc.cpp \ - third_party/libcxxabi/src/private_typeinfo.cpp \ - third_party/libcxxabi/src/stdlib_exception.cpp \ - third_party/libcxxabi/src/stdlib_new_delete.cpp \ - third_party/libcxxabi/src/stdlib_stdexcept.cpp \ - third_party/libcxxabi/src/stdlib_typeinfo.cpp \ - -PUBLIC_HEADERS_C += \ - -LIBCXXABI_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(LIBCXXABI_SRC)))) - -$(LIBCXXABI_OBJS): CPPFLAGS += -D_LIBCPP_DISABLE_EXTERN_TEMPLATE -D_LIBCXXABI_BUILDING_LIBRARY -D_LIBCXXABI_NO_EXCEPTIONS -Ithird_party/libcxxabi/include -nostdinc++ -Ithird_party/libcxx/include $(W_NO_UNUSED_BUT_SET_VARIABLE) $(W_NO_MAYBE_UNINITIALIZED) -fvisibility=hidden -$(LIBCXXABI_OBJS): CXXFLAGS += $(W_NO_CXX14_COMPAT) - -$(LIBDIR)/$(CONFIG)/libcxxabi.a: $(ZLIB_DEP) $(CARES_DEP) $(ADDRESS_SORTING_DEP) $(LIBCXXABI_OBJS) - $(E) "[AR] Creating $@" - $(Q) mkdir -p `dirname $@` - $(Q) rm -f $(LIBDIR)/$(CONFIG)/libcxxabi.a - $(Q) $(AR) $(AROPTS) $(LIBDIR)/$(CONFIG)/libcxxabi.a $(LIBCXXABI_OBJS) -ifeq ($(SYSTEM),Darwin) - $(Q) ranlib -no_warning_for_no_symbols $(LIBDIR)/$(CONFIG)/libcxxabi.a -endif - - - - -ifneq ($(NO_DEPS),true) --include $(LIBCXXABI_OBJS:.o=.dep) -endif - - LIBGPR_SRC = \ src/core/lib/gpr/alloc.cc \ src/core/lib/gpr/atm.cc \ diff --git a/build.yaml b/build.yaml index 285a33a0140..0b512e5e2d9 100644 --- a/build.yaml +++ b/build.yaml @@ -1626,32 +1626,6 @@ libs: deps: - grpc secure: true -- name: cxxabi - build: private - language: c - src: - - third_party/libcxxabi/src/abort_message.cpp - - third_party/libcxxabi/src/cxa_aux_runtime.cpp - - third_party/libcxxabi/src/cxa_default_handlers.cpp - - third_party/libcxxabi/src/cxa_demangle.cpp - - third_party/libcxxabi/src/cxa_exception_storage.cpp - - third_party/libcxxabi/src/cxa_guard.cpp - - third_party/libcxxabi/src/cxa_handlers.cpp - - third_party/libcxxabi/src/cxa_noexception.cpp - - third_party/libcxxabi/src/cxa_thread_atexit.cpp - - third_party/libcxxabi/src/cxa_unexpected.cpp - - third_party/libcxxabi/src/cxa_vector.cpp - - third_party/libcxxabi/src/cxa_virtual.cpp - - third_party/libcxxabi/src/fallback_malloc.cpp - - third_party/libcxxabi/src/private_typeinfo.cpp - - third_party/libcxxabi/src/stdlib_exception.cpp - - third_party/libcxxabi/src/stdlib_new_delete.cpp - - third_party/libcxxabi/src/stdlib_stdexcept.cpp - - third_party/libcxxabi/src/stdlib_typeinfo.cpp - build_system: - - Makefile - defaults: cxxabi - secure: false - name: gpr build: all language: c @@ -6192,11 +6166,6 @@ defaults: CPPFLAGS: -Ithird_party/boringssl/include -fvisibility=hidden -DOPENSSL_NO_ASM -D_GNU_SOURCE -DWIN32_LEAN_AND_MEAN -D_HAS_EXCEPTIONS=0 -DNOMINMAX CXXFLAGS: -fno-rtti -fno-exceptions - cxxabi: - CPPFLAGS: -D_LIBCPP_DISABLE_EXTERN_TEMPLATE -D_LIBCXXABI_BUILDING_LIBRARY -D_LIBCXXABI_NO_EXCEPTIONS - -Ithird_party/libcxxabi/include -nostdinc++ -Ithird_party/libcxx/include $(W_NO_UNUSED_BUT_SET_VARIABLE) - $(W_NO_MAYBE_UNINITIALIZED) -fvisibility=hidden - CXXFLAGS: $(W_NO_CXX14_COMPAT) global: CFLAGS: -g COREFLAGS: -fno-rtti -fno-exceptions diff --git a/grpc.gyp b/grpc.gyp index 4d08d766bc8..73967f47532 100644 --- a/grpc.gyp +++ b/grpc.gyp @@ -172,32 +172,6 @@ 'test/core/tsi/alts/handshaker/alts_handshaker_service_api_test_lib.cc', ], }, - { - 'target_name': 'cxxabi', - 'type': 'static_library', - 'dependencies': [ - ], - 'sources': [ - 'third_party/libcxxabi/src/abort_message.cpp', - 'third_party/libcxxabi/src/cxa_aux_runtime.cpp', - 'third_party/libcxxabi/src/cxa_default_handlers.cpp', - 'third_party/libcxxabi/src/cxa_demangle.cpp', - 'third_party/libcxxabi/src/cxa_exception_storage.cpp', - 'third_party/libcxxabi/src/cxa_guard.cpp', - 'third_party/libcxxabi/src/cxa_handlers.cpp', - 'third_party/libcxxabi/src/cxa_noexception.cpp', - 'third_party/libcxxabi/src/cxa_thread_atexit.cpp', - 'third_party/libcxxabi/src/cxa_unexpected.cpp', - 'third_party/libcxxabi/src/cxa_vector.cpp', - 'third_party/libcxxabi/src/cxa_virtual.cpp', - 'third_party/libcxxabi/src/fallback_malloc.cpp', - 'third_party/libcxxabi/src/private_typeinfo.cpp', - 'third_party/libcxxabi/src/stdlib_exception.cpp', - 'third_party/libcxxabi/src/stdlib_new_delete.cpp', - 'third_party/libcxxabi/src/stdlib_stdexcept.cpp', - 'third_party/libcxxabi/src/stdlib_typeinfo.cpp', - ], - }, { 'target_name': 'gpr', 'type': 'static_library', diff --git a/third_party/libcxx b/third_party/libcxx deleted file mode 160000 index 6599cac0965..00000000000 --- a/third_party/libcxx +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 6599cac0965be8e5a835ab7a5684bbef033d5ad0 diff --git a/third_party/libcxxabi b/third_party/libcxxabi deleted file mode 160000 index 9245d481eb3..00000000000 --- a/third_party/libcxxabi +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 9245d481eb3e890f708ff2d7dadf2a10c04748ba diff --git a/tools/run_tests/run_performance_tests.py b/tools/run_tests/run_performance_tests.py index 68e470e06c3..491efcbfd14 100755 --- a/tools/run_tests/run_performance_tests.py +++ b/tools/run_tests/run_performance_tests.py @@ -193,13 +193,7 @@ def create_netperf_jobspec(server_host='localhost', def archive_repo(languages): """Archives local version of repo including submodules.""" - # Directory contains symlinks that can't be correctly untarred on Windows - # so we just skip them as a workaround. - # See https://github.com/grpc/grpc/issues/16334 - bad_symlinks_dir = '../grpc/third_party/libcxx/test/std/experimental/filesystem/Inputs/static_test_env' - cmdline = [ - 'tar', '--exclude', bad_symlinks_dir, '-cf', '../grpc.tar', '../grpc/' - ] + cmdline = ['tar', '-cf', '../grpc.tar', '../grpc/'] if 'java' in languages: cmdline.append('../grpc-java') if 'go' in languages: diff --git a/tools/run_tests/sanity/check_submodules.sh b/tools/run_tests/sanity/check_submodules.sh index e49ddc8950e..7994b20ea14 100755 --- a/tools/run_tests/sanity/check_submodules.sh +++ b/tools/run_tests/sanity/check_submodules.sh @@ -36,8 +36,6 @@ cat << EOF | awk '{ print $1 }' | sort > "$want_submodules" 28f50e0fed19872e0fd50dd23ce2ee8cd759338e third_party/gflags (v2.2.0-5-g30dbc81) 80ed4d0bbf65d57cc267dfc63bd2584557f11f9b third_party/googleapis (common-protos-1_3_1-915-g80ed4d0bb) c9ccac7cb7345901884aabf5d1a786cfa6e2f397 third_party/googletest (6e2f397) - 6599cac0965be8e5a835ab7a5684bbef033d5ad0 third_party/libcxx (heads/release_60) - 9245d481eb3e890f708ff2d7dadf2a10c04748ba third_party/libcxxabi (heads/release_60) 09745575a923640154bcf307fba8aedff47f240a third_party/protobuf (v3.7.0-rc.2-247-g09745575) e143189bf6f37b3957fb31743df6a1bcf4a8c685 third_party/protoc-gen-validate (v0.0.10) 94324803a497c8f76dbc78df393ef629d3a9f3c3 third_party/udpa (heads/master) From 490be929b34e7ddfa419e010ada0bab70c329837 Mon Sep 17 00:00:00 2001 From: "Mark D. Roth" Date: Wed, 2 Oct 2019 10:56:23 -0700 Subject: [PATCH 58/60] Use more normal API for client channel connectivity watches from internal code --- .../filters/client_channel/client_channel.cc | 100 ++++++++++++++++++ .../filters/client_channel/client_channel.h | 30 ++++-- .../client_channel/lb_policy/xds/xds.cc | 94 ++++++++-------- src/core/lib/transport/connectivity_state.cc | 7 +- src/core/lib/transport/connectivity_state.h | 8 ++ 5 files changed, 177 insertions(+), 62 deletions(-) diff --git a/src/core/ext/filters/client_channel/client_channel.cc b/src/core/ext/filters/client_channel/client_channel.cc index 70746f4783f..923410846ed 100644 --- a/src/core/ext/filters/client_channel/client_channel.cc +++ b/src/core/ext/filters/client_channel/client_channel.cc @@ -179,9 +179,17 @@ class ChannelData { return static_cast(external_watchers_.size()); } + void AddConnectivityWatcher( + grpc_connectivity_state initial_state, + OrphanablePtr watcher); + void RemoveConnectivityWatcher( + AsyncConnectivityStateWatcherInterface* watcher); + private: class SubchannelWrapper; class ClientChannelControlHelper; + class ConnectivityWatcherAdder; + class ConnectivityWatcherRemover; // Represents a pending connectivity callback from an external caller // via grpc_client_channel_watch_connectivity_state(). @@ -1201,6 +1209,72 @@ void ChannelData::ExternalConnectivityWatcher::RemoveWatcherLocked( self->chand_->state_tracker_.RemoveWatcher(self); } +// +// ChannelData::ConnectivityWatcherAdder +// + +class ChannelData::ConnectivityWatcherAdder { + public: + ConnectivityWatcherAdder( + ChannelData* chand, grpc_connectivity_state initial_state, + OrphanablePtr watcher) + : chand_(chand), + initial_state_(initial_state), + watcher_(std::move(watcher)) { + GRPC_CHANNEL_STACK_REF(chand_->owning_stack_, "ConnectivityWatcherAdder"); + GRPC_CLOSURE_INIT(&closure_, &ConnectivityWatcherAdder::AddWatcherLocked, + this, grpc_combiner_scheduler(chand_->combiner_)); + GRPC_CLOSURE_SCHED(&closure_, GRPC_ERROR_NONE); + } + + private: + static void AddWatcherLocked(void* arg, grpc_error* error) { + ConnectivityWatcherAdder* self = + static_cast(arg); + self->chand_->state_tracker_.AddWatcher(self->initial_state_, + std::move(self->watcher_)); + GRPC_CHANNEL_STACK_UNREF(self->chand_->owning_stack_, + "ConnectivityWatcherAdder"); + Delete(self); + } + + ChannelData* chand_; + grpc_connectivity_state initial_state_; + OrphanablePtr watcher_; + grpc_closure closure_; +}; + +// +// ChannelData::ConnectivityWatcherRemover +// + +class ChannelData::ConnectivityWatcherRemover { + public: + ConnectivityWatcherRemover(ChannelData* chand, + AsyncConnectivityStateWatcherInterface* watcher) + : chand_(chand), watcher_(watcher) { + GRPC_CHANNEL_STACK_REF(chand_->owning_stack_, "ConnectivityWatcherRemover"); + GRPC_CLOSURE_INIT(&closure_, + &ConnectivityWatcherRemover::RemoveWatcherLocked, this, + grpc_combiner_scheduler(chand_->combiner_)); + GRPC_CLOSURE_SCHED(&closure_, GRPC_ERROR_NONE); + } + + private: + static void RemoveWatcherLocked(void* arg, grpc_error* error) { + ConnectivityWatcherRemover* self = + static_cast(arg); + self->chand_->state_tracker_.RemoveWatcher(self->watcher_); + GRPC_CHANNEL_STACK_UNREF(self->chand_->owning_stack_, + "ConnectivityWatcherRemover"); + Delete(self); + } + + ChannelData* chand_; + AsyncConnectivityStateWatcherInterface* watcher_; + grpc_closure closure_; +}; + // // ChannelData::ClientChannelControlHelper // @@ -1885,6 +1959,17 @@ grpc_connectivity_state ChannelData::CheckConnectivityState( return out; } +void ChannelData::AddConnectivityWatcher( + grpc_connectivity_state initial_state, + OrphanablePtr watcher) { + New(this, initial_state, std::move(watcher)); +} + +void ChannelData::RemoveConnectivityWatcher( + AsyncConnectivityStateWatcherInterface* watcher) { + New(this, watcher); +} + // // CallData implementation // @@ -3936,6 +4021,21 @@ void grpc_client_channel_watch_connectivity_state( watcher_timer_init); } +void grpc_client_channel_start_connectivity_watch( + grpc_channel_element* elem, grpc_connectivity_state initial_state, + grpc_core::OrphanablePtr + watcher) { + auto* chand = static_cast(elem->channel_data); + chand->AddConnectivityWatcher(initial_state, std::move(watcher)); +} + +void grpc_client_channel_stop_connectivity_watch( + grpc_channel_element* elem, + grpc_core::AsyncConnectivityStateWatcherInterface* watcher) { + auto* chand = static_cast(elem->channel_data); + chand->RemoveConnectivityWatcher(watcher); +} + grpc_core::RefCountedPtr grpc_client_channel_get_subchannel_call(grpc_call_element* elem) { auto* calld = static_cast(elem->call_data); diff --git a/src/core/ext/filters/client_channel/client_channel.h b/src/core/ext/filters/client_channel/client_channel.h index 72bcb404ce0..2ba2b87bb13 100644 --- a/src/core/ext/filters/client_channel/client_channel.h +++ b/src/core/ext/filters/client_channel/client_channel.h @@ -46,17 +46,35 @@ grpc_connectivity_state grpc_client_channel_check_connectivity_state( int grpc_client_channel_num_external_connectivity_watchers( grpc_channel_element* elem); -// TODO(roth): This function is used both when handling external -// connectivity watchers and for LB policies like grpclb and xds that -// contain nested channels. In the latter case, we ideally want -// something closer to the normal connectivity state tracker API. -// When we have time, consider refactoring this somehow to allow each -// use-case to be handled more cleanly. +// Starts a one-time connectivity state watch. When the channel's state +// becomes different from *state, sets *state to the new state and +// schedules on_complete. The watcher_timer_init callback is invoked as +// soon as the watch is actually started (i.e., after hopping into the +// client channel combiner). I/O will be serviced via pollent. +// +// This is intended to be used when starting a watch from outside of C-core +// via grpc_channel_watch_connectivity_state(). It should not be used +// by other callers. void grpc_client_channel_watch_connectivity_state( grpc_channel_element* elem, grpc_polling_entity pollent, grpc_connectivity_state* state, grpc_closure* on_complete, grpc_closure* watcher_timer_init); +// Starts and stops a connectivity watch. The watcher will be initially +// notified as soon as the state changes from initial_state and then on +// every subsequent state change until either the watch is stopped or +// it is notified that the state has changed to SHUTDOWN. +// +// This is intended to be used when starting watches from code inside of +// C-core (e.g., for a nested control plane channel for things like xds). +void grpc_client_channel_start_connectivity_watch( + grpc_channel_element* elem, grpc_connectivity_state initial_state, + grpc_core::OrphanablePtr + watcher); +void grpc_client_channel_stop_connectivity_watch( + grpc_channel_element* elem, + grpc_core::AsyncConnectivityStateWatcherInterface* watcher); + /* Debug helper: pull the subchannel call from a call stack element */ grpc_core::RefCountedPtr grpc_client_channel_get_subchannel_call(grpc_call_element* elem); diff --git a/src/core/ext/filters/client_channel/lb_policy/xds/xds.cc b/src/core/ext/filters/client_channel/lb_policy/xds/xds.cc index e0fa6c31dcd..ee6578a2fb0 100644 --- a/src/core/ext/filters/client_channel/lb_policy/xds/xds.cc +++ b/src/core/ext/filters/client_channel/lb_policy/xds/xds.cc @@ -355,17 +355,17 @@ class XdsLb : public LoadBalancingPolicy { void StartConnectivityWatchLocked(); void CancelConnectivityWatchLocked(); - static void OnConnectivityChangedLocked(void* arg, grpc_error* error); private: + class StateWatcher; + // The owning LB policy. RefCountedPtr xdslb_policy_; // The channel and its status. grpc_channel* channel_; bool shutting_down_ = false; - grpc_connectivity_state connectivity_ = GRPC_CHANNEL_IDLE; - grpc_closure on_connectivity_changed_; + StateWatcher* watcher_ = nullptr; // The retryable XDS calls to the LB server. OrphanablePtr> eds_calld_; @@ -862,6 +862,39 @@ void XdsLb::FallbackHelper::AddTraceEvent(TraceSeverity severity, parent_->channel_control_helper()->AddTraceEvent(severity, message); } +// +// XdsLb::LbChannelState::StateWatcher +// + +class XdsLb::LbChannelState::StateWatcher + : public AsyncConnectivityStateWatcherInterface { + public: + explicit StateWatcher(RefCountedPtr parent) + : AsyncConnectivityStateWatcherInterface( + grpc_combiner_scheduler(parent->xdslb_policy_->combiner())), + parent_(std::move(parent)) {} + + private: + void OnConnectivityStateChange(grpc_connectivity_state new_state) override { + if (!parent_->shutting_down_ && + parent_->xdslb_policy_->fallback_at_startup_checks_pending_ && + new_state == GRPC_CHANNEL_TRANSIENT_FAILURE) { + // In TRANSIENT_FAILURE. Cancel the fallback timer and go into + // fallback mode immediately. + gpr_log(GPR_INFO, + "[xdslb %p] Balancer channel in state TRANSIENT_FAILURE; " + "entering fallback mode", + parent_->xdslb_policy_.get()); + parent_->xdslb_policy_->fallback_at_startup_checks_pending_ = false; + grpc_timer_cancel(&parent_->xdslb_policy_->lb_fallback_timer_); + parent_->xdslb_policy_->UpdateFallbackPolicyLocked(); + parent_->CancelConnectivityWatchLocked(); + } + } + + RefCountedPtr parent_; +}; + // // XdsLb::LbChannelState // @@ -871,8 +904,6 @@ XdsLb::LbChannelState::LbChannelState(RefCountedPtr xdslb_policy, const grpc_channel_args& args) : InternallyRefCounted(&grpc_lb_xds_trace), xdslb_policy_(std::move(xdslb_policy)) { - GRPC_CLOSURE_INIT(&on_connectivity_changed_, OnConnectivityChangedLocked, - this, grpc_combiner_scheduler(xdslb_policy_->combiner())); channel_ = CreateXdsBalancerChannel(balancer_name, args); GPR_ASSERT(channel_ != nullptr); eds_calld_.reset(New>( @@ -900,56 +931,17 @@ void XdsLb::LbChannelState::StartConnectivityWatchLocked() { grpc_channel_element* client_channel_elem = grpc_channel_stack_last_element(grpc_channel_get_channel_stack(channel_)); GPR_ASSERT(client_channel_elem->filter == &grpc_client_channel_filter); - // Ref held by callback. - Ref(DEBUG_LOCATION, "LbChannelState+start_watch").release(); - grpc_client_channel_watch_connectivity_state( - client_channel_elem, - grpc_polling_entity_create_from_pollset_set( - xdslb_policy_->interested_parties()), - &connectivity_, &on_connectivity_changed_, nullptr); + auto watcher = MakeOrphanable(Ref()); + watcher_ = watcher.get(); + grpc_client_channel_start_connectivity_watch( + client_channel_elem, GRPC_CHANNEL_IDLE, std::move(watcher)); } void XdsLb::LbChannelState::CancelConnectivityWatchLocked() { grpc_channel_element* client_channel_elem = grpc_channel_stack_last_element(grpc_channel_get_channel_stack(channel_)); GPR_ASSERT(client_channel_elem->filter == &grpc_client_channel_filter); - grpc_client_channel_watch_connectivity_state( - client_channel_elem, - grpc_polling_entity_create_from_pollset_set( - xdslb_policy_->interested_parties()), - nullptr, &on_connectivity_changed_, nullptr); -} - -void XdsLb::LbChannelState::OnConnectivityChangedLocked(void* arg, - grpc_error* error) { - LbChannelState* self = static_cast(arg); - if (!self->shutting_down_ && - self->xdslb_policy_->fallback_at_startup_checks_pending_) { - if (self->connectivity_ != GRPC_CHANNEL_TRANSIENT_FAILURE) { - // Not in TRANSIENT_FAILURE. Renew connectivity watch. - grpc_channel_element* client_channel_elem = - grpc_channel_stack_last_element( - grpc_channel_get_channel_stack(self->channel_)); - GPR_ASSERT(client_channel_elem->filter == &grpc_client_channel_filter); - grpc_client_channel_watch_connectivity_state( - client_channel_elem, - grpc_polling_entity_create_from_pollset_set( - self->xdslb_policy_->interested_parties()), - &self->connectivity_, &self->on_connectivity_changed_, nullptr); - return; // Early out so we don't drop the ref below. - } - // In TRANSIENT_FAILURE. Cancel the fallback timer and go into - // fallback mode immediately. - gpr_log(GPR_INFO, - "[xdslb %p] Balancer channel in state TRANSIENT_FAILURE; " - "entering fallback mode", - self); - self->xdslb_policy_->fallback_at_startup_checks_pending_ = false; - grpc_timer_cancel(&self->xdslb_policy_->lb_fallback_timer_); - self->xdslb_policy_->UpdateFallbackPolicyLocked(); - } - // Done watching connectivity state, so drop ref. - self->Unref(DEBUG_LOCATION, "LbChannelState+watch_done"); + grpc_client_channel_stop_connectivity_watch(client_channel_elem, watcher_); } // @@ -1843,9 +1835,7 @@ void XdsLb::ShutdownLocked() { gpr_log(GPR_INFO, "[xdslb %p] shutting down", this); } shutting_down_ = true; - if (fallback_at_startup_checks_pending_) { - grpc_timer_cancel(&lb_fallback_timer_); - } + MaybeCancelFallbackAtStartupChecks(); priority_list_.ShutdownLocked(); if (fallback_policy_ != nullptr) { grpc_pollset_set_del_pollset_set(fallback_policy_->interested_parties(), diff --git a/src/core/lib/transport/connectivity_state.cc b/src/core/lib/transport/connectivity_state.cc index 32aa99306be..ec60a1125f8 100644 --- a/src/core/lib/transport/connectivity_state.cc +++ b/src/core/lib/transport/connectivity_state.cc @@ -57,10 +57,9 @@ const char* ConnectivityStateName(grpc_connectivity_state state) { class AsyncConnectivityStateWatcherInterface::Notifier { public: Notifier(RefCountedPtr watcher, - grpc_connectivity_state state) + grpc_connectivity_state state, grpc_closure_scheduler* scheduler) : watcher_(std::move(watcher)), state_(state) { - GRPC_CLOSURE_INIT(&closure_, SendNotification, this, - grpc_schedule_on_exec_ctx); + GRPC_CLOSURE_INIT(&closure_, SendNotification, this, scheduler); GRPC_CLOSURE_SCHED(&closure_, GRPC_ERROR_NONE); } @@ -82,7 +81,7 @@ class AsyncConnectivityStateWatcherInterface::Notifier { void AsyncConnectivityStateWatcherInterface::Notify( grpc_connectivity_state state) { - New(Ref(), state); // Deletes itself when done. + New(Ref(), state, scheduler_); // Deletes itself when done. } // diff --git a/src/core/lib/transport/connectivity_state.h b/src/core/lib/transport/connectivity_state.h index cefd1b88a02..2a4cf63de29 100644 --- a/src/core/lib/transport/connectivity_state.h +++ b/src/core/lib/transport/connectivity_state.h @@ -28,6 +28,7 @@ #include "src/core/lib/gprpp/map.h" #include "src/core/lib/gprpp/orphanable.h" #include "src/core/lib/iomgr/closure.h" +#include "src/core/lib/iomgr/exec_ctx.h" namespace grpc_core { @@ -67,8 +68,15 @@ class AsyncConnectivityStateWatcherInterface protected: class Notifier; + explicit AsyncConnectivityStateWatcherInterface( + grpc_closure_scheduler* scheduler = grpc_schedule_on_exec_ctx) + : scheduler_(scheduler) {} + // Invoked asynchronously when Notify() is called. virtual void OnConnectivityStateChange(grpc_connectivity_state new_state) = 0; + + private: + grpc_closure_scheduler* scheduler_; }; // Tracks connectivity state. Maintains a list of watchers that are From 2d7e477a6c9401e04e7c91e708d5498c1e604f13 Mon Sep 17 00:00:00 2001 From: Moiz Haidry Date: Tue, 1 Oct 2019 14:12:01 -0700 Subject: [PATCH 59/60] Clear the thread state before shutdown on executor, make exception for MacOS and iOS --- src/core/lib/iomgr/executor.cc | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/core/lib/iomgr/executor.cc b/src/core/lib/iomgr/executor.cc index c855d1535a9..87e9f6cf507 100644 --- a/src/core/lib/iomgr/executor.cc +++ b/src/core/lib/iomgr/executor.cc @@ -264,6 +264,15 @@ void Executor::ThreadMain(void* arg) { grpc_core::ExecCtx::Get()->InvalidateNow(); subtract_depth = RunClosures(ts->name, closures); } + + // We have an issue with Apple platforms where applying gpr_tls_set here + // leads to an EAGAIN error while performing a gpr_tls_get, so we are + // skipping this cleanup for Apple platforms. See PR #19978 + // TODO(mhaidry) : Fix this by switching to using thread_local once we have + // support for it in Xcode (PR #20413)or whatever else it takes +#if !defined(__APPLE__) + gpr_tls_set(&g_this_thread_state, reinterpret_cast(nullptr)); +#endif // !__APPLE__ } void Executor::Enqueue(grpc_closure* closure, grpc_error* error, From 446d89010a0a9d8bc7261a5d50ea543e47797177 Mon Sep 17 00:00:00 2001 From: Esun Kim Date: Wed, 2 Oct 2019 13:10:44 -0700 Subject: [PATCH 60/60] Fix python windows link problem --- setup.py | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/setup.py b/setup.py index eed516a1f11..0c6307eb703 100644 --- a/setup.py +++ b/setup.py @@ -147,16 +147,21 @@ EXTRA_ENV_COMPILE_ARGS = os.environ.get('GRPC_PYTHON_CFLAGS', None) EXTRA_ENV_LINK_ARGS = os.environ.get('GRPC_PYTHON_LDFLAGS', None) if EXTRA_ENV_COMPILE_ARGS is None: EXTRA_ENV_COMPILE_ARGS = ' -std=c++11' - if 'win32' in sys.platform and sys.version_info < (3, 5): - EXTRA_ENV_COMPILE_ARGS += ' -D_hypot=hypot' - # We use define flags here and don't directly add to DEFINE_MACROS below to - # ensure that the expert user/builder has a way of turning it off (via the - # envvars) without adding yet more GRPC-specific envvars. - # See https://sourceforge.net/p/mingw-w64/bugs/363/ - if '32' in platform.architecture()[0]: - EXTRA_ENV_COMPILE_ARGS += ' -D_ftime=_ftime32 -D_timeb=__timeb32 -D_ftime_s=_ftime32_s' + if 'win32' in sys.platform: + if sys.version_info < (3, 5): + EXTRA_ENV_COMPILE_ARGS += ' -D_hypot=hypot' + # We use define flags here and don't directly add to DEFINE_MACROS below to + # ensure that the expert user/builder has a way of turning it off (via the + # envvars) without adding yet more GRPC-specific envvars. + # See https://sourceforge.net/p/mingw-w64/bugs/363/ + if '32' in platform.architecture()[0]: + EXTRA_ENV_COMPILE_ARGS += ' -D_ftime=_ftime32 -D_timeb=__timeb32 -D_ftime_s=_ftime32_s' + else: + EXTRA_ENV_COMPILE_ARGS += ' -D_ftime=_ftime64 -D_timeb=__timeb64' else: - EXTRA_ENV_COMPILE_ARGS += ' -D_ftime=_ftime64 -D_timeb=__timeb64' + # We need to statically link the C++ Runtime, only the C runtime is + # available dynamically + EXTRA_ENV_COMPILE_ARGS += ' /MT' elif "linux" in sys.platform: EXTRA_ENV_COMPILE_ARGS += ' -std=gnu99 -fvisibility=hidden -fno-wrapv -fno-exceptions' elif "darwin" in sys.platform: