You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cloudstack.apache.org by James Steele <js...@gmail.com> on 2021/09/03 14:28:26 UTC

Remove host from MySQL?

Hi all,

We have a host that was removed from the webUI, but it somehow still exists in the cloudstack MySQL database.

I wanted to remove the host, reinstall the OS and then re-add back to CS - keeping the same name & IP.

What is the MySQL command to remove the existing host entry? Would be something like:

use cloud;
select * from host;
update host set removed=now() where id=12;

FYI: this is the same Host 12 mentioned here: https://github.com/apache/cloudstack/issues/5300

Thanks, Jim

RE: RE: Remove host from MySQL?

Posted by Yordan Kostov <Yo...@NSOGROUP.COM>.
Just saw Wei response,

I suggest you take his approach as it is safer than mine.

Best regards,
Jordan

-----Original Message-----
From: Yordan Kostov <Yo...@NSOGROUP.COM> 
Sent: 09 септември 2021 г. 8:41
To: users@cloudstack.apache.org
Subject: RE: RE: Remove host from MySQL?


[X] This message came from outside your organization


This means in table vm_instance there are VM instances that are still noted to reside on that host. From what I have seen that is a common ACS behavior.
What you need to do is go to that table, filter by host and make a list of those VMs.
Find if they really exist as you don’t want to remove real ones.

After that is  verified you can delete them one by one based on VM id or all of them at once based on last_host_id.

Regards,
Jordan

-----Original Message-----
From: James Steele <js...@gmail.com>
Sent: 07 септември 2021 г. 12:00
To: users@cloudstack.apache.org
Subject: Re: RE: Remove host from MySQL?


[X] This message came from outside your organization


Thanks for that reply Jordan,

when I did that, I got:

mysql> delete from host where id=12;
ERROR 1451 (23000): Cannot delete or update a parent row: a foreign key constraint fails (`cloud`.`vm_instance`, CONSTRAINT `fk_vm_instance__last_host_id` FOREIGN KEY (`last_host_id`) REFERENCES `host` (`id`))
mysql>

Any idea? Thanks, Jim

RE: RE: Remove host from MySQL?

Posted by Yordan Kostov <Yo...@NSOGROUP.COM>.
This means in table vm_instance there are VM instances that are still noted to reside on that host. From what I have seen that is a common ACS behavior.
What you need to do is go to that table, filter by host and make a list of those VMs.
Find if they really exist as you don’t want to remove real ones.

After that is  verified you can delete them one by one based on VM id or all of them at once based on last_host_id.

Regards,
Jordan

-----Original Message-----
From: James Steele <js...@gmail.com> 
Sent: 07 септември 2021 г. 12:00
To: users@cloudstack.apache.org
Subject: Re: RE: Remove host from MySQL?


[X] This message came from outside your organization


Thanks for that reply Jordan,

when I did that, I got:

mysql> delete from host where id=12;
ERROR 1451 (23000): Cannot delete or update a parent row: a foreign key constraint fails (`cloud`.`vm_instance`, CONSTRAINT `fk_vm_instance__last_host_id` FOREIGN KEY (`last_host_id`) REFERENCES `host` (`id`))
mysql>

Any idea? Thanks, Jim

Re: Remove host from MySQL?

Posted by James Steele <js...@gmail.com>.
Thanks Wei, I ran your command: update vm_instance set last_host_id =NULL where last_host_id=12;

This has succesfully marked the host as 'Removed':
select * from host where id=12;

| 12 | macfkdn17 | 4f2d0b03-0144-4591-923e-2c29bb93038e | Removed | Routing | 10.253.0.57 | 255.255.252.0 | bc:77:e1:26:20:81 | 10.253.0.57  | 255.255.252.0  | bc:77:e1:26:20:81 | NULL | NULL | NULL  |  NULL | 10.253.0.57  | 255.255.252.0  | bc:77:e1:26:20:81  | NULL |  1 |  1 |  0 |   0 |  0 | iqn.1993-08.org.debian:01:4efdaa48c143 | NULL  | KVM | NULL  |  98710974464 | NULL  | 4.15.1.0 | NULL | NULL |  | NULL | 1 | 0 | 0 | 1588922331 | NULL | NULL | 2021-06-18 18:31:27 | 2021-09-03 15:16:12 | 288 | Disabled | NULL | NULL | Disabled|


So I then tried to re-add the host (now that the OS has been reinstalled). The add host process just tries for 5 mins but never completes.
Some bits that look relevant from management-server.log:


2021-09-09 10:40:45,748 WARN  [c.c.a.d.ParamGenericValidationWorker] (qtp1074389766-476:ctx-b04bca76 ctx-5d37a408) (logid:1fad0881) Received unknown parameters for command addHost. Unknown parameters : clustertype
2021-09-09 10:40:45,751 INFO  [c.c.r.ResourceManagerImpl] (qtp1074389766-476:ctx-b04bca76 ctx-5d37a408) (logid:1fad0881) Trying to add a new host at http://10.253.0.57 in data center 1


2021-09-09 10:56:37,914 DEBUG [c.c.u.s.SSHCmdHelper] (qtp1074389766-476:ctx-b04bca76 ctx-5d37a408) (logid:1fad0881) Executing cmd: sudo /usr/share/cloudstack-common/scripts/util/keystore-cert-import /etc/cloudstack/agent/agent.properties /etc/cloudstack/agent/
2021-09-09 10:56:37,914 DEBUG [c.c.u.s.SSHCmdHelper] (qtp1074389766-476:ctx-b04bca76 ctx-5d37a408) (logid:1fad0881) Ssh executed failed
java.io.IOException: Sorry, this connection is closed.



2021-09-09 10:56:37,915 WARN  [c.c.h.k.d.LibvirtServerDiscoverer] (qtp1074389766-476:ctx-b04bca76 ctx-5d37a408) (logid:1fad0881)  can't setup agent, due to com.cloud.utils.exception.CloudRuntimeException: Failed to setup certificate in the KVM agent's keystore file, please see logs and configure manually! - Failed to setup certificate in the KVM agent's keystore file, please see logs and configure manually!
2021-09-09 10:56:37,916 WARN  [c.c.r.ResourceManagerImpl] (qtp1074389766-476:ctx-b04bca76 ctx-5d37a408) (logid:1fad0881) Unable to find the server resources at http://10.250.0.57
2021-09-09 10:56:37,916 INFO  [c.c.u.e.CSExceptionErrorCode] (qtp1074389766-476:ctx-b04bca76 ctx-5d37a408) (logid:1fad0881) Could not find exception: com.cloud.exception.DiscoveryException in error code list for exceptions
2021-09-09 10:56:37,917 WARN  [o.a.c.a.c.a.h.AddHostCmd] (qtp1074389766-476:ctx-b04bca76 ctx-5d37a408) (logid:1fad0881) Exception: 
com.cloud.exception.DiscoveryException: Unable to add the host
	at com.cloud.resource.ResourceManagerImpl.discoverHostsFull(ResourceManagerImpl.java:825)
	at com.cloud.resource.ResourceManagerImpl.discoverHosts(ResourceManagerImpl.java:611)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:566)
	at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:344)
	at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:198)
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163)
	at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:97)
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
	at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:215)
	at com.sun.proxy.$Proxy192.discoverHosts(Unknown Source)
	at org.apache.cloudstack.api.command.admin.host.AddHostCmd.execute(AddHostCmd.java:142)
	at com.cloud.api.ApiDispatcher.dispatch(ApiDispatcher.java:156)
	at com.cloud.api.ApiServer.queueCommand(ApiServer.java:764)
	at com.cloud.api.ApiServer.handleRequest(ApiServer.java:588)
	at com.cloud.api.ApiServlet.processRequestInContext(ApiServlet.java:321)
	at com.cloud.api.ApiServlet$1.run(ApiServlet.java:134)
	at org.apache.cloudstack.managed.context.impl.DefaultManagedContext$1.call(DefaultManagedContext.java:55)
	at org.apache.cloudstack.managed.context.impl.DefaultManagedContext.callWithContext(DefaultManagedContext.java:102)
	at org.apache.cloudstack.managed.context.impl.DefaultManagedContext.runWithContext(DefaultManagedContext.java:52)
	at com.cloud.api.ApiServlet.processRequest(ApiServlet.java:131)
	at com.cloud.api.ApiServlet.doPost(ApiServlet.java:98)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:665)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:750)
	at org.eclipse.jetty.servlet.ServletHolder$NotAsync.service(ServletHolder.java:1443)
	at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:791)
	at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:550)
	at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:143)
	at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:602)
	at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:127)
	at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:235)
	at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:1624)
	at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:233)
	at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1435)
	at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:188)
	at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:501)
	at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:1594)
	at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:186)
	at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1350)
	at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141)
	at org.eclipse.jetty.server.handler.gzip.GzipHandler.handle(GzipHandler.java:766)
	at org.eclipse.jetty.server.handler.HandlerCollection.handle(HandlerCollection.java:146)
	at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:127)
	at org.eclipse.jetty.server.Server.handle(Server.java:516)
	at org.eclipse.jetty.server.HttpChannel.lambda$handle$1(HttpChannel.java:388)
	at org.eclipse.jetty.server.HttpChannel.dispatch(HttpChannel.java:633)
	at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:380)
	at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:273)
	at org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:311)
	at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:105)
	at org.eclipse.jetty.io.ChannelEndPoint$1.run(ChannelEndPoint.java:104)
	at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:773)
	at org.eclipse.jetty.util.thread.QueuedThreadPool$Runner.run(QueuedThreadPool.java:905)
	at java.base/java.lang.Thread.run(Thread.java:829)
2021-09-09 10:56:37,919 INFO  [c.c.a.ApiServer] (qtp1074389766-476:ctx-b04bca76 ctx-5d37a408) (logid:1fad0881) Unable to add the host
2021-09-09 10:56:37,920 DEBUG [c.c.a.ApiServlet] (qtp1074389766-476:ctx-b04bca76 ctx-5d37a408) (logid:1fad0881) ===END===  -- POST  command=addHost&response=json


Any ideas how to proceed next?? Jim


Re: Remove host from MySQL?

Posted by Wei ZHOU <us...@gmail.com>.
Hi James,

You can update db by sql

Update vm_instance set last_host_id =NULL where last_host_id=12;

-Wei

On Tuesday, 7 September 2021, James Steele <js...@gmail.com> wrote:

> Thanks for that reply Jordan,
>
> when I did that, I got:
>
> mysql> delete from host where id=12;
> ERROR 1451 (23000): Cannot delete or update a parent row: a foreign key
> constraint fails (`cloud`.`vm_instance`, CONSTRAINT
> `fk_vm_instance__last_host_id` FOREIGN KEY (`last_host_id`) REFERENCES
> `host` (`id`))
> mysql>
>
> Any idea? Thanks, Jim
>

Re: RE: Remove host from MySQL?

Posted by James Steele <js...@gmail.com>.
Thanks for that reply Jordan,

when I did that, I got:

mysql> delete from host where id=12;
ERROR 1451 (23000): Cannot delete or update a parent row: a foreign key constraint fails (`cloud`.`vm_instance`, CONSTRAINT `fk_vm_instance__last_host_id` FOREIGN KEY (`last_host_id`) REFERENCES `host` (`id`))
mysql> 

Any idea? Thanks, Jim

RE: Remove host from MySQL?

Posted by Yordan Kostov <Yo...@NSOGROUP.COM>.
Hello James,

	If this is production be very cautious about touching the base.

	This will do the trick:
		USE cloud;
		DELETE FROM host WHERE id=12;

Best regards,
Jordan

-----Original Message-----
From: James Steele <js...@gmail.com> 
Sent: 03 септември 2021 г. 17:28
To: users@cloudstack.apache.org
Subject: Remove host from MySQL?


[X] This message came from outside your organization


Hi all,

We have a host that was removed from the webUI, but it somehow still exists in the cloudstack MySQL database.

I wanted to remove the host, reinstall the OS and then re-add back to CS - keeping the same name & IP.

What is the MySQL command to remove the existing host entry? Would be something like:

use cloud;
select * from host;
update host set removed=now() where id=12;

FYI: this is the same Host 12 mentioned here: https://urldefense.com/v3/__https://github.com/apache/cloudstack/issues/5300__;!!A6UyJA!xxSOzkY4Lt4gw1sCqCER6DHC-Cvdc4dEl_df2vKC_ldCsQl1Mu0jn5iHGzR4VsCR7b_nNb6verIS$

Thanks, Jim