Compilar o Cassandra a partir do seu código fonte
- Postado por Adriano Bonacin
- Categorias cassandra
- Data 06/09/2022
- Comentários 0 comentário
Criando nosso container CentOS 7
% docker run -ti --name cassandra --hostname cassandra centos:7
[root@cassandra /]# cat /etc/*release
CentOS Linux release 7.9.2009 (Core)
NAME="CentOS Linux"
VERSION="7 (Core)"
ID="centos"
ID_LIKE="rhel fedora"
VERSION_ID="7"
PRETTY_NAME="CentOS Linux 7 (Core)"
ANSI_COLOR="0;31"
CPE_NAME="cpe:/o:centos:centos:7"
HOME_URL="https://www.centos.org/"
BUG_REPORT_URL="https://bugs.centos.org/"
CENTOS_MANTISBT_PROJECT="CentOS-7"
CENTOS_MANTISBT_PROJECT_VERSION="7"
REDHAT_SUPPORT_PRODUCT="centos"
REDHAT_SUPPORT_PRODUCT_VERSION="7"
CentOS Linux release 7.9.2009 (Core)
CentOS Linux release 7.9.2009 (Core)
[root@cassandra /]#
Instalando pacotes necessários
Vamos precisar do git, wget, unzip e do java (jdk 8). Se você desejar apenas executar programas escritos em java, você pode utilizar o JRE, mas para compilar códigos escritos em Java você vai precisar do JDK (javac). Aqui você consegue mais detalhes.
[root@cassandra /]# yum install -y wget unzip git java-1.8.0-openjdk-devel
Loaded plugins: fastestmirror, ovl
Determining fastest mirrors
* base: mirror.uepg.br
* extras: espejito.fder.edu.uy
* updates: mirror.ufscar.br
base | 3.6 kB 00:00:00
extras | 2.9 kB 00:00:00
updates | 2.9 kB 00:00:00
(1/4): base/7/x86_64/group_gz | 153 kB 00:00:00
(2/4): updates/7/x86_64/primary_db | 17 MB 00:00:01
(3/4): extras/7/x86_64/primary_db | 250 kB 00:00:01
(4/4): base/7/x86_64/primary_db | 6.1 MB 00:00:04
Resolving Dependencies
--> Running transaction check
---> Package git.x86_64 0:1.8.3.1-23.el7_8 will be installed
--> Processing Dependency: perl-Git = 1.8.3.1-23.el7_8 for package: git-1.8.3.1-23.el7_8.x86_64
--> Processing Dependency: perl >= 5.008 for package: git-1.8.3.1-23.el7_8.x86_64
--> Processing Dependency: rsync for package: git-1.8.3.1-23.el7_8.x86_64
--> Processing Dependency: perl(warnings) for package: git-1.8.3.1-23.el7_8.x86_64
--> Processing Dependency: perl(vars) for package: git-1.8.3.1-23.el7_8.x86_64
...
[root@cassandra /]# javac -version javac 1.8.0_342
# wget https://archive.apache.org/dist/ant/binaries/apache-ant-1.10.12-bin.zip
# unzip -q apache-ant-1.10.12-bin.zip
# mv apache-ant-1.10.12 /opt/ant
# ln -s /opt/ant/bin/ant /usr/bin/ant
## # Criar um arquivo com o conteudo abaixo
# cat /etc/profile.d/ant.sh
#!/bin/bash
ANT_HOME=/opt/ant
PATH=$ANT_HOME/bin:$PATH
export PATH ANT_HOME
export CLASSPATH=.# chmod +x /etc/profile.d/ant.sh
# source /etc/profile.d/ant.sh
# export JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.342.b07-1.el7_9.x86_64/jre
# ant -version
Apache Ant(TM) version 1.10.12 compiled on October 13 2021
Clonando o repositório do Cassandra
Próximo passo é clonarmos o repo do cassandra e escolher a versão que desejamos trabalhar.
[root@cassandra /]# git clone https://github.com/apache/cassandra.git
Cloning into 'cassandra'...
remote: Enumerating objects: 371554, done.
remote: Counting objects: 100% (204/204), done.
remote: Compressing objects: 100% (114/114), done.
remote: Total 371554 (delta 72), reused 154 (delta 45), pack-reused 371350
Receiving objects: 100% (371554/371554), 372.47 MiB | 9.77 MiB/s, done.
Resolving deltas: 100% (215903/215903), done.
[root@cassandra /]# cd cassandra
[root@cassandra cassandra]# git status
# On branch trunk
nothing to commit, working directory clean
[root@cassandra cassandra]# git branch -r
origin/HEAD -> origin/trunk
origin/cassandra-1.0
origin/cassandra-1.1
origin/cassandra-1.2
origin/cassandra-2.0
origin/cassandra-2.1
origin/cassandra-2.2
origin/cassandra-3.0
origin/cassandra-3.11
origin/cassandra-4.0
origin/cassandra-4.1
origin/trunk
[root@cassandra cassandra]# git checkout origin/cassandra-3.11
Note: checking out 'origin/cassandra-3.11'.
You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by performing another checkout.
If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -b with the checkout command again. Example:
git checkout -b new_branch_name
HEAD is now at 04c3e81... Merge branch 'cassandra-3.0' into cassandra-3.11
[root@cassandra cassandra]# git checkout -b my-cassandra-3.11
Switched to a new branch 'my-cassandra-3.11'
Compilando o cassandra
Por fim vamos alterar um arquivo Java para deixar nossa marca e compilar o Cassandra com o ANT. Vou alterar o arquivo ColumnFamilyStore.java na linha 432, pois é um trecho fácil de identificar no log. Em seguida, só chamar o ant e aguardar o build.
[root@cassandra cassandra]# vi src/java/org/apache/cassandra/db/ColumnFamilyStore.java
[root@cassandra cassandra]# grep -n -i abonacin src/java/org/apache/cassandra/db/ColumnFamilyStore.java
432: logger.info("ABonacin - Initializing {}.{}", keyspace.getName(), name);
[root@cassandra cassandra]# ant
Buildfile: /cassandra/build.xml
init:
[mkdir] Created dir: /cassandra/build/classes/main
[mkdir] Created dir: /cassandra/build/classes/thrift
[mkdir] Created dir: /cassandra/build/test/lib
[mkdir] Created dir: /cassandra/build/test/classes
[mkdir] Created dir: /cassandra/build/test/stress-classes
[mkdir] Created dir: /cassandra/src/gen-java
[mkdir] Created dir: /cassandra/build/lib
[mkdir] Created dir: /cassandra/build/jacoco
[mkdir] Created dir: /cassandra/build/jacoco/partials
...
jar:
[mkdir] Created dir: /cassandra/build/classes/thrift/META-INF
[copy] Copying 1 file to /cassandra/build/classes/main/META-INF
[copy] Copying 1 file to /cassandra/build/classes/thrift/META-INF
[copy] Copying 1 file to /cassandra/build/classes/main/META-INF
[copy] Copying 1 file to /cassandra/build/classes/thrift/META-INF
[jar] Building jar: /cassandra/build/apache-cassandra-thrift-3.11.14-SNAPSHOT.jar
[jar] Building jar: /cassandra/build/apache-cassandra-3.11.14-SNAPSHOT.jar
[mkdir] Created dir: /cassandra/build/classes/stress/META-INF
[mkdir] Created dir: /cassandra/build/tools/lib
[jar] Building jar: /cassandra/build/tools/lib/stress.jar
BUILD SUCCESSFUL
Total time: 2 minutes 13 seconds
[root@cassandra cassandra]#
Startar o Cassandra
E para finalizar, vamos criar um user e um group para executar o Cassandra. No final, só verificar como ficou o log.
[root@cassandra cassandra]# groupadd -g 1001 cassandra
[root@cassandra cassandra]# useradd -u 1001 -g 1001 cassandra
[root@cassandra cassandra]# chown -R cassandra: /cassandra
[root@cassandra cassandra]# su - cassandra
[cassandra@cassandra ~]$ /cassandra/bin/cassandra
[cassandra@cassandra ~]$ OpenJDK 64-Bit Server VM warning: Cannot open file /cassandra/bin/../logs/gc.log due to No such file or directory
CompilerOracle: dontinline org/apache/cassandra/db/Columns$Serializer.deserializeLargeSubset (Lorg/apache/cassandra/io/util/DataInputPlus;Lorg/apache/cassandra/db/Columns;I)Lorg/apache/cassandra/db/Columns;
CompilerOracle: dontinline org/apache/cassandra/db/Columns$Serializer.serializeLargeSubset (Ljava/util/Collection;ILorg/apache/cassandra/db/Columns;ILorg/apache/cassandra/io/util/DataOutputPlus;)V
CompilerOracle: dontinline org/apache/cassandra/db/Columns$Serializer.serializeLargeSubsetSize (Ljava/util/Collection;ILorg/apache/cassandra/db/Columns;I)I
CompilerOracle: dontinline org/apache/cassandra/db/commitlog/AbstractCommitLogSegmentManager.advanceAllocatingFrom (Lorg/apache/cassandra/db/commitlog/CommitLogSegment;)V
CompilerOracle: dontinline org/apache/cassandra/db/transform/BaseIterator.tryGetMoreContents ()Z
CompilerOracle: dontinline org/apache/cassandra/db/transform/StoppingTransformation.stop ()V
...
INFO [main] 2022-09-05 19:57:43,046 QueryProcessor.java:121 - Initialized prepared statement caches with 10 MB (native) and 10 MB (Thrift)
INFO [main] 2022-09-05 19:57:43,350 ColumnFamilyStore.java:432 - ABonacin - Initializing system.IndexInfo
INFO [main] 2022-09-05 19:57:43,797 ColumnFamilyStore.java:432 - ABonacin - Initializing system.batches
INFO [main] 2022-09-05 19:57:43,806 ColumnFamilyStore.java:432 - ABonacin - Initializing system.paxos
INFO [main] 2022-09-05 19:57:43,815 ColumnFamilyStore.java:432 - ABonacin - Initializing system.local
INFO [main] 2022-09-05 19:57:43,822 ColumnFamilyStore.java:432 - ABonacin - Initializing system.peers
INFO [main] 2022-09-05 19:57:43,830 ColumnFamilyStore.java:432 - ABonacin - Initializing system.peer_events
INFO [main] 2022-09-05 19:57:43,836 ColumnFamilyStore.java:432 - ABonacin - Initializing system.range_xfers
Agora você ja sabe como alterar o código fonte do Cassandra, fazer a alteração que desejar, compilar e colocá-lo para rodar. O que achou dessa brincadeira? Espero que tenha gostado.