FileBaseDataMap CompressMode Add
@@ -782,90 +782,87 @@ | ||
782 | 782 | int hashCode = ((Integer)instructionObj[2]).intValue(); |
783 | 783 | StringBuilder buf = new StringBuilder(this.lineDataSize); |
784 | 784 | CacheContainer accessor = null; |
785 | - RandomAccessFile raf = null; | |
785 | + | |
786 | 786 | BufferedWriter wr = null; |
787 | 787 | |
788 | 788 | buf.append(this.fillCharacter(key, keyDataLength)); |
789 | 789 | buf.append(this.fillCharacter(value, oneDataLength)); |
790 | 790 | |
791 | - File file = this.dataFileList[hashCode % numberOfDataFiles]; | |
792 | 791 | |
793 | - if (this.innerCache != null) | |
794 | - accessor = (CacheContainer)this.innerCache.get(file.getAbsolutePath()); | |
795 | 792 | |
796 | - | |
797 | 793 | synchronized (this.dataFileList[hashCode % numberOfDataFiles]) { |
798 | - if (accessor == null || accessor.isClosed == true) { | |
799 | 794 | |
800 | - raf = new RandomAccessFile(file, "rwd"); | |
801 | - wr = new BufferedWriter(new FileWriter(file, true)); | |
802 | - accessor = new CacheContainer(); | |
803 | - accessor.raf = raf; | |
804 | - accessor.wr = wr; | |
805 | - accessor.file = file; | |
806 | - innerCache.put(file.getAbsolutePath(), accessor); | |
807 | - } else { | |
808 | - | |
809 | - raf = accessor.raf; | |
810 | - wr = accessor.wr; | |
795 | + File compressFile = this.dataFileList[hashCode % numberOfDataFiles]; | |
796 | + byte[] compressData = null; | |
797 | + StringBuilder decompressDataStr =null; | |
798 | + byte[] decompressData = null; | |
799 | + if (compressFile.exists()) { | |
800 | + BufferedInputStream bis = new BufferedInputStream(new FileInputStream(compressFile)); | |
801 | + compressData = new byte[new Long(compressFile.length()).intValue()]; | |
802 | + bis.read(compressData); | |
803 | + bis.close(); | |
804 | + decompressData = SystemUtil.dataDecompress(compressData); | |
811 | 805 | } |
812 | 806 | |
813 | - | |
814 | 807 | // KeyData Write File |
815 | - for (int tryIdx = 0; tryIdx < 2; tryIdx++) { | |
816 | - try { | |
808 | + try { | |
817 | 809 | |
818 | 810 | // Key値の場所を特定する |
819 | 811 | long start1 = System.nanoTime(); |
820 | - long[] dataLineNoRet = this.getLinePoint(key, raf); | |
812 | + long[] dataLineNoRet = this.getLinePoint(key, decompressData); | |
821 | 813 | long end1 = System.nanoTime(); |
822 | 814 | |
823 | - if (dataLineNoRet[0] == -1) { | |
815 | + if (dataLineNoRet[0] == -1) { | |
824 | 816 | long start2 = System.nanoTime(); |
825 | - wr.write(buf.toString()); | |
826 | - SystemUtil.diskAccessSync(wr); | |
817 | + | |
818 | + byte[] fixNewData = null; | |
819 | + byte[] bufBytes = buf.toString().getBytes(); | |
820 | + | |
821 | + if (decompressData == null || decompressData.length < 1) { | |
822 | + fixNewData = bufBytes; | |
823 | + } else { | |
824 | + fixNewData = new byte[bufBytes.length + decompressData.length]; | |
825 | + for (int cpIdx = 0; cpIdx < decompressData.length; cpIdx++) { | |
826 | + fixNewData[cpIdx] = decompressData[cpIdx]; | |
827 | + } | |
828 | + | |
829 | + int newCpIdx = decompressData.length; | |
830 | + for (int cpBufIdx = 0; cpBufIdx < bufBytes.length; cpBufIdx++) { | |
831 | + fixNewData[newCpIdx] = bufBytes[cpBufIdx]; | |
832 | + newCpIdx++; | |
833 | + } | |
834 | + } | |
835 | + | |
836 | + decompressData = fixNewData; | |
827 | 837 | long end2 = System.nanoTime(); |
828 | - if (((end2 - start2) > (1000 * 1000 * 10)) || ((end1 - start1) > (1000 * 1000 * 10))) { | |
829 | - System.out.println("1=" + ((end1 - start1) / 1000 /1000) + " 2=" + ((end2 - start2) / 1000 /1000)); | |
830 | - } | |
831 | - // The size of an increment | |
832 | - this.totalSize.getAndIncrement(); | |
833 | - } else { | |
838 | +if (((end2 - start2) > (1000 * 1000 * 100)) || ((end1 - start1) > (1000 * 1000 * 100))) { | |
839 | +System.out.println("1=" + ((end1 - start1) / 1000 /1000) + " 2=" + ((end2 - start2) / 1000 /1000)); | |
840 | +} | |
841 | + // The size of an increment | |
842 | + this.totalSize.getAndIncrement(); | |
843 | + } else { | |
834 | 844 | |
835 | - // 過去に存在したデータなら1増分 | |
836 | - boolean increMentFlg = false; | |
837 | - if (dataLineNoRet[1] == -1) increMentFlg = true; | |
838 | - //if (this.get(key, hashCode) == null) increMentFlg = true; | |
839 | - | |
840 | - raf.seek(dataLineNoRet[0] * (lineDataSize)); | |
841 | - | |
842 | - raf.write(buf.toString().getBytes(), 0, lineDataSize); | |
843 | - | |
844 | - if (increMentFlg) this.totalSize.getAndIncrement(); | |
845 | + // 過去に存在したデータなら1増分 | |
846 | + boolean increMentFlg = false; | |
847 | + if (dataLineNoRet[1] == -1) increMentFlg = true; | |
848 | + //if (this.get(key, hashCode) == null) increMentFlg = true; | |
849 | + int insIdx = new Long((dataLineNoRet[0] * (lineDataSize))).intValue(); | |
850 | + byte[] insBytes = buf.toString().getBytes(); | |
851 | + for (int i = 0; i < lineDataSize; i++) { | |
852 | + | |
853 | + decompressData[insIdx] = insBytes[i]; | |
845 | 854 | } |
846 | 855 | |
847 | - break; | |
848 | - } catch (IOException ie) { | |
849 | - | |
850 | - // IOExceptionの場合は1回のみファイルを再度開く | |
851 | - if (tryIdx == 1) throw ie; | |
852 | - try { | |
853 | - | |
854 | - if (raf != null) raf.close(); | |
855 | - if (wr != null) wr.close(); | |
856 | - | |
857 | - raf = new RandomAccessFile(file, "rwd"); | |
858 | - wr = new BufferedWriter(new FileWriter(file, true)); | |
859 | - accessor = new CacheContainer(); | |
860 | - accessor.raf = raf; | |
861 | - accessor.wr = wr; | |
862 | - accessor.file = file; | |
863 | - innerCache.put(file.getAbsolutePath(), accessor); | |
864 | - } catch (Exception e) { | |
865 | - throw e; | |
866 | - } | |
856 | + if (increMentFlg) this.totalSize.getAndIncrement(); | |
867 | 857 | } |
858 | + } catch (IOException ie) { | |
868 | 859 | } |
860 | + | |
861 | + compressData = SystemUtil.dataCompress(decompressData); | |
862 | + BufferedOutputStream compressBos = new BufferedOutputStream(new FileOutputStream(compressFile, false)); | |
863 | + compressBos.write(compressData); | |
864 | + compressBos.flush(); | |
865 | + compressBos.close(); | |
869 | 866 | } |
870 | 867 | |
871 | 868 | // 削除処理の場合 |
@@ -908,7 +905,6 @@ | ||
908 | 905 | * @param hashCode This is a key value hash code |
909 | 906 | */ |
910 | 907 | public void put(String key, String value, int hashCode) { |
911 | - | |
912 | 908 | Object[] instructionObj = new Object[3]; |
913 | 909 | instructionObj[0] = key; |
914 | 910 | instructionObj[1] = value; |
@@ -929,6 +925,7 @@ | ||
929 | 925 | if (this.delayWriteQueue.size() > (delayWriteQueueSize - 2000)) Thread.sleep(10); |
930 | 926 | if (this.delayWriteQueue.size() > (delayWriteQueueSize - 1000)) Thread.sleep(20); |
931 | 927 | |
928 | + | |
932 | 929 | this.delayWriteQueue.put(instructionObj); |
933 | 930 | //end2 = System.nanoTime(); |
934 | 931 | this.delayWriteRequestCount++; |
@@ -945,14 +942,17 @@ | ||
945 | 942 | |
946 | 943 | |
947 | 944 | // 指定のキー値が指定のファイル内でどこにあるかを調べる |
948 | - private long[] getLinePoint(String key, RandomAccessFile raf) throws Exception { | |
945 | + private long[] getLinePoint(String key, byte[] targetData) throws Exception { | |
946 | + | |
949 | 947 | long[] ret = {-1, 0}; |
948 | + if (targetData == null) return ret; | |
949 | + | |
950 | 950 | long line = -1; |
951 | 951 | long lineCount = 0L; |
952 | 952 | |
953 | 953 | byte[] keyBytes = key.getBytes(); |
954 | 954 | byte[] equalKeyBytes = new byte[keyBytes.length + 1]; |
955 | - byte[] lineBufs = new byte[this.getDataSize]; | |
955 | + byte[] lineBufs = null; | |
956 | 956 | boolean matchFlg = true; |
957 | 957 | |
958 | 958 | // マッチング用配列作成 |
@@ -964,46 +964,38 @@ | ||
964 | 964 | |
965 | 965 | try { |
966 | 966 | |
967 | - raf.seek(0); | |
968 | - int readLen = -1; | |
969 | - while((readLen = SystemUtil.diskAccessSync(raf, lineBufs)) != -1) { | |
967 | + int readLen = targetData.length; | |
968 | + lineBufs = targetData; | |
969 | + int loop = readLen / lineDataSize; | |
970 | 970 | |
971 | - matchFlg = true; | |
971 | + for (int loopIdx = 0; loopIdx < loop; loopIdx++) { | |
972 | 972 | |
973 | - int loop = readLen / lineDataSize; | |
973 | + int assist = (lineDataSize * loopIdx); | |
974 | 974 | |
975 | - for (int loopIdx = 0; loopIdx < loop; loopIdx++) { | |
976 | - | |
977 | - int assist = (lineDataSize * loopIdx); | |
978 | - | |
979 | - matchFlg = true; | |
980 | - if (equalKeyBytes[equalKeyBytes.length - 1] == lineBufs[assist + (equalKeyBytes.length - 1)]) { | |
981 | - for (int i = 0; i < equalKeyBytes.length; i++) { | |
982 | - if (equalKeyBytes[i] != lineBufs[assist + i]) { | |
983 | - matchFlg = false; | |
984 | - break; | |
985 | - } | |
975 | + matchFlg = true; | |
976 | + if (equalKeyBytes[equalKeyBytes.length - 1] == lineBufs[assist + (equalKeyBytes.length - 1)]) { | |
977 | + for (int i = 0; i < equalKeyBytes.length; i++) { | |
978 | + if (equalKeyBytes[i] != lineBufs[assist + i]) { | |
979 | + matchFlg = false; | |
980 | + break; | |
986 | 981 | } |
987 | - } else { | |
988 | - matchFlg = false; | |
989 | 982 | } |
983 | + } else { | |
984 | + matchFlg = false; | |
985 | + } | |
990 | 986 | |
991 | - // マッチした場合のみ返す | |
992 | - if (matchFlg) { | |
987 | + // マッチした場合のみ返す | |
988 | + if (matchFlg) { | |
993 | 989 | |
994 | - line = lineCount; | |
995 | - // 削除データか確かめる | |
996 | - if (lineBufs[assist + keyDataLength] == FileBaseDataMap.paddingSymbol) ret[1] = -1; | |
997 | - break; | |
998 | - } | |
990 | + line = lineCount; | |
991 | + // 削除データか確かめる | |
992 | + if (lineBufs[assist + keyDataLength] == FileBaseDataMap.paddingSymbol) ret[1] = -1; | |
993 | + break; | |
994 | + } | |
999 | 995 | |
1000 | - lineCount++; | |
1001 | - } | |
1002 | - if (matchFlg) break; | |
996 | + lineCount++; | |
1003 | 997 | } |
1004 | 998 | |
1005 | - } catch (IOException ie) { | |
1006 | - throw ie; | |
1007 | 999 | } catch (Exception e) { |
1008 | 1000 | throw e; |
1009 | 1001 | } |
@@ -1048,7 +1040,7 @@ | ||
1048 | 1040 | String ret = null; |
1049 | 1041 | byte[] keyBytes = key.getBytes(); |
1050 | 1042 | byte[] equalKeyBytes = new byte[keyBytes.length + 1]; |
1051 | - byte[] lineBufs = new byte[this.getDataSize]; | |
1043 | + byte[] lineBufs = null; | |
1052 | 1044 | boolean matchFlg = true; |
1053 | 1045 | |
1054 | 1046 | // マッチング用配列作成 |
@@ -1061,101 +1053,60 @@ | ||
1061 | 1053 | //end1 = System.nanoTime(); |
1062 | 1054 | try { |
1063 | 1055 | //start2 = System.nanoTime(); |
1064 | - File file = this.dataFileList[hashCode % numberOfDataFiles]; | |
1065 | 1056 | CacheContainer accessor = null; |
1066 | - RandomAccessFile raf = null; | |
1067 | - BufferedWriter wr = null; | |
1068 | 1057 | |
1069 | - if (innerCache != null) | |
1070 | - accessor = (CacheContainer)this.innerCache.get(file.getAbsolutePath()); | |
1071 | - | |
1072 | 1058 | synchronized (this.dataFileList[hashCode % numberOfDataFiles]) { |
1073 | - if (accessor == null || accessor.isClosed) { | |
1074 | - | |
1075 | - raf = new RandomAccessFile(file, "rwd"); | |
1076 | - wr = new BufferedWriter(new FileWriter(file, true)); | |
1077 | - accessor = new CacheContainer(); | |
1078 | - accessor.raf = raf; | |
1079 | - accessor.wr = wr; | |
1080 | - accessor.file = file; | |
1081 | - innerCache.put(file.getAbsolutePath(), accessor); | |
1082 | - } else { | |
1083 | - | |
1084 | - raf = accessor.raf; | |
1059 | + | |
1060 | + File compressFile = this.dataFileList[hashCode % numberOfDataFiles]; | |
1061 | + byte[] compressData = null; | |
1062 | + byte[] decompressData = null; | |
1063 | + if (compressFile.exists()) { | |
1064 | + BufferedInputStream bis = new BufferedInputStream(new FileInputStream(compressFile)); | |
1065 | + compressData = new byte[new Long(compressFile.length()).intValue()]; | |
1066 | + bis.read(compressData); | |
1067 | + bis.close(); | |
1068 | + decompressData = SystemUtil.dataDecompress(compressData); | |
1069 | + lineBufs = decompressData; | |
1085 | 1070 | } |
1086 | -//end2 = System.nanoTime(); | |
1087 | -//start3 = System.nanoTime(); | |
1088 | - for (int tryIdx = 0; tryIdx < 2; tryIdx++) { | |
1071 | + int readLen = 0; | |
1072 | + if (decompressData != null && decompressData.length > 0) { | |
1073 | + readLen = decompressData.length; | |
1074 | + } | |
1075 | + | |
1076 | + matchFlg = true; | |
1089 | 1077 | |
1090 | - try { | |
1091 | -//start4 = System.nanoTime(); | |
1092 | - raf.seek(0); | |
1093 | -//end4 = System.nanoTime(); | |
1094 | - int readLen = -1; | |
1095 | -//start5 = System.nanoTime(); | |
1096 | - while((readLen = SystemUtil.diskAccessSync(raf, lineBufs)) != -1) { | |
1097 | -//end5 = System.nanoTime(); | |
1098 | -//timeList.add((end5 - start5)); | |
1099 | - matchFlg = true; | |
1078 | + int loop = readLen / lineDataSize; | |
1100 | 1079 | |
1101 | - int loop = readLen / lineDataSize; | |
1080 | + for (int loopIdx = 0; loopIdx < loop; loopIdx++) { | |
1102 | 1081 | |
1103 | - for (int loopIdx = 0; loopIdx < loop; loopIdx++) { | |
1082 | + int assist = (lineDataSize * loopIdx); | |
1104 | 1083 | |
1105 | - int assist = (lineDataSize * loopIdx); | |
1084 | + matchFlg = true; | |
1106 | 1085 | |
1107 | - matchFlg = true; | |
1086 | + if (equalKeyBytes[equalKeyBytes.length - 1] == lineBufs[assist + (equalKeyBytes.length - 1)]) { | |
1108 | 1087 | |
1109 | - if (equalKeyBytes[equalKeyBytes.length - 1] == lineBufs[assist + (equalKeyBytes.length - 1)]) { | |
1088 | + for (int i = 0; i < equalKeyBytes.length; i++) { | |
1110 | 1089 | |
1111 | - for (int i = 0; i < equalKeyBytes.length; i++) { | |
1090 | + if (equalKeyBytes[i] != lineBufs[assist + i]) { | |
1091 | + matchFlg = false; | |
1092 | + break; | |
1093 | + } | |
1094 | + } | |
1095 | + } else { | |
1112 | 1096 | |
1113 | - if (equalKeyBytes[i] != lineBufs[assist + i]) { | |
1114 | - matchFlg = false; | |
1115 | - break; | |
1116 | - } | |
1117 | - } | |
1118 | - } else { | |
1097 | + matchFlg = false; | |
1098 | + } | |
1119 | 1099 | |
1120 | - matchFlg = false; | |
1121 | - } | |
1100 | + // マッチした場合のみ配列化 | |
1101 | + if (matchFlg) { | |
1122 | 1102 | |
1123 | - // マッチした場合のみ配列化 | |
1124 | - if (matchFlg) { | |
1103 | + tmpBytes = new byte[lineDataSize]; | |
1125 | 1104 | |
1126 | - tmpBytes = new byte[lineDataSize]; | |
1105 | + for (int i = 0; i < lineDataSize; i++) { | |
1127 | 1106 | |
1128 | - for (int i = 0; i < lineDataSize; i++) { | |
1129 | - | |
1130 | - tmpBytes[i] = lineBufs[assist + i]; | |
1131 | - } | |
1132 | - break; | |
1133 | - } | |
1134 | - } | |
1135 | -//start5 = System.nanoTime(); | |
1136 | - if (matchFlg) break; | |
1107 | + tmpBytes[i] = lineBufs[assist + i]; | |
1137 | 1108 | } |
1138 | 1109 | break; |
1139 | - } catch (IOException ie) { | |
1140 | - | |
1141 | - // IOExceptionの場合は1回のみファイルをサイド開く | |
1142 | - if (tryIdx == 1) throw ie; | |
1143 | - | |
1144 | - try { | |
1145 | - | |
1146 | - if (raf != null) raf.close(); | |
1147 | - if (wr != null) wr.close(); | |
1148 | - | |
1149 | - raf = new RandomAccessFile(file, "rwd"); | |
1150 | - wr = new BufferedWriter(new FileWriter(file, true)); | |
1151 | - accessor = new CacheContainer(); | |
1152 | - accessor.raf = raf; | |
1153 | - accessor.wr = wr; | |
1154 | - accessor.file = file; | |
1155 | - innerCache.put(file.getAbsolutePath(), accessor); | |
1156 | - } catch (Exception e) { | |
1157 | - throw e; | |
1158 | - } | |
1159 | 1110 | } |
1160 | 1111 | } |
1161 | 1112 | } |
@@ -1275,19 +1226,31 @@ | ||
1275 | 1226 | List keys = null; |
1276 | 1227 | byte[] datas = null; |
1277 | 1228 | StringBuilder keysBuf = null; |
1278 | - RandomAccessFile raf = null; | |
1229 | + | |
1279 | 1230 | |
1280 | 1231 | try { |
1281 | 1232 | if (this.nowIterationFileIndex < this.dataFileList.length) { |
1282 | 1233 | |
1283 | 1234 | keys = new ArrayList(); |
1284 | - datas = new byte[new Long(this.dataFileList[this.nowIterationFileIndex].length()).intValue()]; | |
1235 | + | |
1236 | + File compressFile = this.dataFileList[this.nowIterationFileIndex]; | |
1237 | + byte[] compressData = null; | |
1238 | + byte[] decompressData = null; | |
1239 | + if (compressFile.exists()) { | |
1240 | + BufferedInputStream bis = new BufferedInputStream(new FileInputStream(compressFile)); | |
1241 | + compressData = new byte[new Long(compressFile.length()).intValue()]; | |
1242 | + bis.read(compressData); | |
1243 | + bis.close(); | |
1244 | + decompressData = SystemUtil.dataDecompress(compressData); | |
1245 | + } | |
1285 | 1246 | |
1286 | - raf = new RandomAccessFile(this.dataFileList[this.nowIterationFileIndex], "rwd"); | |
1247 | + | |
1248 | + datas = decompressData; | |
1287 | 1249 | |
1288 | - raf.seek(0); | |
1289 | 1250 | int readLen = -1; |
1290 | - readLen = SystemUtil.diskAccessSync(raf, datas); | |
1251 | + if (decompressData != null && decompressData.length > 0) { | |
1252 | + readLen = decompressData.length; | |
1253 | + } | |
1291 | 1254 | |
1292 | 1255 | if (readLen > 0) { |
1293 | 1256 |
@@ -1321,9 +1284,7 @@ | ||
1321 | 1284 | } finally { |
1322 | 1285 | |
1323 | 1286 | try { |
1324 | - if(raf != null) raf.close(); | |
1325 | 1287 | |
1326 | - raf = null; | |
1327 | 1288 | datas = null; |
1328 | 1289 | } catch (Exception e2) { |
1329 | 1290 | e2.printStackTrace(); |