Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CASSANDRA-19514: When jvm-dtest shuts down have TCM stop retry messages. Fix a bug where replace with same instance doesnt trigger tcm notification #3227

Closed
wants to merge 134 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
134 commits
Select commit Hold shift + click to select a range
ff40219
CEP-15 (C*): Messaging and storage engine integration
bdeggleston Oct 21, 2022
2e30f7e
Command table now uses a local version added to the payload rather th…
dcapwell Oct 21, 2022
5e41ee1
Partial Replication of Transaction State
belliottsmith Oct 16, 2022
dd142d0
Transaction Expiration
belliottsmith Nov 8, 2022
7aeca7d
Refactor response tracking to improve efficiency and clarity; introdu…
belliottsmith Nov 28, 2022
5c8eabf
Invalidation fixes/improvements
belliottsmith Nov 21, 2022
a40f5e4
CEP-15: Routables
belliottsmith Oct 21, 2022
20a6688
CEP-15: Multi-Partition Transaction CQL Support (Alpha)
maedhroz May 13, 2022
e8775fe
ninja: pick a cassandra-accord SHA to build against to decouple sourc…
belliottsmith Jan 10, 2023
5ffa9f9
CEP-15: (C*) Enhance returning SELECT to allow partition and clusteri…
dcapwell Jan 12, 2023
00d0f41
Shard local CommandStores on contiguous ranges
belliottsmith Jan 8, 2023
0b419f6
Refactor Timestamp/TxnId
belliottsmith Jan 9, 2023
bb2ee42
Support CAS and serial read on Accord
aweisberg Dec 2, 2022
c5496e1
CASSANDRA-18154: CEP-15: Enhance returning SELECT to allow partition …
dcapwell Jan 12, 2023
676af96
Post-rebase fixes around CASSANDRA-18099 and CASSANDRA-18114 (among o…
maedhroz Jan 25, 2023
080903b
Introduce RangeDeps
belliottsmith Jan 9, 2023
f2c1fdc
Introduce Range transactions
belliottsmith Jan 9, 2023
ca978a9
Feature Flag for Accord Transactions
maedhroz Jan 30, 2023
47cb6a5
Ninja: CASSANDRA-18214 added rat checks to Accord, but our metadata f…
dcapwell Feb 2, 2023
e715f17
use equals() rather than reference equality for excluding ourselves f…
maedhroz Feb 2, 2023
6961dfd
Switch Node.Id from long to int
iamaleksey Feb 2, 2023
6894205
Fix null value handling for static columns
jacek-lewandowski Feb 10, 2023
d24f0b6
CEP-15: (C*) Add git submodule for Accord
dcapwell Feb 17, 2023
63631ba
Switched away from https endpoints for git submodules in favor of rel…
dcapwell Feb 22, 2023
14e5c18
Fix statement validation against partition range queries
jacek-lewandowski Feb 16, 2023
9309960
Add support for prepared statements for accord transactions
dcapwell Mar 3, 2023
d57e2e0
add AsyncChain implementations and tests
bdeggleston Jan 27, 2023
ba4a38f
CEP-15/Accord Immutable State Refactor
bdeggleston Feb 3, 2023
743d81a
Remove git hook for pre-push as it is redundant and causes issues whe…
dcapwell Mar 9, 2023
e44a844
CEP-15: (Accord) Migrate Accord away from JDK random to a new interfa…
dcapwell Mar 10, 2023
cdeb116
Improve transaction statement validation
jacek-lewandowski Mar 16, 2023
87de7f5
fixing remaining (mostly compilation) issues after initial rebase of …
maedhroz Mar 16, 2023
7663eae
Operations.migrateReadRequiredOperations fails due to concurrent acce…
dcapwell Mar 17, 2023
e1e90c1
CEP-15 (Accord) Expected reply message with verb ACCORD_INFORM_OF_TXN…
dcapwell Mar 31, 2023
e4a368b
CEP-15 (Accord) Original and recover coordinators may hit a race cond…
dcapwell Apr 7, 2023
00afcc3
CEP-15: (C*) Accord message processing should avoid being passed on t…
dcapwell Apr 27, 2023
e10ed43
CEP-15: (C*) Enhance in-memory FileSystem to work with mmap and suppo…
dcapwell May 8, 2023
13dbbdf
CEP-15: Store PreAccept, Accept, Commit, and Apply messages
iamaleksey Feb 16, 2023
db90358
(Accord only) Permit nodes to join a cluster without the full transac…
belliottsmith Apr 27, 2023
0675d61
minor cleanup in Verb and BTreeSet
May 26, 2023
1be2d91
removing unnecessary calls to ServerTestUtils.daemonInitialization() …
May 31, 2023
16031c2
make sure workspace.xml specifies a storagedir
Jun 2, 2023
f7584fe
CEP-15: (C*) Add notion of CommandsForRanges and make this durable in C*
dcapwell May 25, 2023
f9b0b29
CEP-15: Extend Accord MessageType with a side effect flag
iamaleksey Jun 2, 2023
ed51b34
CEP-15: Convert AccordStateCache cache from write-through to write-back
iamaleksey Jun 2, 2023
e274893
CEP-15: Accord Bootstrap Integration
bdeggleston Jun 7, 2023
59ed5dc
Support state eviction (i.e. permit the state machine to erase transa…
belliottsmith Aug 15, 2023
866b813
CEP-15 (C*) When a host replacement happens don't loose the peer mapp…
dcapwell Aug 16, 2023
ccc3599
CASSANDRA-18774: Fix pre-commit hook
jacek-lewandowski Aug 17, 2023
bbce801
Allow exceptions to be propagated remotely
aweisberg Aug 18, 2023
9b5673e
CEP-15 (C*): when loading commands that have empty waiting_on, make s…
dcapwell Aug 21, 2023
f5edfc7
Fix CompactionAccordIteratorsTest
iamaleksey Aug 22, 2023
b1441ca
Bootstrap/TCM integration test fixes
bdeggleston Mar 26, 2024
b6e0fd6
Fix Accord compaction purger tombstone logic
dcapwell Aug 16, 2023
d4fbb74
CEP-15: (C*) NPE on restart as epoch isnt known but verb handler does…
dcapwell Sep 14, 2023
db2bbe7
CEP-15: (C*) accord.messages.BeginRecovery.RecoverNack#supersededBy i…
dcapwell Sep 14, 2023
8da061c
- Avoid persisting fragments that do not require completion as Update…
Sep 20, 2023
36169b5
CEP-15: Minimize transaction state kept in system tables
iamaleksey Jun 28, 2023
0463bfe
ninja-fix: checkstyle fixes in VirtualTableTest, HistoryValidatorTest…
maedhroz Sep 27, 2023
3374507
ninja-fix: minor post-TCM-rebase cleanup
maedhroz Sep 29, 2023
b8dc70f
ninja-fix: exclude accord_demo.txt from rat checks
maedhroz Sep 30, 2023
ac14ff8
Fix AccordJournalTest and ConfigCompatibilityTest, and revert the sen…
maedhroz Oct 3, 2023
c4cb6cf
Fix Propagate serializer
iamaleksey Sep 28, 2023
4599954
CEP-15: Accord metrics
jacek-lewandowski Oct 10, 2023
135d7be
CEP-15: Add Accord configuration stub
jacek-lewandowski Oct 9, 2023
79cc206
CEP-15: (C*) Implement TopologySorter to prioritise hosts based on Dy…
dcapwell Oct 18, 2023
28fb0d4
Use pinned Harry version
ifesdjeen Oct 19, 2023
96e33a3
Several simulator fixes not yet merged to cep-15-accord
jonmeredith Jul 7, 2023
657596d
Accord support for live migration
aweisberg Jan 23, 2023
9839a40
Accord/non-Accord interoperability
aweisberg May 1, 2023
79b1873
Ninja fix SlowMessageFuzzTest and InvertedIndexSearcherTest
aweisberg Nov 13, 2023
ce00bdc
Fix Paxos V2 prepare response serialization
aweisberg Nov 14, 2023
5b15247
Quick fix for AccordCommandStoreTest#commandLoadSave()
iamaleksey Nov 17, 2023
288b744
Improve validation and address various discovered faults
belliottsmith Oct 9, 2023
3fce9c8
Ninja for CASSANDRA-19045: make sure to use https rather than git@ fo…
dcapwell Nov 27, 2023
2f6b60a
Ninja for CASSANDRA-19045: use the latest sha from trunk rather than …
dcapwell Nov 27, 2023
9866b0f
Reduce command deps
bdeggleston Oct 27, 2023
3ff0887
Fix additional live migration/interop merge issues
aweisberg Nov 29, 2023
55c3a90
Fix AccordJournal.Type interop entries
aweisberg Dec 5, 2023
7d510d2
Fix Mutation serializer
aweisberg Dec 7, 2023
3745460
Fix 5.1 rebase bugs
aweisberg Dec 7, 2023
198b719
Fix AccordCommandsPurger universal durability check
aweisberg Dec 4, 2023
8b16431
Fix empty row check in command/tfk mutation methods
bdeggleston Dec 6, 2023
0a9dc2c
Fix CompactionAccordIteratorsTest
bdeggleston Dec 6, 2023
cff6067
Add back enforceInvariants=false to shouldCleanup in AccordCommandsPu…
aweisberg Dec 8, 2023
57a8033
Fix StorageAttachedIndexDDLTest failing due to background Accord comp…
aweisberg Dec 8, 2023
f66015d
Instance.receiveMessage should use sync
aweisberg Dec 8, 2023
9e6fbab
Fix GuardrailTablesTest
aweisberg Dec 8, 2023
27aee2e
Don't use ImmediateExectuor in JVM dtests to process messages
aweisberg Dec 8, 2023
eeb23fd
Fix TombstoneCountWarningTest
aweisberg Dec 11, 2023
87142f8
Schema based accord fast path configuration
bdeggleston Dec 19, 2023
40142c9
(Accord) NPE while trying to serialize FoundKnownMap as value is null…
dcapwell Jan 8, 2024
ec992c6
Quick fix for AccordAddTableTest: make rejections catch up
ifesdjeen Jan 10, 2024
d2c7493
(Accord): Bug fixes from CASSANDRA-18675 to better support adding key…
dcapwell Jan 4, 2024
1b5fd65
Ninja: Added check that command.route is not null when SPL is trying …
dcapwell Jan 11, 2024
07debc2
Pre-requisite changes for CASSANDRA-18888
iamaleksey Nov 17, 2023
287fd50
fix fast path coordinator test
bdeggleston Jan 10, 2024
2776d34
retry on Invalidated
bdeggleston Jan 11, 2024
4c71211
fix ReducingRangeMapSerializer
bdeggleston Jan 11, 2024
fc12115
improve accord error logging
bdeggleston Jan 11, 2024
2dc4e44
don't make noise when fast path reconfigs are rejected
bdeggleston Jan 11, 2024
0d0ffe3
apply cfk update to both cfk caches
bdeggleston Jan 12, 2024
5fe0553
don't mark initialized cfk instances as updated
bdeggleston Jan 12, 2024
5948dfa
fix fast path update deadlock
bdeggleston Jan 16, 2024
c08d077
load both key command histories for operations specifying keyhistory ALL
bdeggleston Jan 18, 2024
3179782
fix fast path test epoch wait
bdeggleston Jan 18, 2024
afc58d7
Fix LocalPartitioner duplication in *_for_key Accord system tables
iamaleksey Jan 18, 2024
4f6868d
CASSANDRA-18365: Protocol fixes
belliottsmith Jan 17, 2024
79a47a6
Fix SerializerSupport.reconstruct, and introduce RangeFactory
belliottsmith Jan 24, 2024
924963d
Get simulator working (again)
dcapwell Oct 4, 2023
4b75f58
Fix (de)serialization of WaitingOn into cache
belliottsmith Feb 7, 2024
92705d3
Fix simulator logging and clean shutdown
belliottsmith Feb 7, 2024
5c72a68
dtest Instance shutdown (again)
belliottsmith Feb 8, 2024
c2d4e7c
Add TODO for TxnQuery using wrong cluster metadata
aweisberg Feb 15, 2024
7af41c6
Fast single-partition "Ephemeral Reads"
belliottsmith Jan 29, 2024
e78dde3
Refactor CommandsForKey for efficiency, and to support transitive dep…
belliottsmith Feb 15, 2024
6100243
CEP-15: (C*) per-table transactional configuration
bdeggleston Mar 26, 2024
26e42ec
rebase fixes
bdeggleston Mar 27, 2024
7bc74f6
fix MultiElementType pack/unpack accessor api
bdeggleston Mar 27, 2024
5ab02ad
rebase - fix cache metrics
bdeggleston Mar 27, 2024
30ce4ed
rebase fixes
bdeggleston Mar 27, 2024
cf69177
rebase fixes
bdeggleston Mar 27, 2024
303de2f
rebase test fixes
bdeggleston Mar 27, 2024
c2ef5f6
rebase test fixes
bdeggleston Mar 28, 2024
d4c308a
perf improvements
belliottsmith Feb 28, 2024
9ca1e1a
Ninja for CASSANDRA-19305: Disable EphemeralRead by default to get be…
dcapwell Mar 29, 2024
548924f
Ninja for CASSANDRA-19305: Disable EphemeralRead by default to get be…
dcapwell Mar 29, 2024
c42e155
Accord: PreLoadContext must properly and consistently support ranges
dcapwell Mar 29, 2024
70a0605
fix ReadCommand.serializedSize
bdeggleston Mar 29, 2024
53aaac0
revert async message delivery
bdeggleston Mar 29, 2024
63f3956
(Accord) Cassandra bootstrap no longer using the range txn and instea…
dcapwell Apr 1, 2024
9c35158
AccordGens.rangeDeps did not enforce unique ranges, which caused test…
dcapwell Apr 1, 2024
c86a444
CASSANDRA-19514: When jvm-dtest shuts down have TCM stop retry messag…
dcapwell Apr 2, 2024
e338c37
added isShutdown back
dcapwell Apr 2, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
45 changes: 45 additions & 0 deletions .build/build-accord.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<project basedir=".." name="apache-cassandra-accord-build"
xmlns:if="ant:if">
<target name="_build-accord" depends="init">
<exec executable="${basedir}/${accord.dir}/gradlew" dir="${basedir}/${accord.dir}" logError="true" failonerror="true" failifexecutionfails="true">
<!-- Need to call clean as a version change with a jar that didn't have code changes will not produce a new jar with the new version... so need clean to make sure build is stable -->
<arg value="clean" />
<arg value="build" />
<arg value="copyDependencies" /> <!-- For IDE support -->
<arg value="publishToMavenLocal" />
<arg value="-x" />
<arg value="test" />
<!-- since so much development is done from this hook, by adding checkstyle and rat will avoid issues earlier -->
<arg value="rat" />
<arg value="checkstyleMain" />
<arg value="checkstyleTest" />
<arg value="-Paccord_group=org.apache.cassandra" />
<arg value="-Paccord_artifactId=cassandra-accord" />
<arg value="-Paccord_version=${version}" />
</exec>
<!-- when dependencies are copied into the build dir they may be ignored if already present, so cleanup to pick up latest changes -->
<delete>
<!-- Why does this not use ${build.dir.lib}/jar and ${test.lib}/jar? The reason is that filesets never finds files in that case -->
<!-- To handle the case that build or lib dirs do not exist yet, had to push the logic into includes, other solution was to create a task and use if conditions there -->
<fileset dir="${basedir}" includes="build/lib/jars/cassandra-accord-*.jar,build/test/lib/jars/cassandra-accord-*.jar" />
</delete>
</target>
</project>
4 changes: 2 additions & 2 deletions .build/build-checkstyle.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<project basedir="." name="apache-cassandra-checkstyle"
xmlns:rat="antlib:org.apache.rat.anttasks">

<target name="init-checkstyle" depends="resolver-retrieve-build,build-project" unless="no-checkstyle">
<target name="init-checkstyle" depends="resolver-retrieve-build,_build_subprojects,build-project" unless="no-checkstyle">
<path id="checkstyle.lib.path">
<fileset dir="${test.lib}/jars" includes="*.jar"/>
</path>
Expand All @@ -45,7 +45,7 @@
</checkstyle>
</target>

<target name="checkstyle-test" depends="init-checkstyle,resolver-retrieve-build,build-project" description="Run custom checkstyle code analysis on tests" unless="no-checkstyle">
<target name="checkstyle-test" depends="init-checkstyle,resolver-retrieve-build,_build_subprojects,build-project" description="Run custom checkstyle code analysis on tests" unless="no-checkstyle">
<property name="checkstyle.log.dir" value="${build.dir}/checkstyle" />
<property name="checkstyle_test.report.file" value="${checkstyle.log.dir}/checkstyle_report_test.xml"/>
<mkdir dir="${checkstyle.log.dir}" />
Expand Down
1 change: 1 addition & 0 deletions .build/build-rat.xml
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@
<exclude NAME="CHANGES.txt"/>
<exclude NAME="CASSANDRA-14092.txt"/>
<exclude NAME="debian/TODO"/>
<exclude NAME="accord_demo.txt"/>
<!-- legal files -->
<exclude NAME="NOTICE.txt"/>
<exclude NAME="LICENSE.txt"/>
Expand Down
4 changes: 2 additions & 2 deletions .build/build-resolver.xml
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@
<property name="resolver-ant-tasks.initialized" value="true"/>
</target>

<target name="resolver-retrieve-build" depends="resolver-init,write-poms">
<target name="resolver-retrieve-build" depends="resolver-init,write-poms,_build_subprojects">
<resolvepom file="${build.dir}/${final.name}.pom" id="all-pom" />
<resolvepom file="${build.dir}/tmp-${final.name}-deps.pom" id="pom-deps" />

Expand Down Expand Up @@ -195,7 +195,7 @@
</unzip>
</target>

<target name="resolver-dist-lib" depends="resolver-retrieve-build">
<target name="resolver-dist-lib" depends="resolver-retrieve-build,_build_subprojects">
<resolvepom file="${build.dir}/${final.name}.pom" id="all-pom" />

<retry retrycount="3" retrydelay="10" >
Expand Down
5 changes: 5 additions & 0 deletions .build/cassandra-build-deps-template.xml
Original file line number Diff line number Diff line change
Expand Up @@ -143,5 +143,10 @@
<groupId>com.carrotsearch.randomizedtesting</groupId>
<artifactId>randomizedtesting-runner</artifactId>
</dependency>
<dependency>
<groupId>org.apache.cassandra</groupId>
<artifactId>cassandra-accord</artifactId>
<classifier>tests</classifier>
</dependency>
</dependencies>
</project>
4 changes: 4 additions & 0 deletions .build/cassandra-deps-template.xml
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,10 @@
<groupId>org.mindrot</groupId>
<artifactId>jbcrypt</artifactId>
</dependency>
<dependency>
<groupId>org.apache.cassandra</groupId>
<artifactId>cassandra-accord</artifactId>
</dependency>
<dependency>
<groupId>io.airlift</groupId>
<artifactId>airline</artifactId>
Expand Down
1 change: 0 additions & 1 deletion .build/checkstyle_suppressions.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,4 @@
"https://checkstyle.org/dtds/suppressions_1_1.dtd">

<suppressions>
<suppress checks="RegexpSinglelineJava" files="Semaphore\.java"/>
</suppressions>
41 changes: 41 additions & 0 deletions .build/git/git-hooks/post-checkout/100-update-submodules.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/usr/bin/env bash
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# Redirect output to stderr.
exec 1>&2

#set -o xtrace
set -o errexit
set -o pipefail
set -o nounset

bin="$(cd "$(dirname "$0")" > /dev/null; pwd)"

_main() {
# In case the usage happens at a different layer, make sure to cd to the toplevel
local root_dir
root_dir="$(git rev-parse --show-toplevel)"
cd "$root_dir"

if [[ ! -e .gitmodules ]]; then
# nothing to see here, look away!
return 0
fi
git submodule update --init --recursive
}

_main "$@"
1 change: 1 addition & 0 deletions .build/git/git-hooks/post-switch
98 changes: 98 additions & 0 deletions .build/git/git-hooks/pre-commit/100-verify-submodules-pushed.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
#!/usr/bin/env bash
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

##
## When working with submodules the top level project (Apache Cassandra) needs to commit all submodule
## changes so the top level knows what SHA to use. When working in a development environment it is
## common that multiple commits will exist in both projects, if the submodule has its history
## rewritten, then historic top level commits are no longer valid unless the SHAs are pushed to a
## remote repo; this is what the script attempts to do, make sure all SHAs added to the
## Apache Cassandra are backed up to a remote repo to make the Cassandra SHA buildable.
##

# Redirect output to stderr.
exec 1>&2


#set -o xtrace
set -o errexit
set -o pipefail
set -o nounset

bin="$(cd "$(dirname "$0")" > /dev/null; pwd)"

_log() {
echo -e "[pre-commit]\t$*"
}

error() {
_log "$@" 1>&2
exit 1
}

# Status Table
# A Added
# C Copied
# D Deleted
# M Modified
# R Renamed
# T Type Changed (i.e. regular file, symlink, submodule, …<200b>)
# U Unmerged
# X Unknown
# B Broken
_main() {
# In case the usage happens at a different layer, make sure to cd to the toplevel
local root_dir
root_dir="$(git rev-parse --show-toplevel)"
cd "$root_dir"

[[ ! -e .gitmodules ]] && return 0
local enabled=$(git config --bool cassandra.pre-commit.verify-submodules.enabled || echo true)
[ "$enabled" == "false" ] && return 0
local submodules=( $(git config --file .gitmodules --get-regexp path | awk '{ print $2 }') )

local is_submodule=false
local git_sub_dir
local git_sha
while read status file; do
is_submodule=false
for to_check in "${submodules[*]}"; do
if [[ "$to_check" == "$file" ]]; then
is_submodule=true
break
fi
done
if $is_submodule; then
local enabled=$(git config --bool cassandra.pre-commit.verify-submodule-${file}.enabled || echo true)
[ "$enabled" == "false" ] && continue
_log "Submodule detected: ${file} with status ${status}; attempting a push"
_log "\tTo disable pushes, run"
_log "\t\tgit config --local cassandra.pre-commit.verify-submodules.enabled false"
_log "\tOr"
_log "\t\tgit config --local cassandra.pre-commit.verify-submodule-${file}.enabled false"
git_sub_dir="${file}/.git"
branch="$(git config -f .gitmodules "submodule.${file}.branch")"
[[ -z "${branch:-}" ]] && error "Submodule ${file} does not define a branch"
git_sha="$(git --git-dir "${git_sub_dir}" rev-parse HEAD)"
local remote="$(git --git-dir "${git_sub_dir}" config --get "branch.${branch}.remote" || error "Git branch ${branch} is not set up to track any remote in submodule ${file}")"
git --git-dir "${git_sub_dir}" fetch "${remote}"
git --git-dir "${git_sub_dir}" branch "${remote}/${branch}" --contains "${git_sha}" || error "Git commit ${git_sha} not found in $(git remote get-url "${remote}") on branch ${branch}"
fi
done < <(git diff --cached --name-status)
}

_main "$@"
116 changes: 116 additions & 0 deletions .build/git/install-git-defaults.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
#!/usr/bin/env bash
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

#set -o xtrace
set -o errexit
set -o pipefail
set -o nounset

bin="$(cd "$(dirname "$0")" > /dev/null; pwd)"

install_template_script() {
local -r name="$1"
local -r d_dir="$2"

cat <<EOF > "$name"
#!/usr/bin/env bash

# This script is autogenerated by the Apache Cassandra build; DO NOT CHANGE!
# When this script is not found it will be installed automatically by the build
# If an existing script is found, that script will be reloated under ${d_dir} as 000-original.sh

# Redirect output to stderr.
exec 1>&2

# Find all scripts to run
for path in \$(find "$d_dir" -name '*.sh' | perl -e "print sort{(split '/', \\\$a)[-1] <=> (split '/', \\\$b)[-1]}<>"); do
"\$path" "\$@"
done
EOF
chmod a+x "$name"
}

install_hook() {
local -r git_dir="$1"
local -r hooks_dir="${git_dir}/hooks"
local -r name="$2"
local -r d_dir="${hooks_dir}/${name}.d"
local -r trigger_on_install=$3

mkdir "${d_dir}" &> /dev/null || true
local -r script_name="${hooks_dir}/${name}"
local installed=true
if [[ -e "$script_name" ]]; then
# was the script already installed?
if ! grep "This script is autogenerated by the Apache Cassandra build" "$script_name" &> /dev/null ; then
echo "$script_name found, but was not generated by the Apache Cassandra build; please remove or move to ${d_dir}/000-original.sh; creating and moving to ${d_dir} will cause it to run as expected, but won't conflict with hooks this build adds" 1>&2
exit 1
else
installed=false
fi
fi
# install all hooks
cp "$bin"/git-hooks/"${name}"/* "$d_dir"/

# install coordinator hook
install_template_script "$script_name" "$d_dir"
if $installed && $trigger_on_install ; then
echo "Running script $script_name"
"$script_name"
fi
}

_install_hooks() {
local git_dir
# make sure to use --git-common-dir and not --git-dir to support worktrees
git_dir="$(git rev-parse --git-common-dir 2> /dev/null || true)"
if [[ -z "${git_dir:-}" ]]; then
# not in a git repo, noop
return 0
fi

# make sure hooks directory exists; does not exist by default for worktrees
mkdir -p "${git_dir}/hooks" &> /dev/null || true

install_hook "$git_dir" "post-checkout" true
install_hook "$git_dir" "post-switch" false
install_hook "$git_dir" "pre-commit" false
}

_git_config_set() {
local -r name="$1"
# only care about rc
git config --local --get "$name" &> /dev/null
}

_install_configs() {
# when doing pull, this makes sure submodules are updated
_git_config_set submodule.recurse || git config --local submodule.recurse true
}

_main() {
local git_dir
# make sure to use --git-common-dir and not --git-dir to support worktrees
git_dir="$(git rev-parse --git-common-dir 2> /dev/null || true)"
# not in a git repo, noop
[[ -z "${git_dir:-}" ]] && return 0

_install_configs
_install_hooks
}

_main "$@"