Unsafe Field Accessor with newer mysql-connector-java package
ISSUE TYPE
- Bug Report
COMPONENT NAME
mysql-connector-java
CLOUDSTACK VERSION
4.11.3
all
CONFIGURATION
OS / ENVIRONMENT
CentOS7
SUMMARY
Looks like the new version (8.0.x) is stricter with conversions from Long to BigIntfor example. Auto Increment fields in the database are of type BigInt, but in code we are using Long. This generates the errors similar to the following at times:
Can not set long field com.cloud.upgrade.dao.VersionVO.id to java.math.BigInteger
STEPS TO REPRODUCE
Install any new version of mysql-connector-java Version 5.1.25 DOES NOT have the problem. The 8.x versions DO have the problem
We hit it while the database upgrade script was running 4.9.3.0 -> 4.10.0
EXPECTED RESULTS
Looks like older versions of mysql-connector-java did not care that we use Long in code but BigInt in the database columns
ACTUAL RESULTS
We get errors such as this:
Caused by: java.lang.IllegalArgumentException: Can not set long field com.cloud.upgrade.dao.VersionVO.id to java.math.BigInteger
at sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:167)
at sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:171)
at sun.reflect.UnsafeLongFieldAccessorImpl.set(UnsafeLongFieldAccessorImpl.java:102)
Not sure if the correct fix is to update the code to use something more compatible with BigInt or not... But here is a band-aid, here is what our mysql-community-connectors.repo looks like now:
[mysql-community-connectors]
name=MySQL Community Connectors
baseurl=http://repo.mysql.com/yum/mysql-connectors-community/el/$releasever/$basearch/
enabled=1
gpgcheck=1
exclude=mysql-connector-java*
The alternative (what we are using in Trillian) is to use mysql-connector-java from the Base CentOS 7 repo (still version 5.x) and mysql-connector-python from the Epel repo (an ancient version 1.1.6 verrsion) - i.e. forget/remove the repo.mysql.com repo.
We tried 8.0.16 through 8.0.19 and it had the same error regarding Long and BigInt.
For some reason when we try 8.0.11 through 8.0.15, we have some other issue (shown below) but did not have time to troubleshoot that.
"Failed to load DB driver com.mysql.jdbc.Driver"
I had the same issue after update our CentOS 7 OS. Please see all the details for reproducing the issue here: https://lists.apache.org/thread.html/r8413e39ac991dd7f65a30f691e520c48c1c9c496fd9b5a1badbfbbea%40%3Cusers.cloudstack.apache.org%3E
@Slair1 cc @andrijapanicsb @DaanHoogland @PaulAngus this has been fixed in the JDK11 branch that will include mysql-connector java dependency (no distro provided dependency needed now) and fixes the Long conversion issue: https://github.com/apache/cloudstack/pull/3601
validated on CentOS 7 for cloudstack 4.10 and 4.12, during initial start of cloudstack-management, it fail at the database upgrade scripts with following error:
2020-01-22 16:14:52,643 DEBUG [c.c.u.d.T.Transaction] (localhost-startStop-1:null) (logid:) Rolling back the transaction: Time = 2903 Name = Upgrade; called by -TransactionLegacy.rollback:889-TransactionLegacy.removeUpTo:832-TransactionLegacy.close:656-TransactionContextInterceptor.invoke:36-ReflectiveMethodInvocation.proceed:168-ExposeInvocationInterceptor.invoke:92-ReflectiveMethodInvocation.proceed:179-JdkDynamicAopProxy.invoke:213-$Proxy23.persist:-1-DatabaseUpgradeChecker.upgrade:471-DatabaseUpgradeChecker.check:548-CloudStackExtendedLifeCycle.checkIntegrity:65
2020-01-22 16:14:52,658 ERROR [c.c.u.DatabaseUpgradeChecker] (localhost-startStop-1:null) (logid:) Unable to upgrade the database
com.cloud.utils.exception.CloudRuntimeException: Problem with getting the ec attribute
at com.cloud.utils.db.GenericDaoBase.persist(GenericDaoBase.java:1430)
Rollback to mysql-connector-java-5.1.47 worked fine.
Thanks for confirming the workaround @pdion891. I'll close this as it's not a blocker if the distro provided mysql java dependency is not upgraded to 8.x, further #3601 fixes this against jdk11.
validated on CentOS 7 for cloudstack 4.10 and 4.12, during initial start of cloudstack-management, it fail at the database upgrade scripts with following error:
2020-01-22 16:14:52,643 DEBUG [c.c.u.d.T.Transaction] (localhost-startStop-1:null) (logid:) Rolling back the transaction: Time = 2903 Name = Upgrade; called by -TransactionLegacy.rollback:889-TransactionLegacy.removeUpTo:832-TransactionLegacy.close:656-TransactionContextInterceptor.invoke:36-ReflectiveMethodInvocation.proceed:168-ExposeInvocationInterceptor.invoke:92-ReflectiveMethodInvocation.proceed:179-JdkDynamicAopProxy.invoke:213-$Proxy23.persist:-1-DatabaseUpgradeChecker.upgrade:471-DatabaseUpgradeChecker.check:548-CloudStackExtendedLifeCycle.checkIntegrity:65 2020-01-22 16:14:52,658 ERROR [c.c.u.DatabaseUpgradeChecker] (localhost-startStop-1:null) (logid:) Unable to upgrade the database com.cloud.utils.exception.CloudRuntimeException: Problem with getting the ec attribute at com.cloud.utils.db.GenericDaoBase.persist(GenericDaoBase.java:1430)Rollback to mysql-connector-java-5.1.47 worked fine.
which is the procedure to rollback? i am completely new to cloudstack and yesterday installed and faced this issue
@alexanderbazhenoff it is expected to fail with older versions, this has been fixed for 4.14/master. The next major release 4.14.0.0 will support Java11 and the new mysql java 8.x connector.
Could you share how I'd revert to using mysql-connector-java-5.1.47? I'm new to CloudStack and also not too familiar with modifying MySQL settings.
hey @coreymr , I always forget, but please google for your setup. you need to use pip (the python package manager) or your OS package manager (like yum or apt-get) for that. something like
pip/yum/apt-get uninstall mysql-connector
pip/yum/apt-get install mysql-connector-5....
Hi, I started a small PoC on Cloudstack two days ago and followed the official Quickstart guide. Tried to install 4.13 and later 4.11.3 and ran into exactly this issue (and the Python module issue with missing dns.resolver module).
The workaround for this issue (exclude mysql-connector-java-* from MySQL community repo config) is straightforward and works. However, the Quickstart Guide and Install Manual need to include it at least until the permanent fix with 4.14 is released.
So I don't understand why this was closed without updating the documentation on the issue and workaround. As it is now, the Cloudstack install is a jarring debugging experience that only leads to this Github issue if your google-fu is good ...
Hi, I started a small PoC on Cloudstack two days ago and followed the official Quickstart guide. Tried to install 4.13 and later 4.11.3 and ran into exactly this issue (and the Python module issue with missing dns.resolver module).
The workaround for this issue (exclude mysql-connector-java-* from MySQL community repo config) is straightforward and works. However, the Quickstart Guide and Install Manual need to include it at least until the permanent fix with 4.14 is released.
So I don't understand why this was closed without updating the documentation on the issue and workaround. As it is now, the Cloudstack install is a jarring debugging experience that only leads to this Github issue if your google-fu is good ...
That's why this is a community project and I'm challenging you to get engaged and send a documentation PR on that guide, deal? :handshake:
That's why this is a community project and I'm challenging you to get engaged and send a documentation PR on that guide, deal? 🤝
@andrijapanicsb , sounds good. I've found the documentation repo and will send the PR tomorrow! 👍
Cool - I see already an existing PR - see if there is anything to add/remove to it : https://github.com/apache/cloudstack-documentation/pull/93
Thanks
I have same problem, can you give me idea where I drop mysql-connector-java-5.1.49.tar this file manually.
Thanks.
I am having the same issues again, can someone give clear instructions how to fix.
I really dont understand why cloudstack have so many issues...