修改迁移时,volume的path未写入的bug

web_backend_develope
chenlw 9 years ago
parent 5837fb8a65
commit 278c3d3aae

@ -0,0 +1,95 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//ibatis.apache.org//DTD Mapper 3.0//EN"
"http://ibatis.apache.org/dtd/ibatis-3-mapper.dtd">
<mapper namespace="com.platform.dao.VolumeDao">
<resultMap id="getEntityByText" type="com.platform.entities.VolumeInitEntity">
<id property="id" column="id" javaType="int" jdbcType="INTEGER" />
<result property="name" column="name" javaType="string"
jdbcType="VARCHAR" />
<result property="ip" column="ip" javaType="string"
jdbcType="VARCHAR" />
<result property="path" column="path" javaType="string"
jdbcType="VARCHAR" />
<result property="mark" column="mark" javaType="string"
jdbcType="VARCHAR" />
</resultMap>
<!-- 获取数据全部记录信息 -->
<select id="findAll" resultType="com.platform.entities.VolumeInitEntity">
SELECT
id,name,ip,path,mark
FROM
volume_info
ORDER BY id
</select>
<update id="update" parameterType="com.platform.entities.VolumeInitEntity">
UPDATE
volume_info
<set >
<trim suffixOverrides=",">
<if test="name != null and name != ''">
name= #{name},
</if>
<if test="ip != null and ip != ''">
ip= #{ip},
</if>
<if test="path != null and path != ''">
path= #{path},
</if>
<if test="mark != null and mark != ''">
mark= #{mark},
</if>
</trim>
</set>
<where>
id = #{id}
</where>
</update>
<insert id="save" parameterType="com.platform.entities.VolumeInitEntity">
INSERT INTO
volume_info(
<trim suffixOverrides=",">
<if test="name != null and name != ''">
name,
</if>
<if test="ip != null and ip != ''">
ip,
</if>
<if test="path != null and path != ''">
path,
</if>
<if test="mark != null and mark != ''">
mark,
</if>
</trim>
)
VALUES(
<trim suffixOverrides=",">
<if test="name != null and name != ''">
#{name},
</if>
<if test="ip != null and ip != ''">
#{ip},
</if>
<if test="path != null and path != ''">
#{path},
</if>
<if test="mark != null and mark != ''">
#{mark},
</if>
</trim>
)
</insert>
<delete id="remove" parameterType="java.lang.Integer">
DELETE FROM
volume_info
WHERE
id = #{id}
</delete>
</mapper>

@ -220,10 +220,10 @@ PUBLIC "-//ibatis.apache.org//DTD Mapper 3.0//EN"
#{year},
</if>
<if test="startYear != null and startYear != ''">
#{start_year},
#{startYear},
</if>
<if test="endYear != null and endYear != ''">
#{end_year},
#{endYear},
</if>
<if test="volumeIp != null and volumeIp != ''">
#{volumeIp},

@ -49,7 +49,7 @@ PUBLIC "-//ibatis.apache.org//DTD Mapper 3.0//EN"
</resultMap>
<sql id="Base_Column_List">
regionalism_code,system_code,dst_path,lasttime,fkid
regionalism_code,system_code,dst_path,lasttime,fkid,dst_volume_ip,dst_volume_path
</sql>
<!-- 获取数据全部记录信息 -->
@ -120,6 +120,12 @@ PUBLIC "-//ibatis.apache.org//DTD Mapper 3.0//EN"
<if test="fkid > 0 ">
fkid,
</if>
<if test="dstVolumeIp != null and dstVolumeIp != ''">
dst_volume_ip,
</if>
<if test="dstVolumePath != null and dstVolumePath != ''">
dst_volume_path,
</if>
</trim>
)
VALUES(
@ -146,7 +152,13 @@ PUBLIC "-//ibatis.apache.org//DTD Mapper 3.0//EN"
#{lastTime},
</if>
<if test="fkid > 0 ">
#{fkid),
#{fkid},
</if>
<if test="dstVolumeIp != null and dstVolumeIp != ''">
#{dstVolumeIp},
</if>
<if test="dstVolumePath != null and dstVolumePath != ''">
#{dstVolumePath},
</if>
</trim>
)
@ -156,7 +168,7 @@ PUBLIC "-//ibatis.apache.org//DTD Mapper 3.0//EN"
INSERT INTO move_data_tmp ( <include refid="Base_Column_List" /> )
VALUES
<foreach collection="list" item="item" index="index" separator=",">
(#{item.regionalismCode,jdbcType=VARCHAR},#{item.systemCode,jdbcType=INTEGER},#{item.dstPath,jdbcType=VARCHAR},#{item.lastTime,jdbcType=VARCHAR},#{item.fkid})
(#{item.regionalismCode,jdbcType=VARCHAR},#{item.systemCode,jdbcType=INTEGER},#{item.dstPath,jdbcType=VARCHAR},#{item.lastTime,jdbcType=VARCHAR},#{item.fkid},#{item.dstVolumeIp},#{item.dstVolumePath})
</foreach>
</select>

@ -0,0 +1,27 @@
package com.platform.dao;
import java.util.List;
import org.springframework.stereotype.Repository;
import com.platform.entities.VolumeInitEntity;
/**
* @author chen
*
*/
@Repository(value = "volumeDao")
public interface VolumeDao {
/**
* @return
* @throws Exception
*/
List<VolumeInitEntity> findAll() throws Exception;
int update(VolumeInitEntity data) throws Exception;
int save(VolumeInitEntity data) throws Exception;
int remove(int id) throws Exception;
}

@ -0,0 +1,86 @@
package com.platform.entities;
public class VolumeInitEntity {
private int id;
private String name;
private String ip;
private String path;
private String mark;
/**
* @return the id
*/
public int getId() {
return id;
}
/**
* @param id the id to set
*/
public void setId(int id) {
this.id = id;
}
/**
* @return the name
*/
public String getName() {
return name;
}
/**
* @param name the name to set
*/
public void setName(String name) {
this.name = name;
}
/**
* @return the ip
*/
public String getIp() {
return ip;
}
/**
* @param ip the ip to set
*/
public void setIp(String ip) {
this.ip = ip;
}
/**
* @return the path
*/
public String getPath() {
return path;
}
/**
* @param path the path to set
*/
public void setPath(String path) {
this.path = path;
}
/**
* @return the mark
*/
public String getMark() {
return mark;
}
/**
* @param mark the mark to set
*/
public void setMark(String mark) {
this.mark = mark;
}
}

@ -14,9 +14,11 @@ import org.springframework.stereotype.Service;
import com.platform.dao.DataInfoDao;
import com.platform.dao.DataInfoMoveTmpDao;
import com.platform.dao.VolumeDao;
import com.platform.entities.DataInfoEntity;
import com.platform.entities.DataInfoEntityMoveTmp;
import com.platform.entities.FolderNode;
import com.platform.entities.VolumeInitEntity;
import com.platform.glusterfs.CheckoutMD5;
import com.platform.glusterfs.CopyData;
import com.platform.glusterfs.RemoveData;
@ -32,6 +34,9 @@ public class MoveDataServiceImpl implements IMoveDataService {
@Resource(name = "dataInfoDao")
private DataInfoDao dataInfoDao;
@Resource(name = "volumeDao")
private VolumeDao volumeDao;
private RemoveData removeservice = new RemoveData();
@ -63,12 +68,17 @@ public class MoveDataServiceImpl implements IMoveDataService {
if (null ==node.getPath() ||"".equals(node.getPath())) {
return false;
}
List<VolumeInitEntity> listVolume = volumeDao.findAll();
if (null == listVolume || listVolume.size() == 0) {
return false;
}
String tailPath = "";
if (null != data) {
// XXX/320198_16/1,or XXX/320122KFQ_15/1 ---> /320198_16/1, or
// /320122KFQ_15/1
List<DataInfoEntityMoveTmp> exist = dataInfoMoveTmpDao.findAll();
List<String> existIds = new ArrayList<String>();
List<Integer> fkIds = new ArrayList<Integer>();
if (null != exist) {
for (DataInfoEntityMoveTmp dataInfoEntityMoveTmp : exist) {
if ("0".equals(dataInfoEntityMoveTmp.getCompleteStatus())
@ -77,6 +87,7 @@ public class MoveDataServiceImpl implements IMoveDataService {
if (null != dataInfoEntityMoveTmp.getDataPath()) {
existIds.add(dataInfoEntityMoveTmp.getDataPath());
}
fkIds.add(dataInfoEntityMoveTmp.getFkid());
}
}
}
@ -95,6 +106,12 @@ public class MoveDataServiceImpl implements IMoveDataService {
if (existIds.contains(dataInfoEntity.getDataPath())) {
continue;
}
if (dataInfoEntity.getId() == 0) {
continue;
}
if (fkIds.contains(dataInfoEntity.getId())) {
continue;
}
// TODO 正则:取出 data 的后面 的 路径eg: XXX/320198_16/1,or
// XXX/320122KFQ_15/1
Matcher matcher = pattern.matcher(dataInfoEntity.getDataPath());
@ -114,11 +131,30 @@ public class MoveDataServiceImpl implements IMoveDataService {
dataMove.setDstPath(finalDestPath);
dataMove.setLastTime(DateForm.date2StringBysecond(new Date()));
dataMove.setFkid(dataInfoEntity.getId());
dataMove.setVolumePath(node.getName());
// 末尾 含有 /
Matcher matcher3 = pattern2.matcher(node.getPath());
// 去掉 最后 的 / 符合
String volumePath = "";
if (!matcher3.find()) {
volumePath = node.getPath()+"/";
}
else {
volumePath = node.getPath();
}
for ( VolumeInitEntity ve : listVolume) {
if (volumePath.contains(ve.getPath())) {
dataMove.setDstVolumePath(ve.getPath());
dataMove.setDstVolumeIp(ve.getIp());
break;
}
}
moveList.add(dataMove);
}
if (moveList.size() > 0) {
dataInfoMoveTmpDao.insertBatch(moveList);
// for (DataInfoEntityMoveTmp dataInfoEntityMoveTmp2 : moveList) {
// dataInfoMoveTmpDao.save(dataInfoEntityMoveTmp2);
// }
isSuccess = true;
}
}

@ -139,10 +139,13 @@ public class ThreadMoveData{
data.setVolumeIp(dataMove.getDstVolumeIp());
data.setVolumePath(dataMove.getDstVolumePath());
data.setYear(DateForm.date2StringByMin(new Date()));
data.setVolumeIp(dataMove.getVolumeIp());
data.setId(0);
dataInfoDao.save(data);
}
else {
// 3:表示 迁移失败
dataMove.setLastTime(DateForm.date2StringBysecond(new Date()));
dataMove.setCompleteStatus("3");
}
}

@ -44,6 +44,6 @@ public class Constant {
/**
* volume 线
*/
public final static int update_dataInfo_sleep_time = 30000;
public final static int update_dataInfo_sleep_time = 1500;
}

Loading…
Cancel
Save