MyCATApache/Mycat-Server · error

ER_YES

ER_YES

Error message

white host set success ,but write to file failed :" + e.getMessage()

What it means

ShowWhiteHost.setHost adds a white host to the in-memory firewall config (which succeeds), then tries to persist it via FirewallConfig.updateToFile. If persistence throws, the client gets an ER_YES error message saying the white host was set in memory but could not be written to the config file — leaving runtime state and file state inconsistent until restart loses the change.

Solutions

  1. Fix the underlying write failure shown in e.getMessage() (typically permissions on the conf directory or the config file).
  2. chown/chmod the conf directory and config file to the MyCat process user, then re-issue the white host command.
  3. Verify free disk space on the conf partition.
  4. If the in-memory change is acceptable short-term, export/persist the config manually and restart MyCat to confirm the host survives.

Example fix

// shell fix
// before: -rw-r--r-- root root /opt/mycat/conf/server.xml
// after:
// chown mycat:mycat /opt/mycat/conf/server.xml /opt/mycat/conf && chmod u+rw /opt/mycat/conf/server.xml
Defensive patterns

Strategy: try-catch

Validate before calling

File confDir = new File(confPath).getParentFile();
if (!confDir.canWrite()) throw new IllegalStateException("cannot persist white host, conf dir unwritable: " + confDir);

Try / catch

// after issuing 'white host=...' on the manager port
if (resp.contains("write to file failed")) {
  logger.warn("whitelist active in memory only; fix conf write perms and re-apply: {}", resp);
}

Prevention

When it happens

Trigger: Executing the manager 'white host=...' statement when the myid/conf configuration file cannot be written: unwritable directory, missing file, disk full, or XML write failure.

Common situations: MyCat running as a user without write access to the conf directory, read-only container filesystem, or a corrupted/locked server.xml-style config preventing persistence.

Understand the failure class

Background: "failed to write file", "Could not save figure", "Error saving remote file" — file write failed: causes and fixes across languages and libraries — this error's family across 38 libraries.

Related errors


AI-assisted analysis of MyCATApache/Mycat-Server@65f8d8beb7 (2026-09-11). Data as JSON: /api/errors/870d4ff5dc5ec6ec. Report an issue: GitHub.

Appendix: source

Thrown at src/main/java/io/mycat/manager/response/ShowWhiteHost.java:155

        	i++;  
        	UserConfig uc = MycatServer.getInstance().getConfig().getUsers().get(user);
            if (null == uc) {
            	c.writeErrMessage(ErrorCode.ER_YES, "user doesn't exist in host.");
                return; 
            }
            if (uc.getSchemas() == null || uc.getSchemas().size() == 0) {
            	c.writeErrMessage(ErrorCode.ER_YES, "host contains one root privileges user.");
                return;                 
            }
            userConfigs.add(uc);
          }   
        }  
       if (MycatServer.getInstance().getConfig().getFirewall().addWhitehost(host, userConfigs)) {
    	   try{
               FirewallConfig.updateToFile(host, userConfigs);
           }catch(Exception e){
        	   LOGGER.warn("set while host error : " + e.getMessage());
        	   c.writeErrMessage(ErrorCode.ER_YES, "white host set success ,but write to file failed :" + e.getMessage());
           }
    	   
           ok.packetId = 1;
           ok.affectedRows = 1;
           ok.serverStatus = 2;        
    	   ok.message = "white host set to succeed.".getBytes();	
           ok.write(c);  	 
           
       }
       else {
           c.writeErrMessage(ErrorCode.ER_YES, "host duplicated.");
       }
	}	
	
	
	
}

View on GitHub (pinned to 65f8d8beb7)